Java Interview Questions

Java Interview Questions

🟢 Basic Level (1–20)

  1. What is Java?
  2. What are the features of Java?
  3. Why is Java platform independent?
  4. What is JVM?
  5. What is JRE?
  6. What is JDK?
  7. Difference between JVM, JRE, and JDK?
  8. What is main method in Java?
  9. Why is main method static?
  10. What is OOP in Java?
  11. What are the pillars of OOP?
  12. What is class and object?
  13. What is constructor?
  14. Types of constructors?
  15. What is method overloading?
  16. What is method overriding?
  17. Difference between overloading and overriding?
  18. What is inheritance?
  19. What is polymorphism?
  20. What is encapsulation?

⚙️ Core Concepts (21–40)

  1. What is abstraction?
  2. Difference between abstraction and encapsulation?
  3. What is interface?
  4. Difference between abstract class and interface?
  5. What is package in Java?
  6. What is access modifier?
  7. Types of access modifiers?
  8. What is static keyword?
  9. What is final keyword?
  10. What is this keyword?
  11. What is super keyword?
  12. What is exception handling?
  13. Types of exceptions?
  14. What is try-catch block?
  15. What is finally block?
  16. What is throw vs throws?
  17. What is multithreading?
  18. What is thread lifecycle?
  19. What is synchronization?
  20. What is deadlock?

📊 Collections & Java Core (41–60)

  1. What is Java Collections Framework?
  2. What is List?
  3. What is Set?
  4. What is Map?
  5. Difference between List and Set?
  6. Difference between ArrayList and LinkedList?
  7. What is HashMap?
  8. Difference between HashMap and Hashtable?
  9. What is TreeMap?
  10. What is Iterator?
  11. What is fail-fast iterator?
  12. What is generics in Java?
  13. What is wrapper class?
  14. What is autoboxing?
  15. What is unboxing?
  16. What is String?
  17. Difference between String, StringBuffer, StringBuilder?
  18. What is immutable object?
  19. What is garbage collection?
  20. What is memory management in Java?

⚡ Advanced Level (61–80)

  1. What is JVM architecture?
  2. What is class loader?
  3. Types of class loaders?
  4. What is heap memory?
  5. What is stack memory?
  6. What is method area?
  7. What is JIT compiler?
  8. What is bytecode?
  9. What is reflection in Java?
  10. What is serialization?
  11. What is deserialization?
  12. What is transient keyword?
  13. What is volatile keyword?
  14. What is lambda expression?
  15. What is functional interface?
  16. What is Stream API?
  17. What is Optional class?
  18. What is garbage collector types?
  19. What is GC tuning?
  20. What is JVM optimization?

🚀 Scenario-Based (81–100)

  1. How does Java handle memory leaks?
  2. How to improve Java performance?
  3. How to handle exceptions in real projects?
  4. How to design scalable Java application?
  5. How to implement REST API in Java?
  6. How does Spring Boot work?
  7. What is dependency injection?
  8. What is microservices architecture?
  9. How to handle multithreading issues?
  10. How to avoid deadlock?
  11. How to optimize SQL queries in Java apps?
  12. How to secure Java applications?
  13. How to test Java applications?
  14. What is unit testing?
  15. What is Mockito?
  16. What is Maven?
  17. What is Gradle?
  18. What is CI/CD in Java projects?
  19. Why Java is still popular?
  20. Where is Java used in real world?

Java Interview Answers (1–100)

🟢 Basic (1–20)

  1. Java is a high-level, object-oriented programming language
  2. Platform-independent, OOP, secure, robust, multithreaded
  3. Because it runs on JVM
  4. JVM = runs Java bytecode
  5. JRE = JVM + libraries
  6. JDK = JRE + development tools
  7. JVM runs code, JRE provides environment, JDK is full kit
  8. Entry point of Java program
  9. Because JVM calls it without object creation
  10. Programming based on objects
  11. Encapsulation, Inheritance, Polymorphism, Abstraction
  12. Class = blueprint, Object = instance
  13. Special method to initialize object
  14. Default and parameterized
  15. Same method name, different parameters
  16. Redefining parent method
  17. Overloading = compile-time, overriding = runtime
  18. Reusing code from parent class
  19. One thing many forms
  20. Wrapping data + methods

⚙️ Core (21–40)

  1. Hiding implementation details
  2. Abstraction hides, encapsulation binds
  3. Blueprint of methods
  4. Interface = 100% abstraction, abstract class = partial
  5. Group of classes
  6. Controls access to data
  7. private, default, protected, public
  8. Class-level member
  9. Constant keyword
  10. Refers to current object
  11. Refers to parent class
  12. Handling runtime errors
  13. Checked and unchecked
  14. Block to handle exceptions
  15. Executes always
  16. throw = create exception, throws = declare
  17. Running multiple tasks simultaneously
  18. New, Runnable, Running, Blocked, Dead
  19. Prevents data inconsistency
  20. Two threads waiting forever

📊 Collections (41–60)

  1. Framework for data structures
  2. Ordered collection
  3. Unique elements collection
  4. Key-value pairs
  5. List allows duplicates, Set doesn’t
  6. ArrayList = fast read, LinkedList = fast insert
  7. Hash-based key-value storage
  8. Hashtable = synchronized, HashMap = not
  9. Sorted map
  10. Interface for traversal
  11. Throws exception if modified
  12. Type safety for collections
  13. Class wrapper for primitives
  14. Automatic conversion primitive → object
  15. Object → primitive
  16. String is immutable object
  17. String immutable, StringBuffer thread-safe, StringBuilder fast
  18. Object cannot be changed
  19. Automatic memory cleanup
  20. Managing heap memory

⚡ Advanced (61–80)

  1. Class Loader + Heap + Stack + GC
  2. Loads classes into JVM
  3. Bootstrap, Extension, Application
  4. Stores objects
  5. Stores method calls and variables
  6. Stores class-level data
  7. Converts bytecode to native code
  8. Intermediate code for JVM
  9. Inspect classes at runtime
  10. Convert object to byte stream
  11. Convert byte stream back to object
  12. Prevents serialization
  13. Ensures visibility between threads
  14. Short function syntax
  15. Interface with single abstract method
  16. Functional programming API
  17. Avoids null pointer exceptions
  18. Serial, Parallel, CMS, G1
  19. Optimizing garbage collection
  20. Improving JVM performance

🚀 Scenario (81–100)

  1. Use GC tuning + avoid object leaks
  2. Optimize code + memory + algorithms
  3. Use try-catch-finally properly
  4. Use design patterns + microservices
  5. Using Spring Boot REST controllers
  6. Spring Boot auto-configures application
  7. Object dependency management
  8. Small independent services system
  9. Use synchronization/locks
  10. Avoid nested locks + proper design
  11. Use indexing + query optimization
  12. Use authentication + encryption
  13. Unit + integration testing
  14. Testing individual units
  15. Mocking framework
  16. Build tool for Java projects
  17. Alternative build tool
  18. Automated build & deployment
  19. Simple, secure, scalable language
  20. Web, mobile, enterprise systems