Java Interview Questions

148 questions · Core Java, OOP, collections, multithreading, Spring and JVM interview questions.

148 results

1
JavaBeginner#jvm#fundamentals

What is JVM?

Open
2
JavaBeginner#jvm#jdk

Difference between JDK, JRE and JVM?

Open
3
JavaBeginner#operators#object

What is the difference between == and equals() in Java?

Open
4
JavaBeginner#oop

Explain OOP principles in Java.

Open
5
JavaIntermediate#oop#interface

What is the difference between abstract class and interface?

Open
6
JavaBeginner#oop#polymorphism

What is method overloading vs overriding?

Open
7
JavaBeginner#keywords

What is the final keyword?

Open
8
JavaIntermediate#memory#jvm

Explain Java memory model: heap vs stack.

Open
9
JavaIntermediate#gc#memory

What is garbage collection?

Open
10
JavaIntermediate#exceptions

What are checked vs unchecked exceptions?

Open
11
JavaBeginner#strings

What is the difference between String, StringBuilder, and StringBuffer?

Open
12
JavaIntermediate#strings

Why are Strings immutable in Java?

Open
13
JavaIntermediate#collections

Explain the Collections framework hierarchy.

Open
14
JavaBeginner#collections#list

ArrayList vs LinkedList?

Open
15
JavaIntermediate#collections#concurrency

HashMap vs Hashtable vs ConcurrentHashMap?

Open
16
JavaAdvanced#collections#hashmap

How does HashMap work internally?

Open
17
JavaAdvanced#collections

What is the difference between fail-fast and fail-safe iterators?

Open
18
JavaIntermediate#java8#streams

Explain Java 8 Streams.

Open
19
JavaIntermediate#java8#lambda

What are lambda expressions?

Open
20
JavaIntermediate#java8

What is a functional interface?

Open
21
JavaIntermediate#java8

What is Optional?

Open
22
JavaIntermediate#concurrency

Explain multithreading and the Thread lifecycle.

Open
23
JavaAdvanced#concurrency

Difference between synchronized and volatile?

Open
24
JavaAdvanced#concurrency

What is the Executor framework?

Open
25
JavaIntermediate#concurrency

What is the difference between Callable and Runnable?

Open
26
JavaAdvanced#concurrency

Explain wait(), notify() and notifyAll().

Open
27
JavaAdvanced#design-patterns

What is the Singleton pattern? How to implement it thread-safely?

Open
28
JavaIntermediate#design-patterns#spring

What is dependency injection?

Open
29
JavaBeginner#exceptions

What is the difference between throw and throws?

Open
30
JavaIntermediate#exceptions

Explain try-with-resources.

Open
31
JavaIntermediate#fundamentals

What is autoboxing and unboxing?

Open
32
JavaIntermediate#collections

What is the difference between Comparable and Comparator?

Open
33
JavaAdvanced#jvm

What is reflection in Java?

Open
34
JavaIntermediate#generics

What are Java generics?

Open
35
JavaAdvanced#generics

Difference between '? extends T' and '? super T'?

Open
36
JavaAdvanced#concurrency#jvm

What is the Java Memory Model (JMM)?

Open
37
JavaAdvanced#spring

Explain Spring Bean lifecycle.

Open
38
JavaIntermediate#spring

What is the difference between Spring Boot and Spring Framework?

Open
39
JavaIntermediate#jpa

What is JPA vs Hibernate?

Open
40
JavaIntermediate#fundamentals

What is the difference between == and .equals() for Integer in Java?

Open
41
JavaBeginner#fundamentals

What are Java's primitive data types?

Open
42
JavaIntermediate#fundamentals

What is the difference between pass-by-value and pass-by-reference in Java?

Open
43
JavaBeginner#fundamentals

What is the difference between static and instance methods?

Open
44
JavaBeginner#oop

What is a constructor and how does constructor overloading work?

Open
45
JavaIntermediate#oop

What is the difference between instance initializer blocks and constructors?

Open
46
JavaBeginner#object#fundamentals

What is the difference between == and equals() when comparing objects that don't override equals()?

Open
47
JavaIntermediate#object#hashmap

What is the purpose of the hashCode() method and its contract with equals()?

Open
48
JavaBeginner#fundamentals

What is the instanceof operator?

Open
49
JavaBeginner#fundamentals#java10

What is the difference between var and explicit typing in Java 10+?

Open
50
JavaIntermediate#inner-classes

What is the difference between a static nested class and a non-static inner class?

Open
51
JavaIntermediate#inner-classes

What are anonymous inner classes used for?

Open
52
JavaIntermediate#inner-classes

What is a local class in Java?

Open
53
JavaBeginner#fundamentals

What is the difference between an enum and a class with constants?

Open
54
JavaIntermediate#fundamentals#java14

What are records in Java (Java 14+)?

Open
55
JavaAdvanced#fundamentals#java17

