Here is a complete list of Java topic-wise interview questions with detailed
answers, organized by major topics:
1. Java Basics
Q1: What is Java?
A: Java is a high-level, object-oriented programming language developed by Sun
Microsystems. It is platform-independent because of the Java Virtual Machine (JVM).
Q2: What are the features of Java?
A:
Platform Independent
Object-Oriented
Simple
Secure
Robust
Multithreaded
Architecture-Neutral
High Performance
Q3: Difference between JDK, JRE, and JVM?
A:
JDK: Java Development Kit – includes tools to develop Java applications
(compiler, debugger).
JRE: Java Runtime Environment – includes JVM + libraries for running Java
programs.
JVM: Java Virtual Machine – executes Java bytecode.
2. Data Types and Variables
Q4: What are primitive data types in Java?
A: byte, short, int, long, float, double, char, boolean
Q5: What is the difference between int and Integer?
A: int is a primitive data type, Integer is a wrapper class (object representation of
int).
Q6: What is type casting?
A:
Widening (Implicit): int → long
Narrowing (Explicit): double → int
Q7: What is the default value of a local variable?
A: Local variables must be explicitly initialized before use; otherwise, a compile-time
error occurs.
3. Operators and Control Flow
Q8: What are the types of operators in Java?
A:
Arithmetic
Relational
Logical
Assignment
Unary
Bitwise
Ternary
Q9: Difference between == and .equals()?
A:
==: compares reference (memory address)
.equals(): compares values (for objects like String)
Q10: Use of break and continue statements?
A:
break: exits the loop early
continue: skips the current iteration
4. OOP Concepts
Q11: What are the four pillars of OOP?
A:
Encapsulation
Inheritance
Polymorphism
Abstraction
Q12: Difference between method overloading and method overriding?
A:
Overloading: same method name, different parameters, in the same class.
Overriding: same method name and signature in a subclass.
Q13: Difference between Interface and Abstract Class?
A:
Interface: All methods are abstract (Java 8+ allows default/static methods).
Abstract Class: Can have both abstract and non-abstract methods.
5. Constructors
Q14: What is a constructor?
A: A special method that initializes objects when created.
Q15: What is constructor overloading?
A: Defining multiple constructors with different parameters in the same class.
6. Access Modifiers
Q16: What are the types of access modifiers?
A:
private: accessible within the class
default: package-private
protected: package + subclass
public: everywhere
Q17: Can static methods be overridden?
A: No, they can only be hidden (method hiding).
7. Inheritance and Polymorphism
Q18: Types of inheritance in Java?
A:
Single
Multilevel
Hierarchical
(Java doesn’t support multiple inheritance with classes to avoid ambiguity.)
Q19: What is the use of the super keyword?
A: To refer to the immediate parent class (constructor or methods).
8. Strings
Q20: Difference between String, StringBuilder, and StringBuffer?
A:
String: immutable
StringBuilder: mutable, not thread-safe
StringBuffer: mutable, thread-safe
9. Arrays and Collections
Q21: Difference between Array and ArrayList?
A:
Array: Fixed size, stores primitives or objects
ArrayList: Resizable, only stores objects
Q22: Difference between HashSet and TreeSet?
A:
HashSet: unordered, allows null
TreeSet: sorted, no null
Q23: Difference between HashMap and TreeMap?
A:
HashMap: unordered
TreeMap: ordered by keys
10. Exception Handling
Q24: What is the difference between Checked and Unchecked exceptions?
A:
Checked: compile-time (e.g., IOException)
Unchecked: runtime (e.g., NullPointerException)
Q25: Role of try-catch-finally block?
A:
try: code that may throw exception
catch: handles exception
finally: always executed
11. Wrapper Classes
Q26: What are wrapper classes in Java?
A: Classes like Integer, Float, etc., that wrap primitive values into objects.
Q27: What is autoboxing?
A: Automatic conversion from primitive to wrapper class.
12. static and final
Q28: What is the use of static?
A: Belongs to the class rather than instance; shared among all objects.
Q29: Use of final keyword?
A:
Variable: cannot be reassigned
Method: cannot be overridden
Class: cannot be inherited
13. File I/O
Q30: Difference between FileReader and BufferedReader?
A:
FileReader: reads character stream from file
BufferedReader: buffers input for efficient reading
14. Multithreading
Q31: How to create a thread in Java?
A:
Extend Thread class
Implement Runnable interface
Q32: What is synchronization?
A: It prevents thread interference and ensures thread safety.
Q33: Difference between wait() and notify()?
A:
wait(): makes the thread wait
notify(): wakes up a waiting thread
15. Memory Management
Q34: What is finalize() method?
A: Called by garbage collector before object is destroyed.
16. Inner Classes
Q35: What are the types of inner classes?
A:
Static nested class
Non-static inner class
Local inner class
Anonymous inner class
17. Java 8 Features
Q36: What is a Lambda Expression?
A: A concise way to write anonymous methods using ->.
Q37: What is a Functional Interface?
A: An interface with exactly one abstract method.
Q38: What is Stream API?
A: It provides a declarative way to process collections.
18. Miscellaneous
Q39: What is the transient keyword?
A: Marks variables that should not be serialized.
Q40: What is the volatile keyword?
A: Ensures visibility of changes to variables across threads.
Q41: What is enum in Java?
A: A special class representing a group of constants.