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.
Kafka
T or F
Can data get shared between partitions?
False
Partitions are individuals. Data cannot get shared between partitions.
In Kafka data is kept only for a limited time. What is the default time?
The default time is one week
Kafka
Once the data is written to a partition can it be changed?
No. Once the data in the partition is written it can’t be changed, updated, or swap. The data is immutable.
Kafka
Is the data assigned randomly to a partition?
Yes
Kafka
How can you ensure the data is being assigned to a specific partition?
By providing the partition key
Kafka
Define what is a broker?
A broker is a set of servers where the published messages are stores.
Kafka
What is the ideal number of brokers that topics should have?
Ideally 3.
If a broker is down, the other 2 can serve the data.
Explain the concert of Leader and Follower
In Kafka, every partition has one server which plays as the leader, and none or more servers that act as followers.
The leader performs the task of all read and write requests of that partition, while the role of the partition follower is to passively replicate the leader, in other words, it keeps reading data from the partition leader without lagging behind.
In the event of the Leader failing, one of the partition Followers will take on the role of the Leader. This ensures load balancing of the server and can still serve the data.
Kafka
What is a Replication factor?
A replication factor defines the number of copies of a topic in a Kafka cluster.
The replication value should be more than 1. Usually between 2 or 3, but 3 is the best option.
If one broker is down the other brokers can still serve the data.
What is encapsulation?
Encapsulation is the process of restricting direct access to an object’s variables and methods by making them ‘private’.
Encapsulation increases the security of data and making public getters and setters can make the class read-only or write-only.
Why Encapsulation?
Because:
- Increase the security of data
- Offer read-only when using getters, and write-only when using setters.
What is inheritance?
Inheritance enables classes to inherit variables and methods from one class to another.
The class that inherits from another class is called a child class. The class being inherited from is called parent class.
To inherit variables and methods from a class, the keyword “extented” must be used in the child class.
This feature helps in reusing already defined code.
To inherit from a class, use the _____ keyword.
extend word