🔰 Beginner Level (1–20)
1. What is Java?
Answer:
Java is a high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now owned by Oracle). It is widely used for web, mobile, desktop, and enterprise applications.
2. Why is Java platform independent?
Answer:
Java code is compiled into bytecode, which runs on the Java Virtual Machine (JVM). JVM is platform-specific, but bytecode is not—making Java platform independent.
3. What is JVM?
Answer:
JVM (Java Virtual Machine) is responsible for executing Java bytecode and converting it into machine-specific instructions.
4. What is JDK?
Answer:
JDK (Java Development Kit) includes:
-
JRE
-
Compiler (
javac) -
Debugger
-
Development tools
Used for developing Java applications.
5. What is JRE?
Answer:
JRE (Java Runtime Environment) provides libraries and JVM to run Java programs, but not to develop them.
6. What are features of Java?
Answer:
-
Object-Oriented
-
Platform Independent
-
Secure
-
Robust
-
Multithreaded
-
High Performance
-
Portable
7. What is Object-Oriented Programming (OOP)?
Answer:
OOP is a programming paradigm based on objects and classes. Java follows OOP principles like inheritance, encapsulation, abstraction, and polymorphism.
8. What is a class?
Answer:
A class is a blueprint from which objects are created. It contains variables and methods.
9. What is an object?
Answer:
An object is an instance of a class that represents a real-world entity.
10. What is encapsulation?
Answer:
Encapsulation means binding data and methods together and hiding internal details using access modifiers.
11. What is inheritance?
Answer:
Inheritance allows a class to acquire properties and methods of another class using the extends keyword.
12. What is polymorphism?
Answer:
Polymorphism allows one method to perform different tasks based on context.
Types:
-
Compile-time (Method Overloading)
-
Runtime (Method Overriding)
13. What is abstraction?
Answer:
Abstraction hides implementation details and shows only essential features using abstract classes or interfaces.
14. What is an interface?
Answer:
An interface is a collection of abstract methods. It supports multiple inheritance in Java.
15. What is an abstract class?
Answer:
An abstract class can have both abstract and non-abstract methods and cannot be instantiated.
16. Difference between abstract class and interface?
Answer:
| Abstract Class | Interface |
|---|---|
| Can have method body | Only abstract methods (before Java 8) |
| Supports inheritance | Supports multiple inheritance |
17. What are access modifiers?
Answer:
Access modifiers define scope of accessibility:
-
public
-
private
-
protected
-
default
18. What is static keyword?
Answer:
static members belong to the class, not objects.
19. What is final keyword?
Answer:
-
Final variable → value cannot change
-
Final method → cannot override
-
Final class → cannot inherit
20. What is constructor?
Answer:
A constructor is a special method used to initialize objects. It has the same name as the class.
⚙️ Intermediate Level (21–50)
21. What is method overloading?
Answer:
Multiple methods with the same name but different parameters in the same class.
22. What is method overriding?
Answer:
A subclass provides its own implementation of a method defined in its parent class.
23. What is this keyword?
Answer:
this refers to the current object of the class.
24. What is super keyword?
Answer:
Used to refer to parent class variables, methods, or constructors.
25. What is exception?
Answer:
An exception is an unexpected event that disrupts program execution.
26. Types of exceptions in Java?
Answer:
-
Checked Exception
-
Unchecked Exception
-
Error
27. Difference between checked and unchecked exception?
Answer:
Checked exceptions are compile-time, unchecked are runtime.
28. What is try-catch block?
Answer:
Used to handle exceptions and prevent program termination.
29. What is finally block?
Answer:
Code inside finally always executes whether exception occurs or not.
30. What is throw keyword?
Answer:
Used to explicitly throw an exception.
31. What is throws keyword?
Answer:
Used to declare exceptions that a method may pass to the caller.
32. What is multithreading?
Answer:
Multithreading allows multiple threads to run concurrently, improving performance.
![]() |
| Java Programming Concepts |
33. What is thread?
Answer:
A thread is a lightweight subprocess that executes independently.
34. How to create a thread in Java?
Answer:
-
Extend
Threadclass -
Implement
Runnableinterface
35. What is synchronization?
Answer:
Synchronization ensures thread-safe access to shared resources.
36. What is deadlock?
Answer:
Deadlock occurs when two threads wait indefinitely for each other’s resources.
37. What is garbage collection?
Answer:
Automatic memory management process that removes unused objects.
38. What is heap memory?
Answer:
Heap memory stores objects and instance variables.
39. What is stack memory?
Answer:
Stack memory stores method calls and local variables.
40. Difference between heap and stack?
Answer:
Heap is shared and larger; stack is fast and thread-specific.
41. What is String in Java?
Answer:
String is an immutable sequence of characters.
42. Difference between String, StringBuilder, StringBuffer?
Answer:
| Type | Mutable | Thread Safe |
|---|---|---|
| String | ❌ | ✅ |
| StringBuilder | ✅ | ❌ |
| StringBuffer | ✅ | ✅ |
43. What is collection framework?
Answer:
A unified architecture to store and manipulate groups of objects.
44. Difference between List and Set?
Answer:
List allows duplicates; Set does not.
45. What is Map?
Answer:
Map stores key-value pairs.
46. Difference between HashMap and Hashtable?
Answer:
HashMap is not synchronized; Hashtable is synchronized.
47. What is iterator?
Answer:
Iterator is used to traverse collection elements.
48. What is lambda expression?
Answer:
Lambda provides a shorter syntax for implementing functional interfaces.
49. What is functional interface?
Answer:
An interface with only one abstract method.
50. What is Stream API?
Answer:
Stream API processes collections in a functional and declarative way.
![]() |
| Java Interview Questions & Answers (Beginner to Intermediate) [2026-27] |
🚀 Advanced Java (51–80)
51. What is JVM memory structure?
Answer:
JVM memory is divided into:
-
Heap
-
Stack
-
Method Area
-
Program Counter (PC)
-
Native Method Stack
52. What is ClassLoader?
Answer:
ClassLoader loads .class files into JVM at runtime.
Types:
-
Bootstrap
-
Extension
-
Application
53. What is reflection in Java?
Answer:
Reflection allows inspecting and modifying classes, methods, fields at runtime.
54. What is serialization?
Answer:
Serialization converts an object into byte stream for storage or transmission.
55. What is deserialization?
Answer:
Converting byte stream back into an object.
56. Difference between Serializable and Externalizable?
Answer:
Serializable is automatic; Externalizable gives full control over serialization.
57. What is transient keyword?
Answer:
Prevents variable from being serialized.
58. What is volatile keyword?
Answer:
Ensures variable visibility across multiple threads.
59. What is Java Memory Model (JMM)?
Answer:
Defines how threads interact with memory and ensures visibility, atomicity, ordering.
60. What is immutable class?
Answer:
A class whose objects cannot be modified after creation (e.g., String).
61. How to create immutable class?
Answer:
-
Make class
final -
Private final fields
-
No setters
-
Return deep copies
62. What is Executor framework?
Answer:
Provides a thread pool mechanism to manage threads efficiently.
63. What is Callable interface?
Answer:
Similar to Runnable but returns result and can throw exceptions.
64. Difference between Runnable and Callable?
Answer:
Runnable → no return
Callable → returns value
65. What is Future?
Answer:
Represents result of asynchronous computation.
66. What is ForkJoinPool?
Answer:
Used for parallel execution of recursive tasks.
67. What is Optional class?
Answer:
Avoids NullPointerException by wrapping optional values.
68. What is method reference?
Answer:
Shorter way to refer to methods using ::.
69. What is Predicate?
Answer:
Functional interface that returns boolean.
70. What is Supplier?
Answer:
Returns value without input.
71. What is Consumer?
Answer:
Consumes input and returns nothing.
72. What is Comparator vs Comparable?
Answer:
Comparable → natural ordering
Comparator → custom ordering
73. What is fail-fast iterator?
Answer:
Throws exception if collection is modified during iteration.
74. What is fail-safe iterator?
Answer:
Works on copy of collection, no exception.
75. What is ConcurrentHashMap?
Answer:
Thread-safe map with better performance than Hashtable.
76. What is design pattern?
Answer:
Reusable solution to common software design problems.
77. What is Singleton pattern?
Answer:
Ensures only one instance of a class.
78. What is Factory pattern?
Answer:
Creates objects without exposing creation logic.
![]() |
| Microservices, REST API, JVM flow |
79. What is Builder pattern?
Answer:
Used to construct complex objects step-by-step.
80. What is Dependency Injection?
Answer:
Objects receive dependencies from external sources.
81. What is Spring Framework?
Answer:
Spring simplifies Java development using IoC and DI.
82. What is Spring Boot?
Answer:
Spring Boot removes boilerplate and provides auto-configuration.
83. What is REST API?
Answer:
REST is architectural style using HTTP methods.
84. Difference between PUT and POST?
Answer:
POST → create
PUT → update
85. What is @RestController?
Answer:
Combines @Controller and @ResponseBody.
86. What is @Autowired?
Answer:
Automatically injects dependencies.
87. What is JPA?
Answer:
Java Persistence API for ORM mapping.
88. What is Hibernate?
Answer:
Popular JPA implementation.
89. What is lazy vs eager loading?
Answer:
Lazy loads when needed; eager loads immediately.
90. What is Microservices architecture?
Answer:
Application divided into small independent services.
91. What is API Gateway?
Answer:
Single entry point for all microservices.
92. What is Docker in Java apps?
Answer:
Used to containerize Java applications.
93. What is CI/CD?
Answer:
Automates build, test, and deployment.
![]() |
| Modern Spring Boot microservices architecture diagram, API gateway, database, cloud deployment |
94. How do you handle exceptions globally in Spring Boot?
Answer:
Using @ControllerAdvice.
95. What is logging framework?
Answer:
Used to log application activities (Log4j, SLF4J).
96. What is JWT?
Answer:
JSON Web Token for secure authentication.
97. What is CORS?
Answer:
Controls cross-origin requests.
98. What is load balancing?
Answer:
Distributes traffic across multiple servers.
99. What is caching?
Answer:
Stores frequently used data for fast access.
100. How do you optimize Java application performance?
Answer:
-
Proper GC tuning
-
Use thread pools
-
Efficient collections
-
Avoid memory leaks
-
Profiling tools

![Java Interview Questions & Answers (Beginner to Intermediate) [2026-27] Java Interview Questions & Answers (Beginner to Intermediate) [2026-27]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAmTH_ZtCz0pGDurDM7pXQoYpsRIzAoXNci6dBPXYqIumznt8HHU_w99OIiqoCQ7tX6Ilk3_dqxAqYZa3HOa75MfuSm4oDnnhy2yijptllZPLqwf1_7Q953jRPnz9damXBBwQ4CYPdeaykXfY4BqTymhxKWr1G0QDNW0mkQ-zecuNJWxd1ruKv8bvgPYN0/w640-h640-rw/Java%20Interview%20Question%20and%20Answers.png)

