100+ Java interview questions
📌
Core Java & OOP
1. What are the main features of Java?
2. What is the difference between JDK, JRE, and JVM?
3. Explain platform independence in Java.
4. What are the data types in Java?
5. Difference between primitive and wrapper classes?
6. Explain == vs equals() in Java.
7. What is the difference between final, finally, and finalize()?
8. What is method overloading vs method overriding?
9. Can we override static methods in Java?
10.Difference between abstract class and interface?
11.Can an interface extend another interface?
12.Can an abstract class have a constructor?
13.What is multiple inheritance? How is it achieved in Java?
14.What is encapsulation? Give an example.
15.Explain polymorphism with examples.
16.What is an inner class in Java?
17.What are anonymous classes?
18.What is a marker interface? Example?
19.Difference between this and super keyword?
20.What is the diamond problem? How does Java solve it?
📌
Strings & Immutable Objects
21.Why are Strings immutable in Java?
22.Difference between String, StringBuilder, and StringBuffer?
23.How does String pooling work?
24.What happens when you do new String("abc")?
25.How does intern() method work?
26.Why is char[] used for storing passwords instead of String?
📌
Java Collections Framework
27.Difference between ArrayList and LinkedList?
28.Difference between HashMap and Hashtable?
29.Difference between HashMap and ConcurrentHashMap?
30.Difference between HashSet and TreeSet?
31.Difference between Array and ArrayList?
32.What is the load factor in HashMap?
33.How does HashMap work internally?
34.What is a fail-fast vs fail-safe iterator?
35.What is the difference between Iterator and ListIterator?
36.Can a HashMap have null key and value?
37.How does LinkedHashMap maintain insertion order?
38.What is the difference between Comparable and Comparator?
39.How does PriorityQueue work?
40.What is CopyOnWriteArrayList?
41.How is WeakHashMap different from HashMap?
42.How does EnumMap differ from HashMap?
43.What is IdentityHashMap?
44.What is difference between Collection and Collections?
45.Explain the difference between Vector and ArrayList.
📌
Multithreading & Concurrency
46.Difference between process and thread?
47.What is context switching in threads?
48.Difference between Runnable and Callable?
49.Difference between sleep() and wait()?
50.Difference between wait(), notify(), and notifyAll()?
51.What is thread-safety?
52.What is a daemon thread?
53.How to create a thread in Java?
54.Difference between synchronized method and block?
55.What is reentrant lock in Java?
56.Difference between Lock and synchronized keyword?
57.What is volatile variable in Java?
58.Difference between AtomicInteger and synchronized block?
59.What is the ThreadLocal class?
60.What is deadlock? How to prevent it?
61.What is livelock vs starvation?
62.What are Executors in Java?
63.Difference between submit() and execute() in ExecutorService?
64.What is ForkJoinPool?
65.What is CompletableFuture in Java 8?
📌
Exception Handling
66.Difference between checked and unchecked exceptions?
67.Difference between throw and throws?
68.What is try-with-resources?
69.Can a finally block be skipped?
70.Can we have multiple catch blocks for a try block?
71.What happens if exception occurs in constructor?
72.What are suppressed exceptions in Java?
73.Difference between Error and Exception?
📌
Java 8+ Features
74.What are lambda expressions?
75.Difference between functional interface and normal interface?
76.What are streams in Java 8?
77.Difference between intermediate and terminal operations in streams?
78.What is Optional in Java?
79.What are default and static methods in interfaces?
80.Difference between map() and flatMap()?
81.What is method reference in Java 8?
82.What are Collectors in streams?
83.Difference between parallelStream() and stream()?
84.What is var in Java 10?
85.What is Records in Java 14?
86.What is sealed class in Java 17?
87.What are switch expressions in Java 12+?
88.Difference between JEPs (Java Enhancement Proposals) and normal updates?
📌
Memory Management & JVM
89.What is the JVM?
90.Explain class loading in Java.
91.Difference between heap and stack memory?
92.What are memory leaks in Java?
93.Explain garbage collection in Java.
94.What are strong, weak, soft, and phantom references?
95.What is metaspace in Java 8?
96.Difference between serial, parallel, and G1 garbage collector?
97.What is JIT compiler?
98.Explain JVM architecture.
99.What are classloaders in Java?
100. Difference between static class loading and dynamic class loading?
📌
Spring & Enterprise Java
101. What is dependency injection in Spring?
102. Difference between BeanFactory and ApplicationContext?
103. What is Spring Boot and why is it used?
104. Difference between REST and SOAP?
105. What is Hibernate?
106. Difference between lazy loading and eager loading in Hibernate?
107. What is caching in Hibernate?
108. What is microservices architecture?
109. Difference between Monolithic and Microservices applications?
110. What is Spring Security?