What is the difference between sealed classes and final classes (Java 17)?

Open
56
JavaIntermediate#fundamentals#java14

What is the difference between switch statement and switch expression (Java 14+)?

Open
57
JavaBeginner#strings#java15

What is text block syntax in Java (Java 15+)?

Open
58
JavaIntermediate#strings

What is the String pool (intern pool)?

Open
59
JavaBeginner#strings

How do you reverse a String in Java?

Open
60
JavaBeginner#strings

How do you check if a String is a palindrome?

Open
61
JavaBeginner#strings

What is the difference between String.format and concatenation?

Open
62
JavaIntermediate#strings

How do you split a String and handle edge cases with delimiters that are regex special characters?

Open
63
JavaIntermediate#collections

What is the difference between Set implementations HashSet, LinkedHashSet, and TreeSet?

Open
64
JavaIntermediate#collections

What is the difference between Iterator and ListIterator?

Open
65
JavaIntermediate#collections

What is the difference between Deque and Queue?

Open
66
JavaBeginner#collections

How do you make a collection immutable?

Open
67
JavaBeginner#collections

What is the difference between Collection and Collections?

Open
68
JavaIntermediate#generics

What is a bounded type parameter in generics?

Open
69
JavaBeginner#generics

Can you use primitive types with generics?

Open
70
JavaAdvanced#generics

What is type erasure in Java generics?

Open
71
JavaIntermediate#collections

How do you sort a List of custom objects by multiple fields?

Open
72
JavaBeginner#generics

What is the diamond operator in generics?

Open
73
JavaBeginner#exceptions

What is the exception hierarchy in Java?

Open
74
JavaBeginner#exceptions

What is a custom exception and how do you create one?

Open
75
JavaIntermediate#exceptions

What is exception chaining (cause)?

Open
76
JavaBeginner#exceptions

What is the order of execution for try, catch, and finally?

Open
77
JavaAdvanced#exceptions

What happens if an exception is thrown in a finally block?

Open
78
JavaIntermediate#exceptions

What is multi-catch in Java 7+?

Open
79
JavaIntermediate#concurrency

What is a race condition and how do you prevent it?

Open
80
JavaAdvanced#concurrency

What is a deadlock and how can it be avoided?

Open
81
JavaIntermediate#concurrency

What is the difference between synchronized methods and synchronized blocks?

Open
82
JavaIntermediate#concurrency

What are atomic classes like AtomicInteger used for?

Open
83
JavaAdvanced#concurrency

What is a CountDownLatch?

Open
84
JavaAdvanced#concurrency

What is a ThreadLocal and when would you use it?

Open
85
JavaIntermediate#concurrency

What is the difference between Thread.sleep() and Object.wait()?

Open
86
JavaAdvanced#concurrency

What is the difference between ReentrantLock and synchronized?

Open
87
JavaAdvanced#concurrency#java8

What is a CompletableFuture and how does it improve async programming?

Open
88
JavaIntermediate#concurrency

What are the different thread pool types provided by Executors?

Open
89
JavaAdvanced#concurrency

What is thread starvation?

Open
90
JavaIntermediate#java8#streams

What is the difference between map() and flatMap() in streams?

Open
91
JavaBeginner#streams

What is the difference between Collectors.toList() and Collectors.toSet()?

Open
92
JavaIntermediate#streams

How do you group elements using Collectors.groupingBy?

Open
93
JavaIntermediate#streams

What is the difference between findFirst() and findAny() in streams?

Open
94
JavaBeginner#java8

What is the difference between Optional.of() and Optional.ofNullable()?

Open
95
JavaIntermediate#java8#lambda

What is a method reference and what are its types?

Open
96
JavaIntermediate#streams

What is the difference between Stream.reduce() with and without an identity value?

Open
97
JavaAdvanced#streams

What is a parallel stream and when should you avoid it?

Open
98
JavaAdvanced#memory#gc

What are the different generations in the JVM heap?

Open
99
JavaAdvanced#memory#gc

What causes a memory leak in Java despite having garbage collection?

Open
100
JavaAdvanced#memory#gc

What is the difference between strong, weak, soft, and phantom references?

Open
101
JavaAdvanced#gc#jvm

What is the difference between G1, CMS, and ZGC garbage collectors?

Open
102
JavaIntermediate#gc#memory

What is the purpose of the finalize() method and why is it discouraged?

Open
103
JavaIntermediate#serialization

What is serialization in Java?

Open
104
JavaIntermediate#serialization

What is the purpose of serialVersionUID?

Open
105
JavaIntermediate#serialization

What happens to static and transient fields during serialization?

Open
106
JavaAdvanced#serialization

How can you customize the serialization process?

Open
107
JavaIntermediate#design-patterns

What is the Factory design pattern?

Open
108
JavaIntermediate#design-patterns

What is the Builder pattern and when should you use it?

