TOP 20 JAVA INTERVIEW QUESTIONS
1. What is the difference between JDK, JRE, and JVM?
● JDK (Java Development Kit) includes tools for developing Java applications, including
the JRE and compilers.
● JRE (Java Runtime Environment) provides the libraries and environment to run Java
applications.
● JVM (Java Virtual Machine) is the engine that runs Java bytecode.
2. What are the main features of Java?
● Object-Oriented, Platform-Independent (Write Once, Run Anywhere), Robust (exception
handling, garbage collection), Multithreaded, and Secure.
3. Explain the concept of Object-Oriented Programming (OOP) in Java.
● Encapsulation: Bundling data with methods that operate on it.
● Inheritance: Deriving new classes from existing ones.
● Polymorphism: Using a single interface to represent different types.
● Abstraction: Hiding complex implementation details and showing only the necessary
features.
4. What is the difference between == and equals() in Java?
● == compares object references.
● equals() compares the content/values of objects.
5. What is a constructor in Java?
● A constructor is a special method used to initialize objects. It is called when an object is
created and can be overloaded.
6. What is the difference between an interface and an abstract class in
Java?
● Abstract Class: Can have abstract and concrete methods, supports multiple
inheritance, and can have constructors.
● Interface: Only abstract methods (until Java 8 added default and static methods), used
for full abstraction, supports multiple inheritance through implementation.
7. What is the difference between ArrayList and LinkedList in Java?
● ArrayList: Resizable array, better for random access.
● LinkedList: Doubly linked list, better for frequent insertions and deletions.
8. What is the significance of the final keyword in Java?
● Final Class: Cannot be subclassed.
● Final Method: Cannot be overridden.
● Final Variable: Value cannot be changed once assigned.
9. What is exception handling in Java?
● Exception handling in Java is managing runtime errors using try, catch, finally,
and throw/throws to maintain normal program flow.
10. What is the difference between checked and unchecked exceptions in
Java?
● Checked Exceptions: Must be handled or declared using throws (e.g., IOException).
● Unchecked Exceptions: Do not require explicit handling (e.g., NullPointerException).
11. What is multithreading in Java?
● Multithreading is the concurrent execution of two or more threads to maximize CPU
utilization. Java supports it via the Thread class and Runnable interface.
12. What is the difference between String, StringBuilder, and
StringBuffer?
● String: Immutable sequence of characters.
● StringBuilder: Mutable, not thread-safe, better performance.
● StringBuffer: Mutable, thread-safe, slower due to synchronization.
13. What are Java Streams in Java 8?
● Streams are used to process collections of objects in a functional programming style,
offering operations like filter, map, and reduce.
14. What is garbage collection in Java?
● Garbage collection is the automatic process of reclaiming memory by removing objects
that are no longer in use, managed by the JVM.
15. What is the purpose of the static keyword in Java?
● Static Variable: Shared among all instances of a class.
● Static Method: Belongs to the class rather than an instance.
● Static Block: Executes when the class is loaded.
16. What are Lambda Expressions in Java?
● Lambda expressions provide a clear and concise way to implement functional interfaces
using an expression syntax, introduced in Java 8.
17. What is the volatile keyword in Java?
● volatile is used for variables that can be accessed by multiple threads, ensuring
visibility of changes across threads.
18. Explain the concept of synchronized in Java.
● The synchronized keyword ensures that only one thread can access a block of code
or method at a time, preventing race conditions.
19. What is the Java Memory Model?
● The Java Memory Model defines how threads interact through memory and how
changes made by one thread become visible to others. It includes concepts like
happens-before, volatile, and synchronization.
20. What is the Optional class in Java 8?
● Optional is a container class that helps avoid NullPointerException by
representing values that may or may not be present.