Top 50 Java Interview Questions
Beginner Level (Questions 1-20)​
Basic Java Concepts​
-
What is Java and what are its main features?
- Platform independence, object-oriented, secure, robust, multithreaded
-
What is JVM, JRE, and JDK?
- JVM: Java Virtual Machine, JRE: Java Runtime Environment, JDK: Java Development Kit
-
What is the difference between JIT compiler and interpreter?
- JIT compiles bytecode to native machine code at runtime
-
What are the primitive data types in Java?
- byte, short, int, long, float, double, boolean, char
-
What is the difference between
==
andequals()
method?==
compares references,equals()
compares content
-
What is method overloading?
- Same method name with different parameters in the same class
-
What is method overriding?
- Child class provides specific implementation of parent class method
-
What is the difference between
String
,StringBuffer
, andStringBuilder
?- String is immutable, StringBuffer is synchronized, StringBuilder is not synchronized
-
What are access modifiers in Java?
- public, private, protected, default (package-private)
-
What is the difference between instance and static variables?
- Instance variables belong to objects, static variables belong to class
Object-Oriented Programming​
-
What are the four pillars of OOP?
- Encapsulation, Inheritance, Polymorphism, Abstraction
-
What is inheritance and what are its types?
- Single, multilevel, hierarchical inheritance (multiple inheritance through interfaces)
-
What is the difference between abstract class and interface?
- Abstract class can have concrete methods, interface has only abstract methods (before Java 8)
-
What is encapsulation?
- Bundling data and methods together and hiding internal implementation
-
What is polymorphism? Explain with example.
- One interface, multiple implementations (compile-time and runtime polymorphism)
Control Structures and Exception Handling​
-
What is the difference between
final
,finally
, andfinalize
?final
: keyword,finally
: block,finalize
: method
-
What is exception handling and its hierarchy?
- Throwable → Error/Exception → RuntimeException/Checked exceptions
-
What is the difference between checked and unchecked exceptions?
- Checked: compile-time verification, Unchecked: runtime exceptions
-
What is try-with-resources?
- Automatic resource management introduced in Java 7
-
What are the different types of loops in Java?
- for, while, do-while, enhanced for loop
Intermediate Level (Questions 21-35)​
Collections Framework​
-
What is the Java Collections Framework?
- Unified architecture for representing and manipulating collections
-
What is the difference between ArrayList and LinkedList?
- ArrayList: dynamic array, LinkedList: doubly linked list
-
What is the difference between HashMap and Hashtable?
- HashMap is not synchronized, allows null values; Hashtable is synchronized
-
What is the difference between Set and List?
- Set doesn't allow duplicates, List allows duplicates and maintains order
-
What is Iterator and how is it different from Enumeration?
- Iterator is fail-fast and allows removal, Enumeration is fail-safe
-
What is the difference between Comparable and Comparator?
- Comparable: natural ordering, Comparator: custom ordering
-
What is ConcurrentHashMap?
- Thread-safe version of HashMap without synchronizing entire map
Multithreading​
-
What is multithreading and its benefits?
- Concurrent execution of threads for better performance and resource utilization
-
What is the difference between Thread class and Runnable interface?
- Thread class vs implementing Runnable interface approach
-
What is synchronization and why is it needed?
- Controlling access to shared resources by multiple threads
-
What is the difference between
wait()
andsleep()
?- wait() releases lock, sleep() doesn't release lock
-
What is deadlock and how to prevent it?
- Circular dependency of threads waiting for resources
Memory Management​
-
What is garbage collection in Java?
- Automatic memory management to reclaim unused objects
-
What are different types of garbage collectors?
- Serial, Parallel, G1, ZGC, etc.
-
What is memory leak and how to prevent it?
- Objects not being garbage collected due to unintended references
Advanced Level (Questions 36-50)​
Advanced Java Features​
-
What are generics and type erasure?
- Type safety at compile time, type information erased at runtime
-
What is reflection in Java?
- Examining and manipulating classes, methods, fields at runtime
-
What are annotations and how do they work?
- Metadata that provides information about code
-
What is lambda expression and functional interfaces?
- Anonymous functions and interfaces with single abstract method
-
What is Stream API?
- Functional-style operations on collections of objects
Design Patterns and Architecture​
-
What is Singleton design pattern and its implementation?
- Ensures only one instance of a class exists
-
What is Factory design pattern?
- Creates objects without specifying exact class to create
-
What is Observer design pattern?
- One-to-many dependency between objects
-
What is MVC architecture?
- Model-View-Controller separation of concerns
-
What is dependency injection?
- Providing dependencies from external source rather than creating them
Performance and Advanced Topics​
-
What is JVM memory structure?
- Heap, Stack, Method Area, PC Register, Native Method Stack
-
What is the difference between heap and stack memory?
- Heap: objects storage, Stack: method calls and local variables
-
What is classloader and its types?
- Bootstrap, Extension, Application classloaders
-
What is serialization and deserialization?
- Converting objects to byte stream and vice versa
-
What are the latest features in Java 8, 11, 17, and 21?
- Lambda expressions, Streams, Modules, Records, Pattern Matching, etc.
Study Tips for Each Level:​
Beginner Level Focus:​
- Master basic syntax and OOP concepts
- Practice writing simple programs
- Understand data types and control structures
Intermediate Level Focus:​
- Deep dive into Collections Framework
- Learn multithreading basics
- Understand exception handling thoroughly
Advanced Level Focus:​
- Study design patterns
- Learn about JVM internals
- Explore modern Java features
- Practice system design problems
Recommended Practice Approach:​
- Start with basics - Ensure you understand fundamental concepts
- Code examples - Write code for each concept
- Progress gradually - Don't jump to advanced topics too quickly
- Practice coding - Use platforms like LeetCode, HackerRank
- Build projects - Apply concepts in real-world scenarios
Remember: Focus on understanding concepts rather than memorizing answers. Interviewers often ask follow-up questions to test your depth of knowledge!