Core Java Interview Questions
2026 Edition
The questions freshers actually get asked — curated from the mock interviews we run every week at The Kiran Academy. Clear answers, code where it matters, and notes on how interviewers dig deeper.
☕ Java Basics & OOP 8 questions
1Why is Java called platform independent?▾
.class file runs on Windows, Linux or Mac without recompiling. "Write once, run anywhere." 2What is the difference between JDK, JRE and JVM?▾
javac, debugger) — needed to write Java programs. 3What are the four pillars of OOP? Explain each in one line.▾
extends. Polymorphism — one interface, many implementations (overloading at compile time, overriding at runtime). Abstraction — exposing what something does while hiding how, via abstract classes and interfaces. 4Why does Java not support multiple inheritance with classes?▾
show(), the compiler cannot decide which one C inherits. Java allows multiple inheritance of type through interfaces instead — and since Java 8, conflicts from default methods must be resolved explicitly by overriding. 5Method overloading vs method overriding?▾
class Shape { double area() { return 0; } }
class Circle extends Shape {
double r;
@Override double area() { return Math.PI * r * r; } // overriding
double area(int precision) { /* ... */ return 0; } // overloading
}
6Interface vs abstract class — when do you use which?▾
Comparable, Runnable) — a class can implement many. Use an abstract class when related classes share state and partial implementation — fields, constructors, non-final method bodies. Since Java 8 interfaces can have default and static methods, but still no instance state. 7What does the static keyword do?▾
static members belong to the class, not to instances — one copy shared by all objects. Static methods cannot use this or access instance members directly. Common uses: utility methods (Math.max), counters, constants (static final), and the main method itself — the JVM calls it without creating an object. 8What is a constructor? Can it be final, static or inherited?▾
final, static or abstract, and constructors are not inherited — though a subclass constructor always calls a parent constructor (implicitly super() if you do not write it). 🔤 Strings 5 questions
9Why are Strings immutable in Java?▾
HashMap keys (hashcode can be cached), and the string pool — JVM can share one copy across references only because no one can change it. 10String vs StringBuilder vs StringBuffer?▾
11What is the String constant pool?▾
String a = "java"; String b = "java"; — both point to the same pooled object. new String("java") forces a separate heap object outside the pool; intern() puts it back. 12Difference between == and equals() for Strings?▾
== compares references (same object?), equals() compares character content. Because of the pool, two literals may pass ==, but never rely on it — always compare strings with equals() (or equalsIgnoreCase()). String a = "java";
String b = new String("java");
System.out.println(a == b); // false - different objects
System.out.println(a.equals(b)); // true - same content
13Which String programs should a fresher be able to write on paper?▾
🗂️ Collections Framework 7 questions
14ArrayList vs LinkedList — when does each win?▾
15How does HashMap work internally?▾
put(key, value): compute hashCode() of the key, map it to a bucket index, store an entry node there. Collisions become a linked list inside the bucket — converted to a red-black tree after 8 entries (Java 8+) so worst case is O(log n). get() repeats the hashing and then uses equals() to find the exact key. Resizes (rehash) when size exceeds capacity × load factor (default 0.75). 16HashMap vs Hashtable vs ConcurrentHashMap?▾
17List vs Set vs Map in one line each?▾
18How does HashSet ensure uniqueness?▾
hashCode() and equals() consistently. 19Comparable vs Comparator?▾
compareTo(); one order per class. Comparator — ordering defined outside the class via compare(); you can have many (sort employees by name, then by salary). Since Java 8: Comparator.comparing(Employee::getSalary). list.sort(Comparator.comparing(Employee::getSalary)
.thenComparing(Employee::getName));
20What are fail-fast and fail-safe iterators?▾
ConcurrentModificationException if the collection is structurally modified during iteration — they detect it via a modification counter. Fail-safe (ConcurrentHashMap, CopyOnWriteArrayList) iterate over a snapshot or tolerate concurrent changes — no exception, but you may not see the latest data. Reading answers is step one. Saying them out loud is the job.
Our Mock Interview Program puts you through 15+ real interview rounds with working professionals — Java, SQL and HR — until answering these becomes automatic.
⚠️ Exception Handling 5 questions
21Checked vs unchecked exceptions?▾
throws. Represent recoverable external failures. Unchecked (RuntimeException and subclasses: NullPointerException, ArrayIndexOutOfBounds) — programming bugs; the compiler does not force handling. Error (OutOfMemoryError) — JVM-level, do not catch. 22Does finally always execute? When does it not?▾
finally runs whether or not an exception is thrown, even after a return in try/catch. It does NOT run if the JVM exits first (System.exit()), the thread is killed, or the JVM crashes. A return inside finally overrides earlier returns — a known bad practice interviewers love to probe. 23throw vs throws?▾
throw — a statement that actually raises one exception object: throw new IllegalArgumentException("age"). throws — a method-signature clause declaring which checked exceptions a method may pass to its caller: void read() throws IOException. 24How do you create a custom exception, and when should you?▾
Exception (checked) or RuntimeException (unchecked) and provide constructors that pass the message/cause to super. Create one when the failure is domain-specific and callers need to handle it distinctly — e.g. InsufficientBalanceException in a banking app instead of a generic RuntimeException. public class InsufficientBalanceException extends RuntimeException {
public InsufficientBalanceException(String msg) { super(msg); }
}
25What is try-with-resources?▾
AutoCloseable when the block exits — even on exception. Replaces the verbose finally-close pattern and avoids leaked connections/streams: try (BufferedReader br = new BufferedReader(...)) { ... }. Multiple resources close in reverse order of declaration. 🧵 Multithreading 6 questions
26Process vs thread?▾
27What are the ways to create a thread in Java?▾
Thread and override run(), or implement Runnable and pass it to a Thread — prefer Runnable (you keep your superclass slot, separates task from execution). For results and exceptions use Callable<V> with an ExecutorService, which is also the answer interviewers want for "how do you manage threads in real projects" — thread pools, not raw threads. 28What does synchronized do?▾
29wait() vs sleep()?▾
wait() (Object method) releases the lock and pauses until notify()/notifyAll() — must be called inside synchronized. sleep() (Thread static method) pauses the current thread for a fixed time and does NOT release any lock. Mixing these up is an instant red flag in interviews. 30What does volatile guarantee — and what does it not?▾
volatile guarantees visibility: every read sees the latest write, no thread-local caching. It does NOT guarantee atomicity — count++ on a volatile int is still a race (read-modify-write). For atomic counters use AtomicInteger; for compound invariants use locks. 31What is a deadlock, and how do you prevent it?▾
tryLock with timeout, or avoid multiple locks via higher-level concurrency utilities. Be ready to sketch the two-thread/two-lock example on paper. 🧠 JVM & Memory 5 questions
32Heap vs stack memory?▾
33How does garbage collection work in simple terms?▾
System.gc() but never force it. 34Can Java have memory leaks if it has a GC?▾
35final vs finally vs finalize?▾
final — keyword: constant variable, non-overridable method, non-extendable class. finally — block that runs after try/catch. finalize() — deprecated method GC once called before reclaiming an object; never rely on it (use try-with-resources/Cleaner). Three unrelated things with similar names — a pure trap question. 36What happens when you run "java Main" — briefly?▾
main() executes on the main thread. JIT compiles hot methods to native code as the program runs — which is why Java warms up. ⚡ Java 8+ Features 7 questions
37What is a lambda expression and why was it added?▾
(a, b) -> a + b. Added to enable functional-style code (especially the Streams API) and replace bulky anonymous inner classes for callbacks and comparators. 38What is a functional interface? Name the common built-ins.▾
@FunctionalInterface. Built-ins from java.util.function: Predicate<T> (test → boolean), Function<T,R> (transform), Consumer<T> (accept, no return), Supplier<T> (provide), plus Runnable and Comparator. 39map() vs flatMap() in streams?▾
map transforms each element one-to-one — a stream of lists stays a stream of lists. flatMap transforms each element into a stream and flattens them into one: List<List<Integer>> → Stream<Integer>. If your result is nested one level too deep, you needed flatMap. List<String> words = List.of("java", "code");
words.stream()
.flatMap(w -> Arrays.stream(w.split("")))
.distinct()
.forEach(System.out::print); // javcode
40What is Optional and what problem does it solve?▾
orElse, map, ifPresent instead of null checks. Anti-patterns interviewers probe: calling get() blindly, using Optional for fields or parameters (it is designed for return types). 41What are default methods in interfaces, and why do they exist?▾
default. The motivation was evolving old interfaces without breaking implementers — Collection gained stream() this way. If a class inherits the same default from two interfaces, it must override and may pick one via InterfaceName.super.method(). 42Intermediate vs terminal stream operations?▾
43What is a method reference?▾
String::toUpperCase, System.out::println, Employee::new. Four kinds: static method, instance method of a particular object, instance method of an arbitrary object of a type, and constructor reference. Want to be the candidate these questions are easy for?
Our 6-month Java Full Stack course covers everything here in depth — plus Spring Boot, projects, and placement support until you are hired. Free demo class, no commitment.