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.

✅ 43 questions 📚 7 topics 🆓 Free, no signup 🔄 Updated June 2026

☕ Java Basics & OOP 8 questions

1Why is Java called platform independent?
Java source code compiles to bytecode, not machine code. The JVM installed on each operating system translates that same bytecode into native instructions — so one compiled .class file runs on Windows, Linux or Mac without recompiling. "Write once, run anywhere."
How interviewers dig deeper: Follow-up: is the JVM itself platform independent? No — there is a different JVM build per OS. The bytecode is independent, the JVM is not.
2What is the difference between JDK, JRE and JVM?
JVM executes bytecode. JRE = JVM + core libraries — enough to run Java programs. JDK = JRE + development tools (compiler javac, debugger) — needed to write Java programs.
3What are the four pillars of OOP? Explain each in one line.
Encapsulation — bundling data and methods, hiding state behind private fields with getters/setters. Inheritance — a class acquires properties of another with 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.
How interviewers dig deeper: Interviewers almost always pick one pillar and ask for a real-life example. Prepare one concrete example each — not definitions.
4Why does Java not support multiple inheritance with classes?
To avoid the diamond problem: if class C extends both A and B, and both define 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?
Overloading: same method name, different parameter list, same class — resolved at compile time. Overriding: subclass redefines a parent method with the same signature — resolved at runtime via dynamic dispatch. Overriding cannot reduce visibility or throw broader checked exceptions.
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?
Use an interface for a capability contract that unrelated classes can share (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?
A constructor initialises a new object; it has the class name and no return type. It cannot be 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?
Security (strings carry file paths, URLs, credentials), thread safety without synchronisation, safe use as HashMap keys (hashcode can be cached), and the string pool — JVM can share one copy across references only because no one can change it.
How interviewers dig deeper: Classic follow-up: "then what happens when you concatenate?" — a new String object is created; the original is untouched.
10String vs StringBuilder vs StringBuffer?
String — immutable; every modification creates a new object. StringBuilder — mutable, not thread-safe, fastest; the default choice for building strings in a loop. StringBuffer — mutable and synchronised; only when multiple threads share the same builder, which is rare.
11What is the String constant pool?
A special memory area where string literals are stored once and reused. 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?
Reverse a string without library methods, check palindrome, count vowels/character frequency, remove duplicate characters, find the first non-repeated character, and check if two strings are anagrams. In our mock interviews these are the most common warm-up programs — practise writing them by hand, not just in an IDE.

🗂️ Collections Framework 7 questions

14ArrayList vs LinkedList — when does each win?
ArrayList is backed by a dynamic array: O(1) random access, fast iteration; inserts in the middle shift elements. LinkedList is a doubly-linked list: O(1) insert/delete at the ends once positioned, but O(n) access and worse cache behaviour. Default to ArrayList; in practice LinkedList wins only for heavy add/remove at both ends (deque use).
15How does HashMap work internally?
An array of buckets. 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).
How interviewers dig deeper: This is the single most-asked Java interview question. Follow-ups: why must you override equals() and hashCode() together? What happens with a mutable key? What changed in Java 8?
16HashMap vs Hashtable vs ConcurrentHashMap?
HashMap — not synchronised, allows one null key; the default. Hashtable — legacy, every method synchronised (slow), no nulls; avoid in new code. ConcurrentHashMap — thread-safe with fine-grained locking (bucket level), no null keys/values; the right choice for concurrent access.
17List vs Set vs Map in one line each?
List — ordered, allows duplicates, index access (ArrayList, LinkedList). Set — no duplicates (HashSet unordered, LinkedHashSet insertion order, TreeSet sorted). Map — key/value pairs, unique keys (HashMap, LinkedHashMap, TreeMap). Map is technically not a Collection — interviewers like that detail.
18How does HashSet ensure uniqueness?
HashSet is backed by a HashMap — every added element becomes a key with a dummy value. Uniqueness comes from the same hashCode-then-equals check HashMap performs on keys. Which is why elements stored in a HashSet must implement hashCode() and equals() consistently.
19Comparable vs Comparator?
Comparable — the class defines its own natural order via 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?
Fail-fast (ArrayList, HashMap iterators) throw 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?
Checked (IOException, SQLException) — verified at compile time; you must catch or declare with 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?
Extend 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?
Java 7+ syntax that auto-closes anything implementing 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?
A process is an independent program with its own memory space. A thread is a lightweight unit of execution inside a process — threads of one process share heap memory (which is what makes synchronisation necessary) but have their own stacks.
27What are the ways to create a thread in Java?
Extend 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?
It makes a block or method mutually exclusive on a monitor lock — only one thread at a time can hold the lock of that object (or of the class for static methods). It also establishes happens-before: changes made inside are visible to the next thread acquiring the same lock. Cost: contention and possible deadlocks, so keep synchronised sections small.
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?
Two or more threads each hold a lock the other needs, waiting forever. Classic prevention: acquire locks in a fixed global order, keep lock scope minimal, use 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?
Stack — per thread; stores method frames, local variables and references; freed automatically when methods return. Heap — shared; all objects live here, managed by the garbage collector. StackOverflowError = too-deep recursion; OutOfMemoryError = heap exhausted.
33How does garbage collection work in simple terms?
The GC finds objects no longer reachable from GC roots (active threads, static fields, local references) and reclaims their memory. Generational design: new objects go to the young generation (collected often and cheaply); survivors get promoted to the old generation (collected rarely). You can request GC with System.gc() but never force it.
34Can Java have memory leaks if it has a GC?
Yes — a leak in Java means objects stay reachable but unused, so GC cannot touch them: ever-growing static collections, unclosed resources, listeners never deregistered, cache without eviction. The fix is breaking the references, not tuning the 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?
The JVM starts, the class loader loads Main.class (bootstrap → platform → application loaders, parent delegation), bytecode is verified, static initialisers run, and 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 concise syntax for an anonymous function implementing a functional interface: (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.
An interface with exactly one abstract method (SAM), optionally annotated @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?
A container that may or may not hold a value — an explicit, type-level answer to null and NullPointerException. Use 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?
Java 8 lets interfaces ship method bodies marked 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?
Intermediate (map, filter, sorted, distinct) return a stream and are lazy — nothing runs yet. Terminal (collect, forEach, count, reduce, findFirst) trigger the whole pipeline and produce a result. A stream can be consumed only once; reusing it throws IllegalStateException.
43What is a method reference?
Shorthand for a lambda that only calls an existing method: 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.

🎯 Student Success Stories Watch all on YouTube →
How to Get a Job in IT

How to Get a Job in IT

Becoming a Software Tester — My Story

Becoming a Software Tester — My Story

From Fresher to Developer

From Fresher to Developer

First Offer Letter Story

First Offer Letter Story

How I Cleared My Interview

How I Cleared My Interview

Placement Story That Inspires

Placement Story That Inspires

Hrashada Sangle | Job Placement!

Hrashada Sangle | Job Placement!

Secured Job as Automation Tester Intern!

Secured Job as Automation Tester Intern!

Secured Job as a Software Intern!

Secured Job as a Software Intern!

March 2026 Placements Update

March 2026 Placements Update

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

MERN Stack | Job Placement Story

MERN Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

AI / ML Course | Job Placement Story

AI / ML Course | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

How to Get a Job in IT

How to Get a Job in IT

Becoming a Software Tester — My Story

Becoming a Software Tester — My Story

From Fresher to Developer

From Fresher to Developer

First Offer Letter Story

First Offer Letter Story

How I Cleared My Interview

How I Cleared My Interview

Placement Story That Inspires

Placement Story That Inspires

Hrashada Sangle | Job Placement!

Hrashada Sangle | Job Placement!

Secured Job as Automation Tester Intern!

Secured Job as Automation Tester Intern!

Secured Job as a Software Intern!

Secured Job as a Software Intern!

March 2026 Placements Update

March 2026 Placements Update

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

MERN Stack | Job Placement Story

MERN Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

AI / ML Course | Job Placement Story

AI / ML Course | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

How to Get a Job in IT

How to Get a Job in IT

Becoming a Software Tester — My Story

Becoming a Software Tester — My Story

From Fresher to Developer

From Fresher to Developer

First Offer Letter Story

First Offer Letter Story

How I Cleared My Interview

How I Cleared My Interview

Placement Story That Inspires

Placement Story That Inspires

Hrashada Sangle | Job Placement!

Hrashada Sangle | Job Placement!

Secured Job as Automation Tester Intern!

Secured Job as Automation Tester Intern!

Secured Job as a Software Intern!

Secured Job as a Software Intern!

March 2026 Placements Update

March 2026 Placements Update

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

MERN Stack | Job Placement Story

MERN Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

AI / ML Course | Job Placement Story

AI / ML Course | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

How to Get a Job in IT

How to Get a Job in IT

Becoming a Software Tester — My Story

Becoming a Software Tester — My Story

From Fresher to Developer

From Fresher to Developer

First Offer Letter Story

First Offer Letter Story

How I Cleared My Interview

How I Cleared My Interview

Placement Story That Inspires

Placement Story That Inspires

Hrashada Sangle | Job Placement!

Hrashada Sangle | Job Placement!

Secured Job as Automation Tester Intern!

Secured Job as Automation Tester Intern!

Secured Job as a Software Intern!

Secured Job as a Software Intern!

March 2026 Placements Update

March 2026 Placements Update

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

MERN Stack | Job Placement Story

MERN Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

AI / ML Course | Job Placement Story

AI / ML Course | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story

Java Full Stack | Job Placement Story