Java Interview Questions and Answers: JDK, JRE, JVM, OOP Concepts, and More
This article provides concise English explanations for 33 common Java interview questions, covering the differences between JDK/JRE/JVM, the main method signature, OOP principles, memory management, access modifiers, collections, and many other core Java concepts.
Q1. Explain JDK, JRE and JVM?
JDK
JRE
JVM
Java Development Kit.
Java Runtime Environment.
Java Virtual Machine.
Tools required to compile, document and package Java programs.
Runtime environment that can execute Java bytecode.
An abstract machine that provides a runtime environment for executing Java bytecode.
Contains JRE + development tools.
Actual implementation of the JVM.
JVM has three representations: specification, implementation, and runtime instance.
Q2. Explain public static void main(String[] args) in Java.
The main() method is the entry point of any Java program and is always declared as public static void main(String[] args) .
public : access modifier; any class can invoke the method.
static : class‑level keyword; the method can be called without creating an instance.
void : return type; the method returns no value.
main : the name searched for by the JVM as the program start.
String[] args : array of arguments passed from the command line.
Q3. Why is Java platform‑independent?
Java bytecode can run on any operating system because the JVM abstracts away the underlying platform.
Q4. Why is Java not 100% object‑oriented?
Java defines eight primitive data types (boolean, byte, char, int, float, double, long, short) that are not objects.
Q5. What are wrapper classes in Java?
Wrapper classes convert primitive types to reference types. Each primitive has a corresponding wrapper (e.g., Integer for int ).
Q6. What is a constructor in Java?
A constructor initializes an object; it has the same name as the class, no return type, and is invoked automatically when an object is created.
Two types of constructors:
Default constructor : a no‑argument constructor automatically provided if no other constructors are defined.
Parameterized constructor : a constructor that accepts arguments to initialize instance variables.
Q7. What is a Singleton class and how to make a class a singleton?
A Singleton class allows only one instance per JVM. Making the constructor private enforces the singleton property.
Q8. Difference between ArrayList and Vector.
ArrayList
Vector
Not synchronized (faster).
Synchronized (thread‑safe, slower).
Increases size by ~50% when needed.
Doubles its size by default.
No defined increment size.
Has a defined increment size.
Iterated using
Iteratoronly.
Can be iterated using
Enumerationor
Iterator.
Q9. Difference between equals() and == in Java.
equals() is a method defined in Object that can be overridden to compare logical equality of objects.
== is a binary operator that compares primitive values or object references for identity.
Q10. Difference between heap and stack memory.
Feature
Stack
Heap
Memory
Used by a single execution thread.
Shared by all parts of the application.
Access
Not accessible by other threads.
Globally accessible.
Memory management
LIFO release.
Managed per object lifecycle.
Lifetime
Exists until the thread finishes.
Exists from program start to termination.
Usage
Stores local primitives and reference variables.
Stores all objects.
Q11. What is a Java package and its advantages?
A package groups related classes and interfaces. Advantages include name conflict avoidance, easier access control, encapsulation of hidden classes, and a logical hierarchy for easier navigation.
Q12. Why does Java not use pointers?
Pointers are considered unsafe and would increase code complexity. The JVM handles memory allocation, so direct memory access is unnecessary.
Q13. What is the JIT compiler in Java?
The Just‑In‑Time (JIT) compiler translates bytecode into native machine instructions at runtime, improving performance by compiling frequently executed methods.
Q14. What are access modifiers in Java?
Java provides four access modifiers: default , private , protected , and public . Their visibility is summarized in the table below.
Modifier
Default
Private
Protected
Public
Same class
Yes
Yes
Yes
Yes
Same package, subclass
Yes
No
Yes
Yes
Same package, non‑subclass
Yes
No
Yes
Yes
Different package, subclass
No
No
Yes
Yes
Different package, non‑subclass
No
No
No
Yes
Q15. Define a Java class.
A class is a blueprint that contains fields (variables) and methods describing object behavior.
class Abc {
// member variables
// class body methods
}Q16. What is an object in Java and how to create one?
An object represents a real‑world entity with state, behavior, and identity. It is created using the new keyword, e.g., ClassName obj = new ClassName(); .
Q17. What is Object‑Oriented Programming (OOP)?
OOP organizes programs around objects rather than functions, making it suitable for large, complex, and maintainable codebases.
Q18. Main OOP concepts in Java.
Inheritance : a class acquires properties of another class.
Encapsulation : bundling data and methods together.
Abstraction : exposing only essential features.
Polymorphism : ability of a variable, function, or object to take multiple forms.
Q19. Difference between local variables and instance variables.
Local variables are declared inside methods, constructors, or blocks and have limited scope. Instance variables are declared at class level (outside methods) and belong to each object instance.
if (x > 100) {
String test = "Edureka";
} class Test {
public String empName;
public int empAge;
}Q20. Distinguish between methods and constructors.
Method
Constructor
Represents object behavior.
Initializes object state.
Must have a return type.
No return type.
Called explicitly.
Called implicitly.
Compiler does not provide a default.
Compiler provides a default if none is defined.
Name can differ from class name.
Name must match class name.
Q21. What does the final keyword mean in Java?
final can be applied to variables, methods, and classes:
Final variable : value cannot be changed after assignment.
Final method : cannot be overridden by subclasses.
Final class : cannot be subclassed.
Q22. Difference between break and continue .
break
continue
Can be used in switch and loops.
Can be used only in loops.
Terminates the innermost switch or loop.
Skips the current iteration and proceeds to the next.
Exits the block immediately.
Continues with the next iteration of the loop.
for (int i = 0; i < 5; i++) {
if (i == 3) {
break;
}
System.out.println(i);
} for (int i = 0; i < 5; i++) {
if (i == 2) {
continue;
}
System.out.println(i);
}Q23. What is an infinite loop in Java? Example.
An infinite loop runs indefinitely until externally terminated.
public class InfiniteForLoopDemo {
public static void main(String[] args) {
for (;;) {
System.out.println("Welcome to Edureka!");
}
}
}Q24. Difference between this() and super() .
this()
super()
Refers to the current instance of the class.
Refers to the current instance of the parent class.
Calls the class's own constructor.
Calls the parent class's constructor.
Used to access methods of the current class.
Used to access methods of the superclass.
Must be the first statement in a constructor block.
Must be the first statement in a constructor block.
Q25. What is the Java String pool?
The String pool stores string literals in heap memory; if a string already exists, the same reference is reused, improving memory usage and performance.
Q26. Distinguish static and non‑static methods.
Static method
Non‑static method
Declared with the
statickeyword.
No
statickeyword required.
Called using the class name (ClassName.methodName).
Called on an instance of the class.
Cannot access instance variables or methods directly.
Can access both static and instance members.
Q27. What is constructor chaining in Java?
Constructor chaining is the process where one constructor calls another constructor of the same class (using this() ) or the superclass (using super() ).
Q28. Difference between String, StringBuilder, and StringBuffer.
Aspect
String
StringBuilder
StringBuffer
Storage
String pool (constant area)
Heap
Heap
Mutability
Immutable
Mutable
Mutable
Thread safety
Thread‑safe (because immutable)
Not thread‑safe
Thread‑safe
Performance
Fast for read‑only operations
More efficient for frequent modifications
Less efficient due to synchronization
Q29. What is a class loader in Java?
A class loader loads class files into the JVM. Java provides three built‑in class loaders: Bootstrap ClassLoader, Extension ClassLoader, and System/Application ClassLoader.
Q30. Why are Java strings immutable?
Immutability allows strings to be safely shared, cached in the String pool, and improves security, synchronization, and performance.
Q31. Difference between arrays and ArrayLists.
Array
ArrayList
Can hold only one data type (including primitives).
Can hold objects of any type (generics allow type safety).
Size fixed at declaration.
Size dynamic; can grow/shrink.
Requires explicit index to add elements.
No need to specify index for addition.
Not parameterized.
Parameterized (e.g.,
ArrayList<String>).
Can store primitive types and objects.
Can store only objects (primitives must be boxed).
Q32. What is a Map in Java?
A Map is an interface in java.util that maps unique keys to values. Keys are not duplicated, and each key maps to at most one value.
Q33. What are Java collection classes? Overview of methods and interfaces.
The Java Collections Framework provides interfaces (e.g., List , Set , Map ) and concrete classes (e.g., ArrayList , HashSet , HashMap ) for storing and manipulating groups of objects.
If you have any questions about these Java interview topics, feel free to comment below.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.