Most Frequent Java Interview Questions Flashcards
Explain JDK?
JDK stands for Java Development Kit.
JDK is the tool necessary to compile, document, and package Java programs.
It contains JRE + development tools
Explain JRE?
JRE stands for Java Runtime Environment
JRE refers to a runtime environment in which Java bytecode can be executed. It contains libraries and resources that a Java program needs to run.
Explain JVM
JVM stands for Java Virtual Machine
It is a virtual machine that enables a computer to run Java program compiled to Java bytecode.
Explain public static void main(String[] args)
- public: Is an access modifier, which is used to specify who can access this method. Public means that this method will be accessible by any class.
- static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a class.
- void: It is the return type of the main() method. Void means the method will not return any value.
- main: It is the name of the method which is searched by the JVM as a startingn point for an application. It is the method where the main execution occurs.
Main it is the name of the method which is searched by the JVM as a starting point for an application. It is the method where the main execution occurs.
- String[ ] args: It is the parameter passed to the main method
Why is Java not 100% object-oriented?
Java is not 100% object-oriented because it makes use of eight primitive data types which are not objects.
What are Java’s 8 primitive data types and their sizes?
boolean, byte, short, char, int, float, long, and double.
boolean 1 bit
byte 8 bit
short 16 bit
char 6 bit
int 32 bit
float 32 bit
long 64 bit
double 6 bit
Why Java is platform independent?
Java is platform-independent because it’s compiled to Java bytecode and can run any operating system.
What are wrapper classes in Java?
Wrapper classes convert Java primitives into objects. Every primitive data type has a class dedicated to it.
Since Java 5 the auto box feature was introduced.
Autoboxing is when the primitive type is automatically converted to an Object. An example is converting an int into an Integer object.
Unboxing is the opposite of autoboxing, where the object is converted back to a primitive type. An example, converting a Long object into a long primitive type.
What are constructors in Java?
In Java, constructors refer to a block of code that is used to initialize an object.
It must have the same name as the class, and it has no return type. It’s also automatically called when an object is created.
There are 2 types of constructors:
- Default constructor: In Java, the default constructor does not take any inputs.
- Parameterized Constructor: This constructor is able to initialize the object with provided values.
What is a singleton class in Java and how can we make a class singleton?
Singleton class is a class whose only one instance can be created at any given time, in one JVM.
A class can be made singleton by making its constructor private.
What is the difference between equals() and == (equal operator) in Java?
The equals operator and the equals() method are used in Java to compare two objects.
The == (equal operator) compares the memory location of two objects.
The equals() method compares the VALUE of both objects.
What are access modifiers in Java?
In Java, access modifiers are special keywords that are used to restrict access to classes, constructors, data members, and methods by other classes.
Java supports four types of access modifiers:
default
public
protected
private
Define a Java class, and define an object
A Java class is a blueprint that contains variables and methods to describe the behavior of an object.
An Object is an instance of a class that has state and behavior. The instance variables provides the state of the object, and
What is Kafka?
Kafka is a distributed publish-subscribe stream-processing messaging system.
It’s open-source software and its goal is to provide a unified, high-throughput, platform for handling real-time data feed.
Highly throughput Scalability Replication Durability Stream process data loss
Describe the “Highly throughput” feature in Kafka
Kafka is high throughput because supports millions of messages with modest hardware
Describe the scalability feature in Kafka
Kafka offers highly scalable distributed systems with no downtime
List the various components of Kafka
The four major components of Kafka are:
- Topic
- Producer
- Brokers
- Consumers
List the various components of Kafka
The four major components of Kafka are:
- Topic
- Producer
- Brokers
- Consumers
Describe what is a topic in Kafka
In Kafka a topic is a stream of messages belonging to the same type.
- Kafka can have as many topics as you want
- Topics are identified by their name
Describe what is a topic in Kafka
In Kafka, a topic is a stream of messages belonging to the same type.
- Kafka can have as many topics as you want
- Topics are identified by their name
Describe what is a topic in Kafka
In Kafka, a topic is a stream of messages belonging to the same type.
- Kafka can have as many topics as you want
- Topics are identified by their name
Describe the role of the offset
The messages contained in the partitions are assigned a unique ID number and that is called the offset.
The role of the offset is to uniquely identify every message within the partition.
Kafka
Describe the role of the offset
The messages contained in the partitions are assigned a unique ID number and that is called the offset.
The role of the offset is to uniquely identify every message within the partition.
Kafka
T or F
Is the order of offsets guaranteed only within a partition?
True
Each partition is individual, and cannot write messages between partitions.
Example:
If offset 8 in partition 0 has been written the next offset will be 7 regardless of the offsets of others partitions.