Java Interview Questions 2026: Top 40 With Detailed Answers
Core Java (Q1-Q15)
Q1: JDK vs JRE vs JVM? JVM: executes bytecode. JRE: JVM + class libraries, for running. JDK: JRE + compiler + tools, for developing.
Q2: String immutability? Strings cannot be modified after creation. str = str + ' world' creates a NEW object. Benefits: thread-safe, usable as HashMap keys, enables string pool optimisation.
Q3: HashMap vs Hashtable? HashMap: not synchronised, allows null key, faster. Hashtable: synchronised, no nulls, legacy. Use ConcurrentHashMap for thread-safe maps.
Q4: How does HashMap work internally? Array of buckets. hashCode() determines bucket index. Collisions use linked list. Java 8+: converts to red-black tree at length 8 — O(n) to O(log n).
Q5: == vs .equals()? == compares references (memory addresses). .equals() compares content. ALWAYS use .equals() for String comparison.
OOP (Q16-Q25)
Q16: Abstract class vs interface? Abstract: constructors, instance vars, concrete methods, single inheritance. Interface: multiple implementation, default/static methods (Java 8+). Abstract for shared code, interface for contracts.
Q17: Overloading vs overriding? Overloading: same name, different params, compile-time. Overriding: child redefines parent method, runtime. Cannot override static, final, private methods.
Q18: What is polymorphism? One interface, multiple implementations. Compile-time (overloading) and runtime (overriding). Core OOP pillar enabling flexible, extensible code.
Multithreading (Q26-Q35)
Q26: Thread vs Runnable? Extending Thread prevents extending other classes. Implementing Runnable allows extending another class. Always prefer Runnable or Callable.
Q27: What is synchronized? Prevents multiple threads executing a block simultaneously. Each object has an intrinsic lock. Prefer java.util.concurrent alternatives for performance.
Q28: What is a deadlock? Thread A holds Lock 1 waits Lock 2. Thread B holds Lock 2 waits Lock 1. Prevention: always acquire locks in the same order.
Java 8+ Features (Q36-Q40)
Q36: Lambda expressions? Anonymous functions: Runnable r = () -> System.out.println(Hello) — no anonymous class needed.
Q37: Stream API? Functional operations on collections, lazy: list.stream().filter(x -> x > 0).map(x -> x * 2).collect(toList())
Q38: Optional? Container for a value that may be null. opt.orElse(default), opt.ifPresent(consumer) — avoids NullPointerException.
Q39: CompletableFuture? Async computation: CompletableFuture.supplyAsync(() -> fetchData()).thenApply(data -> process(data))
Q40: Default methods in interfaces? Java 8 allows interface method implementations: default void log() {} — add methods without breaking existing implementations.
See Java Academy for complete learning path.
Found this useful? Share it:
Weekly DevOps & Cloud digest
Every Sunday — tutorials, interview questions, tips, and what changed in DevOps and Cloud this week.

