Java Interview Questions
🟢 Basic Level (1–20)
- What is Java?
- What are the features of Java?
- Why is Java platform independent?
- What is JVM?
- What is JRE?
- What is JDK?
- Difference between JVM, JRE, and JDK?
- What is main method in Java?
- Why is main method static?
- What is OOP in Java?
- What are the pillars of OOP?
- What is class and object?
- What is constructor?
- Types of constructors?
- What is method overloading?
- What is method overriding?
- Difference between overloading and overriding?
- What is inheritance?
- What is polymorphism?
- What is encapsulation?
⚙️ Core Concepts (21–40)
- What is abstraction?
- Difference between abstraction and encapsulation?
- What is interface?
- Difference between abstract class and interface?
- What is package in Java?
- What is access modifier?
- Types of access modifiers?
- What is static keyword?
- What is final keyword?
- What is this keyword?
- What is super keyword?
- What is exception handling?
- Types of exceptions?
- What is try-catch block?
- What is finally block?
- What is throw vs throws?
- What is multithreading?
- What is thread lifecycle?
- What is synchronization?
- What is deadlock?
📊 Collections & Java Core (41–60)
- What is Java Collections Framework?
- What is List?
- What is Set?
- What is Map?
- Difference between List and Set?
- Difference between ArrayList and LinkedList?
- What is HashMap?
- Difference between HashMap and Hashtable?
- What is TreeMap?
- What is Iterator?
- What is fail-fast iterator?
- What is generics in Java?
- What is wrapper class?
- What is autoboxing?
- What is unboxing?
- What is String?
- Difference between String, StringBuffer, StringBuilder?
- What is immutable object?
- What is garbage collection?
- What is memory management in Java?
⚡ Advanced Level (61–80)
- What is JVM architecture?
- What is class loader?
- Types of class loaders?
- What is heap memory?
- What is stack memory?
- What is method area?
- What is JIT compiler?
- What is bytecode?
- What is reflection in Java?
- What is serialization?
- What is deserialization?
- What is transient keyword?
- What is volatile keyword?
- What is lambda expression?
- What is functional interface?
- What is Stream API?
- What is Optional class?
- What is garbage collector types?
- What is GC tuning?
- What is JVM optimization?
🚀 Scenario-Based (81–100)
- How does Java handle memory leaks?
- How to improve Java performance?
- How to handle exceptions in real projects?
- How to design scalable Java application?
- How to implement REST API in Java?
- How does Spring Boot work?
- What is dependency injection?
- What is microservices architecture?
- How to handle multithreading issues?
- How to avoid deadlock?
- How to optimize SQL queries in Java apps?
- How to secure Java applications?
- How to test Java applications?
- What is unit testing?
- What is Mockito?
- What is Maven?
- What is Gradle?
- What is CI/CD in Java projects?
- Why Java is still popular?
- Where is Java used in real world?
Java Interview Answers (1–100)
🟢 Basic (1–20)
- Java is a high-level, object-oriented programming language
- Platform-independent, OOP, secure, robust, multithreaded
- Because it runs on JVM
- JVM = runs Java bytecode
- JRE = JVM + libraries
- JDK = JRE + development tools
- JVM runs code, JRE provides environment, JDK is full kit
- Entry point of Java program
- Because JVM calls it without object creation
- Programming based on objects
- Encapsulation, Inheritance, Polymorphism, Abstraction
- Class = blueprint, Object = instance
- Special method to initialize object
- Default and parameterized
- Same method name, different parameters
- Redefining parent method
- Overloading = compile-time, overriding = runtime
- Reusing code from parent class
- One thing many forms
- Wrapping data + methods
⚙️ Core (21–40)
- Hiding implementation details
- Abstraction hides, encapsulation binds
- Blueprint of methods
- Interface = 100% abstraction, abstract class = partial
- Group of classes
- Controls access to data
- private, default, protected, public
- Class-level member
- Constant keyword
- Refers to current object
- Refers to parent class
- Handling runtime errors
- Checked and unchecked
- Block to handle exceptions
- Executes always
- throw = create exception, throws = declare
- Running multiple tasks simultaneously
- New, Runnable, Running, Blocked, Dead
- Prevents data inconsistency
- Two threads waiting forever
📊 Collections (41–60)
- Framework for data structures
- Ordered collection
- Unique elements collection
- Key-value pairs
- List allows duplicates, Set doesn’t
- ArrayList = fast read, LinkedList = fast insert
- Hash-based key-value storage
- Hashtable = synchronized, HashMap = not
- Sorted map
- Interface for traversal
- Throws exception if modified
- Type safety for collections
- Class wrapper for primitives
- Automatic conversion primitive → object
- Object → primitive
- String is immutable object
- String immutable, StringBuffer thread-safe, StringBuilder fast
- Object cannot be changed
- Automatic memory cleanup
- Managing heap memory
⚡ Advanced (61–80)
- Class Loader + Heap + Stack + GC
- Loads classes into JVM
- Bootstrap, Extension, Application
- Stores objects
- Stores method calls and variables
- Stores class-level data
- Converts bytecode to native code
- Intermediate code for JVM
- Inspect classes at runtime
- Convert object to byte stream
- Convert byte stream back to object
- Prevents serialization
- Ensures visibility between threads
- Short function syntax
- Interface with single abstract method
- Functional programming API
- Avoids null pointer exceptions
- Serial, Parallel, CMS, G1
- Optimizing garbage collection
- Improving JVM performance
🚀 Scenario (81–100)
- Use GC tuning + avoid object leaks
- Optimize code + memory + algorithms
- Use try-catch-finally properly
- Use design patterns + microservices
- Using Spring Boot REST controllers
- Spring Boot auto-configures application
- Object dependency management
- Small independent services system
- Use synchronization/locks
- Avoid nested locks + proper design
- Use indexing + query optimization
- Use authentication + encryption
- Unit + integration testing
- Testing individual units
- Mocking framework
- Build tool for Java projects
- Alternative build tool
- Automated build & deployment
- Simple, secure, scalable language
- Web, mobile, enterprise systems