0% found this document useful (0 votes)
9 views22 pages

Java Interview QuestionBank

The document is a comprehensive question bank for Java interviews, targeting candidates with 0-3 years of experience. It covers various topics such as Core Java, OOP, Collections, Exceptions, Multithreading, and Java 8+ features, with over 300 questions categorized by difficulty. Each section includes a variety of question types, including output-based, scenario-based, and tricky questions to prepare candidates for real interview patterns.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views22 pages

Java Interview QuestionBank

The document is a comprehensive question bank for Java interviews, targeting candidates with 0-3 years of experience. It covers various topics such as Core Java, OOP, Collections, Exceptions, Multithreading, and Java 8+ features, with over 300 questions categorized by difficulty. Each section includes a variety of question types, including output-based, scenario-based, and tricky questions to prepare candidates for real interview patterns.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ JAVA INTERVIEW

COMPLETE QUESTION BANK


0–3 Years Experience | Service-Based & Mid-Level Product Companies

Core Java · OOP · Collections · Exceptions · Multithreading · Java 8+

300+ Questions · Output-Based · Scenario-Based · Tricky · Real Interview Pattern

DIFFICULTY LEGEND

BASIC Fresher level — expected from all candidates

MEDIUM Real interview standard — must know

TRICKY Conceptual depth — separates good candidates

OUTPUT Predict output of given code snippet

SCENARI
Design / real-world application of concepts
O

Section Topic Questions

1 Core Java Fundamentals 45

2 OOP Concepts 50

3 Collections Framework 55

4 Exception Handling 30

5 Multithreading 40

6 Java 8+ Features 50

7 Mixed / Cross-Topic 30

TOTAL 300+
■ SECTION 1 — CORE JAVA FUNDAMENTALS

1A. Java Basics & Platform

Q1. What is Java? Why is it called platform-independent? BASIC

Q2. What is the difference between JDK, JRE, and JVM? BASIC

Q3. What happens when you run a Java program — explain the full flow from .java to output? MEDIUM

Q4. What is bytecode? Who generates it and who executes it? BASIC

Q5. What is the difference between the Interpreter and the JIT Compiler inside JVM? MEDIUM

Q6. Why is JVM not platform-independent but Java is? TRICKY

Q7. What are the 11 features of Java? Explain any 5 that matter in real projects. MEDIUM

Q8. Is Java 100% object-oriented? Why or why not? TRICKY

Q9. What does 'Write Once, Run Anywhere' really mean in a CI/CD deployment context? SCENARIO

Q10. What is the difference between Java being compiled and interpreted? MEDIUM

1B. JVM Memory & Garbage Collection

Q11. Explain all 5 memory areas of JVM with what is stored in each. MEDIUM

Q12. What is the difference between Stack memory and Heap memory? BASIC

Q13. Where are static variables stored — Stack or Heap? TRICKY

Q14. Where are local variables stored? Where are objects stored? BASIC

Q15. What is Metaspace in Java 8+? How is it different from PermGen? MEDIUM

Q16. What is Garbage Collection? How does it decide which objects to collect? BASIC

Q17. What are the different types of GC algorithms — Serial, Parallel, CMS, G1, ZGC? MEDIUM

Q18. What is Minor GC vs Major GC vs Full GC? MEDIUM

Q19. What is the difference between Young Generation, Old Generation? MEDIUM

Q20. When does OutOfMemoryError occur? What JVM flag do you adjust? MEDIUM

Q21. When does StackOverflowError occur? Give a practical example. MEDIUM

Q22. Can you force Garbage Collection? Is [Link]() reliable? TRICKY

Q23. What is finalize() method? Why was it deprecated in Java 9+? TRICKY

Q24. What are strong, soft, weak, and phantom references in Java? TRICKY

Q25. If an object has a circular reference, will GC collect it? Why? TRICKY

1C. Data Types, Type Casting & Operators

Q26. What are the 8 primitive data types in Java with their sizes? BASIC

Q27. What is the default value of each primitive type and reference type? BASIC

Q28. What is the difference between widening and narrowing type conversion? BASIC
Q29. What is the range of int? What happens when you go beyond it (overflow)? MEDIUM

Q30. Why should you never use float or double for currency/financial calculations? MEDIUM

Q31. What is the difference between prefix (++i) and postfix (i++) operators? MEDIUM

Q32. What is short-circuit evaluation in && and || operators? MEDIUM

Q33. What are bitwise operators? Where are they used in real backend code? MEDIUM

Q34. What does the >>> (unsigned right shift) operator do differently from >>? TRICKY

Q35. What is the output of this code? (Integer overflow) OUTPUT

int x = Integer.MAX_VALUE; [Link](x + 1); [Link](Integer.MIN_VALUE == x +


1);

Q36. What is the output? (prefix vs postfix) OUTPUT