Open
109
JavaIntermediate#design-patterns

What is the Observer pattern?

Open
110
JavaIntermediate#design-patterns

What is the Strategy pattern?

Open
111
JavaAdvanced#design-patterns

What is the difference between the Adapter and Decorator patterns?

Open
112
JavaAdvanced#design-patterns#oop

What is the difference between composition and inheritance, and why is 'favor composition over inheritance' recommended?

Open
113
JavaAdvanced#design-patterns

What is the Template Method pattern?

Open
114
JavaBeginner#jdbc

What is JDBC and what are its main components?

Open
115
JavaBeginner#jdbc

What is the difference between Statement and PreparedStatement?

Open
116
JavaIntermediate#jdbc

What is a CallableStatement used for?

Open
117
JavaIntermediate#jdbc

What is connection pooling and why is it important?

Open
118
JavaIntermediate#jdbc

How do you manage transactions manually in JDBC?

Open
119
JavaAdvanced#jdbc

What is batch processing in JDBC?

Open
120
JavaBeginner#spring

What is Inversion of Control (IoC) in Spring?

Open
121
JavaIntermediate#spring

What are the different types of dependency injection in Spring?

Open
122
JavaBeginner#spring

What is the difference between @Component, @Service, @Repository, and @Controller?

Open
123
JavaIntermediate#spring

What is Spring Boot auto-configuration?

Open
124
JavaIntermediate#spring

What is the purpose of @RestController vs @Controller in Spring MVC?

Open
125
JavaAdvanced#spring

What is Spring AOP and what is it used for?

Open
126
JavaAdvanced#spring

What is @Transactional and how does it work in Spring?

Open
127
JavaBeginner#spring

What is the difference between application.properties and application.yml in Spring Boot?

Open
128
JavaBeginner#spring

What is the purpose of Spring Boot starters?

Open
129
JavaIntermediate#spring

What is the difference between @RequestParam, @PathVariable, and @RequestBody?

Open
130
JavaIntermediate#spring

What are Spring bean scopes?

Open
131
JavaIntermediate#puzzle#operators

What does this print? int x = 5; System.out.println(x++ + ++x);

Open
132
JavaBeginner#puzzle#strings

What is the output of this code? String s1 = "abc"; String s2 = "abc"; String s3 = new String("abc"); System.out.println(s1 == s2); System.out.println(s1 == s3);

Open
133
JavaAdvanced#puzzle#exceptions

What does this code output and why? try { return 1; } finally { return 2; }

Open
134
JavaAdvanced#puzzle#collections

What is the output? List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); for (Integer i : list) { if (i == 1) list.remove(i); }

Open
135
JavaIntermediate#puzzle#oop

What is the output of this code involving static and instance initialization order? class A { static { System.out.println("static A"); } { System.out.println("instance A"); } A() { System.out.println("constructor A"); } } new A(); new A();

Open
136
JavaIntermediate#puzzle#fundamentals

What does this print? Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d);

Open
137
JavaBeginner#puzzle#operators

What is the output? public class Test { public static void main(String[] args) { System.out.println(10 / 3); System.out.println(10.0 / 3); System.out.println(10 % 3); } }

Open
138
JavaAdvanced#puzzle#oop

What happens when you compile and run this code? class Parent { static void greet() { System.out.println("Parent"); } } class Child extends Parent { static void greet() { System.out.println("Child"); } } Parent p = new Child(); p.greet();

Open
139
JavaIntermediate#puzzle#arrays

What is the output of this array comparison? int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; System.out.println(a == b); System.out.println(a.equals(b)); System.out.println(Arrays.equals(a, b));

Open
140
JavaAdvanced#puzzle#oop

What does this output? class Base { int x = 10; int getX() { return x; } } class Derived extends Base { int x = 20; int getX() { return x; } } Base obj = new Derived(); System.out.println(obj.x); System.out.println(obj.getX());

Open
141
JavaAdvanced#jvm

What is the difference between a class loader's parent delegation model levels: Bootstrap, Extension/Platform, and Application?

Open
142
JavaAdvanced#jvm

What is JIT compilation?

Open
143
JavaIntermediate#oop#fundamentals

What is the difference between shallow copy and deep copy in Java?

Open
144
JavaAdvanced#oop#interface

What is the diamond problem and how does Java avoid it with interfaces?

Open
145
JavaIntermediate#serialization#keywords

What is the purpose of the transient keyword outside of serialization context — does it affect anything else?

Open
146
JavaIntermediate#interface#java8

What is the difference between an interface's default method and a static method?

Open
147
JavaAdvanced#streams#exceptions

What is the difference between checked exception wrapping in streams' lambdas — why can't you throw checked exceptions inside a lambda directly used in a stream?

Open
148
JavaAdvanced#collections#oop

What is the difference between the Comparable interface's compareTo() contract and a poorly implemented one?

Open