All question banksProgramming Languages
Java Questions Comprehensive collection of the most frequently asked Java interview questions covering fundamentals, OOP concepts, collections, multithreading, exception handling, JVM internals, and advanced topics. Each answer is concise, detailed, and interview-ready.
1. What is Java and how is it different from other programming languages? Beginner 2. Explain the concept of 'Write Once, Run Anywhere' (WORA) Beginner 3. What is the Java Virtual Machine (JVM) and its role? Beginner 4. Differentiate between JDK, JRE, and JVM Beginner 5. What are the primitive data types in Java? Beginner 6. What are wrapper classes and why are they used? Beginner 7. What are the four main principles of Object-Oriented Programming? Beginner 8. What is a class in Java and how do you define one? Beginner 9. What is an object in Java? Beginner 10. What is a constructor in Java? Beginner 11. Explain the 'public static void main(String[] args)' method Beginner 12. What is the difference between instance variables and local variables? Beginner 13. What are static variables and methods? Beginner 14. What is method overloading? Beginner 15. What is method overriding? Intermediate 16. What is inheritance in Java? Beginner 17. What is the difference between an interface and an abstract class? Intermediate 18. What is encapsulation and how is it achieved? Beginner 19. What is polymorphism in Java? Intermediate 20. What is abstraction in Java? Intermediate 21. What is the difference between == and equals() method? Beginner 22. What is the String class and is it mutable or immutable? Beginner 23. What is the difference between String, StringBuilder, and StringBuffer? Intermediate 24. What is garbage collection in Java? Intermediate 25. Explain the try-catch-finally block Beginner 26. What is the difference between checked and unchecked exceptions? Intermediate 27. What is the purpose of the final keyword? Beginner 28. What is the this keyword in Java? Beginner 29. What is the super keyword in Java? Beginner 30. What is autoboxing and unboxing? Intermediate 31. What is the Java Collections Framework? Intermediate 32. What is the difference between ArrayList and LinkedList? Intermediate 33. What is the difference between HashMap and Hashtable? Intermediate 34. What is the difference between Set and List? Beginner 35. What is an Iterator and how is it used? Intermediate 36. What is the difference between fail-fast and fail-safe iterators? Advanced 37. What is multithreading in Java? Intermediate 38. What is the difference between Thread and Runnable? Intermediate 39. What is thread synchronization and why is it important? Intermediate 40. Explain the synchronized keyword Intermediate 41. What is a deadlock and how can it be prevented? Advanced 42. What is the volatile keyword? Advanced 43. What are wait(), notify(), and notifyAll() methods? Advanced 44. What is the Java Memory Model? Advanced 45. How does the JVM organize memory? Advanced 46. What is the difference between heap and stack memory? Intermediate 47. What are generics in Java? Intermediate 48. What is serialization and deserialization? Advanced 49. What is the transient keyword? Intermediate 50. What is reflection in Java? Advanced 51. What are lambda expressions in Java 8? Intermediate 52. What are functional interfaces? Intermediate 53. What is the Stream API in Java 8? Intermediate 54. What is the Optional class in Java 8? Intermediate 55. What are default methods in interfaces? Intermediate 56. What is method reference in Java 8? Intermediate 57. What is the difference between Comparable and Comparator? Intermediate 58. What is the difference between Runnable and Callable? Advanced 59. What is Future in Java? Advanced 60. What is ExecutorService? Advanced 61. What is the Singleton design pattern? Advanced 62. What is the Factory design pattern? Advanced 63. What is dependency injection? Advanced 64. What is immutability and its benefits? Advanced 65. What is the difference between throw and throws? Beginner 66. What is a custom exception? Intermediate 67. What is the difference between error and exception? Intermediate 68. What is JDBC and its components? Intermediate 69. What is the difference between Statement and PreparedStatement? Intermediate 70. What is a connection pool? Advanced 71. What is the difference between abstract class and interface in Java 8+? Advanced 72. What is composition over inheritance? Advanced 73. What are SOLID principles? Advanced 74. What is the difference between process and thread? Intermediate 75. What is the CompletableFuture? Advanced 76. What is the fork/join framework? Advanced 77. What is CountDownLatch? Advanced 78. What is CyclicBarrier? Advanced 79. What is Semaphore in Java? Advanced 80. What is ConcurrentHashMap and how does it work? Advanced 81. What is ThreadLocal? Advanced 82. What are atomic variables? Advanced 83. What is the difference between ArrayList and Vector? Intermediate 84. What is the difference between HashSet and TreeSet? Intermediate 85. What is the difference between HashMap and TreeMap? Intermediate 86. What is the equals() and hashCode() contract? Intermediate 87. What is the purpose of the finalize() method? Intermediate 88. What is the difference between shallow copy and deep copy? Advanced 89. What is covariant return type? Advanced 90. What is varargs in Java? Intermediate 91. What are enums in Java? Intermediate 92. What is annotation in Java? Intermediate 93. What is the difference between Array and ArrayList? Beginner 94. What is the difference between String literal and String object? Intermediate 95. What is the classpath in Java? Intermediate 96. What is ClassLoader in Java? Advanced 97. What is the difference between Path and Classpath? Beginner 98. What is Just-In-Time (JIT) compiler? Advanced 99. What are different garbage collection algorithms? Advanced 100. What is the difference between heap and metaspace? Advanced 101. What is pass-by-value in Java? Intermediate 102. What is the instanceof operator? Intermediate 103. What is static import? Intermediate 104. What is the diamond problem and how does Java handle it? Advanced 105. What is the difference between Scanner and BufferedReader? Intermediate 106. What is NIO in Java? Advanced 107. What is the Service Provider Interface (SPI)? Advanced 108. What is the difference between JIT and AOT compilation? Advanced 109. What is the Module System in Java 9? Advanced 110. What are records in Java? Intermediate