int a = 5; int b = a++ + ++a; [Link](a); [Link](b);

1D. Strings, String Pool & Wrapper Classes

Q37. Why are Strings immutable in Java? What are the advantages? MEDIUM

Q38. What is the String Pool (String Intern Pool)? Where does it live in Java 7+ vs earlier? MEDIUM

Q39. What is the difference between String s = 'hello' and new String('hello')? MEDIUM

Q40. What does [Link]() do? When would you use it? TRICKY

Q41. What are Wrapper classes? Why do we need them? BASIC

Q42. What is autoboxing and unboxing? When can unboxing cause a NullPointerException? MEDIUM

Q43. What is the Integer cache? Which range is cached and what is the trap? TRICKY

Q44. Is Java pass-by-value or pass-by-reference? Prove it with an example. MEDIUM

Q45. What is the output? Explain the == vs equals() behavior for String and Integer. OUTPUT

String s1 = "hello"; String s2 = "hello"; String s3 = new String("hello"); Integer a = 127, b =


127; Integer x = 200, y = 200; [Link](s1 == s2); [Link](s1 == s3);
[Link]([Link](s3)); [Link](a == b); [Link](x == y);
■■ SECTION 2 — OOP CONCEPTS

2A. OOP Pillars & Class Design

Q46. What are the 4 pillars of OOP? Define each in one crisp line. BASIC

Q47. What is the difference between a Class and an Object? BASIC

Q48. What is the difference between instance variables and local variables? BASIC

Q49. What is the difference between instance methods and static methods? BASIC

Q50. Where would you actually use a static method in a real project? SCENARIO

Q51. What is a static block? When does it run? Can it throw an exception? MEDIUM

Q52. Can a class be both abstract and final? Can a method be both static and abstract? TRICKY

Q53. What is a POJO? How is it different from a JavaBean? MEDIUM

2B. Constructors

Q54. What is a constructor? How is it different from a method? BASIC

Q55. What is a default constructor? When does the compiler NOT generate one? MEDIUM

Q56. What is constructor overloading? BASIC

Q57. What is constructor chaining? Explain this() and super() with rules. MEDIUM

Q58. Can a constructor be private? When would you use a private constructor? TRICKY

Q59. What is a copy constructor? Java doesn't have one built-in — how do you implement it? MEDIUM

Q60. What happens if you call super() explicitly in a child constructor vs not calling it? TRICKY

Q61. Can a constructor return a value? What is its return type? TRICKY

2C. Encapsulation

Q62. What is encapsulation? How do you achieve it in Java? BASIC

Q63. What is data hiding? How is it different from abstraction? MEDIUM

Q64. Why is it a bad practice to make fields public? Give a real-world consequence. MEDIUM

Q65. What is the JavaBean convention? Why is it important in frameworks like Spring and Hibernate? MEDIUM

Q66. Can you have a getter without a setter? When and why would you do that? SCENARIO

Q67. How would you implement an immutable class in Java? List all the rules. TRICKY

Q68. Why is String itself an example of an immutable (encapsulated) class? TRICKY

2D. Inheritance

Q69. What is inheritance? What keyword is used? BASIC

Q70. What are the 5 types of inheritance? Which ones does Java support? MEDIUM

Q71. Why does Java NOT support multiple inheritance with classes? What is the diamond problem? MEDIUM

Q72. How does Java solve the diamond problem using interfaces? TRICKY
Q73. What is the difference between IS-A and HAS-A relationships? MEDIUM

Q74. When should you prefer composition over inheritance? SCENARIO

Q75. What is method hiding? How is it different from method overriding? TRICKY

Q76. Can a subclass constructor call a superclass constructor? What are the rules? MEDIUM

Q77. What does the 'final' keyword do to a class, method, and variable? MEDIUM

Q78. What is the difference between extends and implements? BASIC

Q79. What is the output? (Constructor chaining in inheritance) OUTPUT

class A { A() { [Link]("A constructor"); } } class B extends A { B() {


[Link]("B constructor"); } } class C extends B { C() { [Link]("C
constructor"); } } public class Test { public static void main(String[] args) { new C(); } }

2E. Polymorphism — Overloading & Overriding

Q80. What is polymorphism? What are its two types in Java? BASIC

Q81. What is method overloading? What can differ between overloaded methods? BASIC

Q82. Can you overload a method based only on the return type? Why or why not? TRICKY

Q83. What is method overriding? What are the exact rules for valid overriding? MEDIUM

Q84. What is the @Override annotation? Why should you always use it? MEDIUM

Q85. Can private, static, or final methods be overridden? Why? TRICKY

Q86. What is covariant return type? In which Java version was it introduced? TRICKY

Q87. What is dynamic method dispatch (virtual method invocation)? MEDIUM

Q88. What is the difference between static binding (compile-time) and dynamic binding (runtime)? MEDIUM

Q89. If a parent class method throws IOException, can the overriding child method throw Exception? Why? TRICKY

Q90. What is the output? (Runtime polymorphism) OUTPUT

class Animal { void sound() { [Link]("Animal sound"); } } class Dog extends Animal {
void sound() { [Link]("Dog barks"); } } public class Test { public static void
main(String[] args) { Animal a = new Dog(); [Link](); } }

Q91. What is the output? (Overloading resolution — tricky) OUTPUT

class Test { static void print(int x) { [Link]("int: " + x); } static void print(long
x) { [Link]("long: " + x); } static void print(double x) {
[Link]("double: " + x); } public static void main(String[] args) { print(10);
print(10L); print(10.0); byte b = 5; print(b); } }

2F. Abstraction — Abstract Class & Interface

Q92. What is abstraction? How is it different from encapsulation? MEDIUM

Q93. What is an abstract class? Can it have constructors? Can it have concrete methods? BASIC

Q94. What is an interface? What can and cannot it contain (before Java 8)? BASIC

Q95. What changed in interfaces with Java 8 (default and static methods)? MEDIUM

Q96. What changed with interfaces in Java 9 (private methods in interfaces)? TRICKY
Q97. What is the difference between an abstract class and an interface — detailed comparison? MEDIUM

Q98. Can you instantiate an abstract class? Can you instantiate an interface? BASIC

Q99. When would you choose an abstract class over an interface in real project design? SCENARIO

Q10 What is a marker interface? Give two examples from the JDK. MEDIUM

0.

Q10 What is a functional interface? Give 5 examples from [Link]. MEDIUM

1.

Q10 Can an interface extend another interface? Can it extend multiple interfaces? TRICKY

2.

Q10 What happens if a class implements two interfaces that have a default method with the same TRICKY

3. signature?

Q10 Where do you use abstraction in your real projects? Give a concrete example. SCENARIO

4.

Q10 Design a notification system using abstract class and interface. Which would you use and why? SCENARIO

5.

2G. Keywords: this, super, final, instanceof

Q10 What are the 3 uses of the 'this' keyword? BASIC

6.

Q10 What are the 3 uses of the 'super' keyword? BASIC

7.

Q10 What is the difference between this() and super() and what is the constraint on their placement? MEDIUM

8.

Q10 What is upcasting? Is it implicit or explicit? MEDIUM

9.

Q11 What is downcasting? When can it throw a ClassCastException? MEDIUM

0.

Q11 How do you safely downcast? What operator do you use? BASIC

1.

Q11 What is pattern matching instanceof (Java 16+)? How does it improve downcasting? TRICKY

2.

Q11 Can you use 'this' inside a static method? Why? MEDIUM

3.

Q11 What is the output? (this() and super() chain) OUTPUT

4.

class Parent { int x; Parent(int x) { this.x = x; [Link]("Parent: " + x); } } class


Child extends Parent { int y; Child(int x, int y) { super(x); this.y = y;
[Link]("Child: " + y); } } new Child(10, 20);
■ SECTION 3 — COLLECTIONS FRAMEWORK

3A. Framework Overview & Hierarchy

Q11 What is the Java Collections Framework (JCF)? What problem does it solve? BASIC

5.

Q11 Draw/describe the hierarchy: Iterable → Collection → List / Set / Queue. Where does Map fit? MEDIUM

6.

Q11 What is the difference between Collection (interface) and Collections (utility class)? MEDIUM

7.

Q11 What is the difference between Arrays and Collections? When would you choose one over the other? MEDIUM

8.

Q11 What are the key differences between List, Set, and Map interfaces? BASIC

9.

Q12 What is the difference between synchronized collections and concurrent collections? MEDIUM

0.

3B. List — ArrayList & LinkedList

Q12 What is ArrayList? How does it store elements internally? BASIC

1.

Q12 What is the default capacity of ArrayList? How does it grow when full? MEDIUM

2.

Q12 What is the time complexity of get(), add(), add(index), remove(index) for ArrayList? MEDIUM

3.

Q12 What is LinkedList? How does it store elements internally (doubly-linked)? BASIC

4.

Q12 Compare ArrayList vs LinkedList for: random access, insertion in middle, memory usage. MEDIUM

5.

Q12 When should you NEVER use LinkedList? When is it better than ArrayList? SCENARIO

6.

Q12 What is the difference between ArrayList and Vector? MEDIUM

7.

Q12 What is CopyOnWriteArrayList? When would you use it? TRICKY

8.

Q12 How do you make an ArrayList thread-safe? What are the options? MEDIUM

9.

Q13 What does [Link]() do? Is it truly immutable? TRICKY

0.

Q13 What happens when you run this code? Why? OUTPUT

1.

List<String> list = new ArrayList<>([Link]("A", "B", "C")); for (String s : list) { if


([Link]("B")) [Link](s); } [Link](list);
3C. Set — HashSet, LinkedHashSet, TreeSet

Q13 What guarantees does a Set provide? How is it different from a List? BASIC

2.

Q13 How does HashSet check for duplicates internally? MEDIUM

3.

Q13 What data structure backs a HashSet internally? TRICKY

4.

Q13 What happens if you add an object to a HashSet without overriding hashCode() and equals()? TRICKY

5.

Q13 What is LinkedHashSet? What ordering does it maintain? BASIC

6.

Q13 What is TreeSet? What ordering does it use? What interface must elements implement? MEDIUM

7.

Q13 Compare HashSet vs LinkedHashSet vs TreeSet for: ordering, performance, null handling. MEDIUM

8.

Q13 Can HashSet store null? Can TreeSet store null? Why the difference? TRICKY

9.

Q14 What is NavigableSet? Name 4 methods that TreeSet provides through NavigableSet. TRICKY

0.

3D. Map — HashMap (DEEP DIVE)

Q14 What is HashMap? What data structure does it use internally? BASIC

1.

Q14 Explain step-by-step how [Link](key, value) works internally. MEDIUM

2.

Q14 What is hashing? What is a hash collision? How does HashMap handle it? MEDIUM

3.

Q14 What changed in Java 8 with HashMap's collision handling (treeification)? MEDIUM

4.

Q14 What is the default initial capacity and load factor of HashMap? When does it resize? MEDIUM

5.

Q14 What is rehashing? Why is it expensive? How do you avoid it? TRICKY

6.

Q14 What is the contract between hashCode() and equals()? What happens if you violate it? TRICKY

7.

Q14 Can HashMap have duplicate keys? Can it have duplicate values? Can it have a null key? MEDIUM

8.

Q14 What is the difference between HashMap, Hashtable, LinkedHashMap, and TreeMap? MEDIUM

9.

Q15 What is ConcurrentHashMap? How is it different from Hashtable? MEDIUM

0.

Q15 How does ConcurrentHashMap achieve thread safety without locking the entire map? TRICKY

1.
Q15 What is getOrDefault()? What is computeIfAbsent()? When do you use each? MEDIUM

2.

Q15 What is the difference between put() and putIfAbsent()? MEDIUM

3.

Q15 How would you implement an LRU cache using LinkedHashMap? SCENARIO

4.

Q15 You have 1 million records to store in a HashMap — what initial capacity should you set and why? SCENARIO

5.

Q15 What is the output? (HashMap key mutation — the broken contract) OUTPUT

6.

Map<List<Integer>, String> map = new HashMap<>(); List<Integer> key = new


ArrayList<>([Link](1, 2)); [Link](key, "value"); [Link]([Link](key)); //
Line A [Link](3); [Link]([Link](key)); // Line B — what happens?

3E. Queue, Deque, Stack & PriorityQueue

Q15 What is a Queue? What are the two sets of Queue methods and how do they differ in failure behavior? MEDIUM

7.

Q15 What is the difference between offer(), add(), poll(), remove(), peek(), element()? MEDIUM

8.

Q15 What is ArrayDeque? Why is it preferred over LinkedList for Queue/Stack use cases? MEDIUM

9.

Q16 What is a PriorityQueue? What ordering does it use by default? BASIC

0.

Q16 How do you create a max-heap using PriorityQueue? MEDIUM

1.

Q16 Why is the Stack class considered legacy? What should you use instead? MEDIUM

2.

Q16 What is BlockingQueue? Name two implementations and when to use them. TRICKY

3.

Q16 Design an order processing system using a PriorityQueue where premium orders are processed first. SCENARIO

4.

3F. Iterator, Comparable & Comparator

Q16 What is an Iterator? What are its 3 methods? BASIC

5.

Q16 What is a ListIterator? How is it different from Iterator? MEDIUM

6.

Q16 What is the difference between fail-fast and fail-safe iterators? Give one example of each. MEDIUM

7.

Q16 Why does ConcurrentModificationException occur and how do you avoid it? MEDIUM

8.

Q16 How do you safely remove elements from a collection while iterating? MEDIUM

9.
Q17 What is the difference between Comparable and Comparator? MEDIUM

0.

Q17 Which package does Comparable belong to? Which does Comparator belong to? BASIC

1.

Q17 What does compareTo() return — explain negative, zero, positive values. MEDIUM

2.

Q17 How do you sort a list by multiple fields using [Link]().thenComparing()? MEDIUM

3.

Q17 Can you pass a null-safe Comparator? What is [Link]() / nullsLast()? TRICKY

4.

Q17 What is the output? (Comparator chain) OUTPUT

5.

List<String> names = [Link]("Charlie", "Alice", "Bob", "alice");


[Link](String.CASE_INSENSITIVE_ORDER); [Link](names);
[Link]([Link]()); [Link](names);
■■ SECTION 4 — EXCEPTION HANDLING

4A. Exception Hierarchy & Types

Q17 What is the Throwable hierarchy — draw it: Throwable → Error / Exception. BASIC

6.

Q17 What is the difference between Error and Exception? BASIC

7.

Q17 What is the difference between checked and unchecked exceptions? BASIC

8.

Q17 Give 5 examples of checked exceptions and 5 examples of unchecked exceptions. BASIC

9.

Q18 What is RuntimeException? Does it need to be declared in throws clause? MEDIUM

0.

Q18 What are common JVM Errors — StackOverflowError, OutOfMemoryError, ExceptionInInitializerError? MEDIUM

1.

Q18 Can you catch an Error? Should you? When might you? TRICKY

2.

Q18 What is the difference between NoClassDefFoundError and ClassNotFoundException? TRICKY

3.

4B. try-catch-finally & try-with-resources

Q18 What is the execution order of try, catch, and finally blocks? BASIC

4.

Q18 Does finally always execute? Name the two scenarios where it does NOT. MEDIUM

5.

Q18 What happens if both the try block and the finally block throw an exception? TRICKY

6.

Q18 Can a finally block override a return value from a try block? Is this good practice? TRICKY

7.

Q18 What is multi-catch (catch multiple exception types in one block)? What Java version introduced it? MEDIUM

8.

Q18 What is try-with-resources? What interface must the resource implement? MEDIUM

9.

Q19 What is the closing order of resources in try-with-resources with multiple resources? TRICKY

0.

Q19 What is suppressed exception in try-with-resources? How do you access it? TRICKY

1.

Q19 What is exception chaining / wrapping? Why is it important for debugging? MEDIUM

2.

Q19 What is the output of this try-catch-finally code? OUTPUT

3.
public static int test() { try { [Link]("try"); return 1; } catch (Exception e) {
[Link]("catch"); return 2; } finally { [Link]("finally"); return 3; //
<-- overrides try's return! } } [Link](test());

Q19 What is the output? (Exception in catch block) OUTPUT

4.

try { int[] arr = new int[5]; arr[10] = 1; // ArrayIndexOutOfBoundsException } catch


(ArrayIndexOutOfBoundsException e) { [Link]("Caught: " + [Link]()); int x = 10
/ 0; // ArithmeticException inside catch! } finally { [Link]("Finally runs"); }

4C. throw, throws & Custom Exceptions

Q19 What is the difference between throw and throws? BASIC

5.

Q19 When do you use throws on a method signature vs try-catch inside the method? MEDIUM

6.

Q19 How do you create a custom exception? When should it extend Exception vs RuntimeException? MEDIUM

7.

Q19 Why should custom exceptions in REST APIs typically be unchecked (RuntimeException)? SCENARIO

8.

Q19 What is the best practice for exception messages in a production microservice? SCENARIO

9.

Q20 What is the difference between re-throwing an exception and wrapping it? MEDIUM

0.

Q20 Your REST API throws a generic Exception up the call stack. What are the problems with this design? SCENARIO

1.

Q20 How does Spring's @ControllerAdvice + @ExceptionHandler pattern work to handle custom SCENARIO

2. exceptions?

Q20 Can you throw a checked exception from a lambda expression? Why is this a problem? TRICKY

3.

Q20 What is the difference between catching Exception vs Throwable? TRICKY

4.

Q20 In a multi-catch block, can the caught types be in an inheritance relationship? TRICKY

5.
■ SECTION 5 — MULTITHREADING

5A. Thread Basics & Lifecycle

Q20 What is a thread? How is it different from a process? BASIC

6.

Q20 What are the two ways to create a thread in Java? Which is preferred and why? BASIC

7.

Q20 What is Runnable vs Callable? What is the key difference in their return type? MEDIUM

8.

Q20 What are all 6 states of a Thread lifecycle? Draw/describe the transitions. MEDIUM

9.

Q21 What is the difference between start() and run() methods? What happens if you call run() directly? MEDIUM

0.

Q21 What is sleep()? What is join()? What is yield()? MEDIUM

1.

Q21 What is a daemon thread? How do you mark a thread as daemon? MEDIUM

2.

Q21 What is the difference between user threads and daemon threads at JVM shutdown? TRICKY

3.

Q21 What is thread priority in Java? Does it guarantee execution order? MEDIUM

4.

5B. Thread Safety — synchronized, volatile, Atomic

Q21 What is a race condition? Give a practical example. MEDIUM

5.

Q21 What does the synchronized keyword do? What is the lock/monitor it uses? MEDIUM

6.

Q21 What is the difference between synchronized method and synchronized block? Which is better and MEDIUM

7. why?

Q21 What does static synchronized mean? What object does it lock on? TRICKY

8.

Q21 What is the volatile keyword? What problem does it solve? MEDIUM

9.

Q22 Why is volatile NOT enough to make i++ thread-safe? TRICKY

0.

Q22 What is AtomicInteger? How does it differ from using synchronized for a counter? MEDIUM

1.

Q22 What is the difference between synchronized, volatile, and Atomic classes — when do you use each? TRICKY

2.

Q22 What is the happens-before relationship in Java Memory Model? TRICKY

3.
Q22 What is a ThreadLocal variable? When would you use it in a web application? TRICKY

4.

Q22 Is this counter implementation thread-safe? What output do you expect from 1000 threads each calling OUTPUT

5. increment()?

class Counter { private int count = 0; public void increment() { count++; } // NOT atomic! public
int getCount() { return count; } } // Expected: 1000 | Actual: often < 1000 — why?

5C. Deadlock, wait/notify & ExecutorService

Q22 What is a deadlock? What are the 4 conditions for deadlock to occur? MEDIUM

6.

Q22 How do you prevent a deadlock in Java? Give 3 strategies. TRICKY

7.

Q22 What is the difference between wait(), notify(), and notifyAll()? MEDIUM

8.

Q22 Which class do wait(), notify(), and notifyAll() belong to? In which context must they be called? TRICKY

9.

Q23 What is the difference between sleep() and wait()? MEDIUM

0.

Q23 What is an ExecutorService? Why use it instead of creating Thread objects directly? MEDIUM

1.

Q23 What is the difference between newFixedThreadPool(), newCachedThreadPool(), and MEDIUM

2. newSingleThreadExecutor()?

Q23 What is the difference between submit() and execute() in ExecutorService? MEDIUM

3.

Q23 What is a Future? How do you get a result from a Callable via Future? MEDIUM

4.

Q23 What is a CompletableFuture? How is it different from Future? TRICKY

5.

Q23 What is the difference between shutdown() and shutdownNow() in ExecutorService? MEDIUM

6.

Q23 What is a thread pool? Why does it improve performance over creating a new thread per request? MEDIUM

7.

Q23 Your web server creates a new Thread for every HTTP request. What is the problem with this SCENARIO

8. approach?

Q23 How would you implement a producer-consumer pattern in Java? SCENARIO

9.

Q24 What is a ReentrantLock? How is it different from synchronized? TRICKY

0.

Q24 What is tryLock()? How does it help prevent deadlocks? TRICKY

1.

Q24 What is a CountDownLatch? When would you use it? TRICKY

2.
Q24 What is a CyclicBarrier? How is it different from CountDownLatch? TRICKY

3.

Q24 What is a Semaphore? Give a real-world use case. TRICKY

4.

Q24 What is the ForkJoinPool? What kind of tasks is it designed for? TRICKY

5.
■ SECTION 6 — JAVA 8+ FEATURES

6A. Lambda Expressions & Functional Interfaces

Q24 What is a lambda expression? What is its syntax? BASIC

6.

Q24 What is a functional interface? What annotation marks it? BASIC

7.

Q24 What is the purpose of @FunctionalInterface — is it mandatory? MEDIUM

8.

Q24 What are the 4 core functional interfaces in [Link]? BASIC

9.

Q25 What is the signature of Predicate? Function? Consumer? Supplier? MEDIUM

0.

Q25 What is a BiFunction? What is a BinaryOperator? How are they related? MEDIUM

1.

Q25 What is a UnaryOperator? How does it differ from Function? MEDIUM

2.

Q25 Compose two Predicates using and(), or(), negate(). Write an example. MEDIUM

3.

Q25 What is a method reference? What are the 4 types of method references? MEDIUM

4.

Q25 When should you use a method reference vs a lambda? Is one always better? MEDIUM

5.

Q25 Can a lambda capture local variables from its enclosing scope? What rule must they follow? TRICKY

6.

Q25 What is the difference between a lambda and an anonymous inner class? TRICKY

7.

Q25 Can you serialize a lambda expression? TRICKY

8.

Q25 What is the output? (Variable capture in lambda) OUTPUT

9.

int x = 10; Runnable r = () -> [Link](x); [Link](); // Now try: x = 20; -- does it
compile? Why?

6B. Stream API — Core Operations

Q26 What is the Stream API? What problem does it solve? BASIC

0.

Q26 What is the difference between intermediate and terminal operations? Give 5 examples of each. MEDIUM

1.

Q26 What does it mean that streams are lazy? Prove it with an example. TRICKY

2.
Q26 What is the difference between map() and flatMap()? Give a clear example. MEDIUM

3.

Q26 What is filter()? What type must the predicate return? BASIC

4.

Q26 What is reduce()? What is its identity element? Write an example summing a list. MEDIUM

5.

Q26 What is collect()? What is [Link](), toSet(), toMap(), groupingBy(), joining()? MEDIUM

6.

Q26 What is the difference between findFirst() and findAny()? When does findAny() differ? TRICKY

7.

Q26 What is peek()? When is it useful? Why should you not use it for side effects? TRICKY

8.

Q26 What is distinct()? What does it use internally to determine uniqueness? MEDIUM

9.

Q27 What is the difference between sorted() with no arg vs sorted(Comparator)? MEDIUM

0.

Q27 What is the difference between count(), sum(), average(), min(), max()? MEDIUM

1.

Q27 What is a Collector? How do you implement a custom Collector? TRICKY

2.

Q27 What is [Link]()? Write a query to group orders by status. MEDIUM

3.

Q27 What is [Link]()? How is it different from groupingBy()? TRICKY

4.

Q27 Can a stream be reused after a terminal operation? What exception do you get? MEDIUM

5.

Q27 What is an IntStream, LongStream, DoubleStream? Why use them over Stream? TRICKY

6.

Q27 When should you NOT use streams? What are their performance trade-offs? TRICKY

7.

Q27 What is the output? (Stream laziness — how many elements are processed?) OUTPUT

8.

List<Integer> nums = [Link](1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Optional<Integer> result =


[Link]() .filter(n -> { [Link]("filter: " + n); return n % 2 == 0; }) .map(n ->
{ [Link]("map: " + n); return n * n; }) .findFirst(); [Link]("Result: " +
[Link]());

Q27 Write a stream pipeline to: given a list of employees, find the top 3 highest-paid employees in the OUTPUT

9. 'Engineering' department, returning their names as a comma-separated String.

// Input: List<Employee> where Employee has: name, dept, salary // Expected output: "Alice, Bob,
Charlie" (sorted desc by salary) String result = [Link]() .filter(e ->
"Engineering".equals([Link]()))
.sorted([Link](Employee::getSalary).reversed()) .limit(3)
.map(Employee::getName) .collect([Link](", "));
6C. Parallel Streams

Q28 What is a parallel stream? How do you create one? BASIC

0.

Q28 What thread pool does parallelStream() use internally? MEDIUM

1.

Q28 When does parallel stream actually improve performance? When does it make things worse? TRICKY

2.

Q28 Is parallel stream always faster? What are the hidden costs? TRICKY

3.

Q28 What issues can arise with parallel streams and mutable shared state? TRICKY

4.

Q28 Can you use parallelStream() on a synchronized collection safely? TRICKY

5.

6D. Optional

Q28 What is Optional? What problem does it solve? BASIC

6.

Q28 What is the difference between [Link](), [Link](), and [Link]()? MEDIUM

7.

Q28 What is the difference between orElse() and orElseGet()? When should you prefer orElseGet()? TRICKY

8.

Q28 What does orElseThrow() do? How do you pass a custom exception? MEDIUM

9.

Q29 What is the difference between map() and flatMap() on Optional? TRICKY

0.

Q29 Why should Optional NOT be used as a method parameter or as a field in a class? TRICKY

1.

Q29 What does ifPresent() do? What is ifPresentOrElse() (Java 9)? MEDIUM

2.

Q29 What is [Link]() (Java 9)? How is it different from orElse()? TRICKY

3.

Q29 What does [Link]() (Java 9) do? TRICKY

4.

6E. Other Java 8+ Features

Q29 What are default methods in interfaces? Why were they introduced in Java 8? MEDIUM

5.

Q29 What are static methods in interfaces? When are they useful? MEDIUM

6.

Q29 What is the new Date/Time API ([Link])? What were the problems with the old Date/Calendar? MEDIUM

7.

Q29 What is the difference between LocalDate, LocalDateTime, ZonedDateTime, and Instant? MEDIUM

8.
Q29 What is a DateTimeFormatter? How do you parse and format dates? MEDIUM

9.

Q30 What are the key new features in Java 9, 10, 11? (var, modules, new String methods) MEDIUM

0.

Q30 What is var (Java 10 local variable type inference)? What are its limitations? MEDIUM

1.

Q30 What are records in Java 16+? How are they different from a regular class? TRICKY

2.

Q30 What are sealed classes in Java 17? What problem do they solve? TRICKY

3.

Q30 What is the switch expression (Java 14+)? How is it different from switch statement? TRICKY

4.

Q30 What is text block (Java 15+)? When is it useful? MEDIUM

5.
■ SECTION 7 — MIXED / CROSS-TOPIC REAL INTERVIEW
QUESTIONS

These questions combine multiple topics and represent the most common real-interview patterns for 1–3 years
experience candidates in India. Strong candidates will connect concepts across sections.

7A. Collections + Multithreading

Q30 What happens when two threads concurrently call put() on the same HashMap? What can go wrong? TRICKY

6.

Q30 What is ConcurrentHashMap? How does it avoid the issues of HashMap in multithreaded use? MEDIUM

7.

Q30 Can you use streams with synchronized collections like Vector or [Link]()? TRICKY

8.

Q30 Why is CopyOnWriteArrayList safe for concurrent reads but expensive for writes? TRICKY

9.

Q31 If you use [Link]() and iterate over it, is it thread-safe? Why not? TRICKY

0.

7B. String + Performance

Q31 Why is String immutable — what is the real backend security advantage? SCENARIO

1.

Q31 Why can String be safely used as a HashMap key but mutable objects cannot? TRICKY

2.

Q31 You are building a report that concatenates 10,000 strings in a loop. What do you use and why? SCENARIO

3.

Q31 What is [Link]() and when would you use it for performance optimization? TRICKY

4.

Q31 Why does '+' operator on Strings in a loop create O(n^2) memory — explain with JVM internals. TRICKY

5.

7C. OOP Design + Real Project Scenarios

Q31 You are designing a payment service. How would you use abstract class + interface together? SCENARIO

6.

Q31 What is the SOLID principle? Briefly explain each letter with a Java example. SCENARIO

7.

Q31 What design patterns have you used in Java? Explain Singleton, Factory, Strategy with examples. SCENARIO

8.

Q31 How is the Singleton pattern broken by reflection, serialization, or cloning — and how do you fix it? TRICKY

9.

Q32 You have a class hierarchy going 5 levels deep — what problems does this cause and how do you fix SCENARIO

0. it?

Q32 What is the difference between method overloading and operator overloading? Does Java support the MEDIUM

1. latter?
Q32 Why does Java not support operator overloading for custom classes? TRICKY

2.

7D. Java 8 Streams + Collections

Q32 How do you remove duplicate elements from a List while preserving insertion order using streams? MEDIUM

3.

Q32 How do you find the frequency of each word in a sentence using streams? MEDIUM

4.

Q32 Given a Map>, flatten it to a single List using flatMap. MEDIUM

5.

Q32 How do you convert a List to a Map where the value is the string length? MEDIUM

6.

Q32 How do you find the second highest salary from a list of employees using streams? MEDIUM

7.

Q32 What is the difference between stream().collect(toList()) and stream().toList() (Java 16)? TRICKY

8.

Q32 How do you check if all elements, any element, or no element in a list matches a condition? MEDIUM

9.

Q33 How would you group a list of transactions by category and sum amounts per category using streams? SCENARIO

0.

7E. Exception Handling + Real-World Design

Q33 Your REST API returns a generic 500 error for all exceptions. How do you fix the exception handling SCENARIO

1. architecture?

Q33 What is the best practice for exception logging in a microservice — what information must you always SCENARIO

2. log?

Q33 Should service layer methods throw checked or unchecked exceptions? What are the trade-offs? SCENARIO

3.

Q33 How do you handle NullPointerException defensively — using Optional vs null check vs @NotNull? SCENARIO

4.

Q33 In a try-catch block, you catch Exception. A colleague says you should catch more specific types. Why SCENARIO

5. are they right?

7F. Tricky Output-Based Rapid Fire

Q33 What is the output? (static vs instance initialization order) OUTPUT

6.

class Test { static int x = 10; int y = 20; static { x = 30; [Link]("static block:
x=" + x); } { y = 40; [Link]("instance block: y=" + y); } Test() {
[Link]("constructor: y=" + y); } public static void main(String[] args) {
[Link]("main: x=" + x); Test t1 = new Test(); Test t2 = new Test(); } }

Q33 What is the output? (String comparison trap) OUTPUT

7.

String a = "Java"; String b = "Java"; String c = new String("Java"); [Link](a == b);


[Link](a == c); [Link]([Link](c)); [Link](a == [Link]());
Q33 What is the output? (finally with return — common interview trap) OUTPUT

8.

static int getValue() { int x = 0; try { x = 1; return x; // saved as 1 } finally { x = 2; // no


return here } } [Link](getValue());

Q33 What is the output? (HashMap iteration order) OUTPUT

9.

Map<Integer, String> map = new HashMap<>(); [Link](3, "Three"); [Link](1, "One"); [Link](2,
"Two"); for ([Link]<Integer, String> e : [Link]()) [Link]([Link]() + " ->
" + [Link]()); // Is the output order guaranteed? What would LinkedHashMap give?

Q34 What is the output? (autoboxing null NullPointerException trap) OUTPUT

0.

Integer i = null; int j = i; // unboxing null! [Link](j);

■ Java Interview Complete Question Bank | 300+ Questions | 0–3 Years Experience | Service-Based & Mid-Level Product Companies | 30%
Basic · 40% Medium · 30% Tricky/Output/Scenario

You might also like