Interview Prep12 min read

Top 25 Java Interview Questions with Answers (2026)

Most fresher Java interviews and service-company placement tests draw from the same well of topics: core Java and OOP, the collections framework, exceptions, and multithreading. Know these cold and you'll handle the majority of what's thrown at you. Here are the questions that come up again and again, grouped by area - each with a concise answer you can actually say out loud.

A laptop showing a code editor with floating curly braces, angle brackets, a terminal window and a database icon, representing Java programming

Core Java & OOP

What are the four pillars of OOP?

Encapsulation (bundling data with the methods that use it and hiding internal state), inheritance (a class reusing a parent's behaviour), polymorphism (one interface, many implementations), and abstraction (exposing what an object does while hiding how). Give a one-line example of each.

Abstract class vs interface - when do you use each?

Use an abstract class for an 'is-a' relationship with shared state or partial implementation; use an interface for a 'can-do' capability that many unrelated classes implement. Since Java 8 interfaces can have default methods, but only an abstract class can hold instance state and constructors.

Method overloading vs overriding?

Overloading is the same method name with different parameters, resolved at compile time (static polymorphism). Overriding is a subclass redefining a superclass method with the same signature, resolved at runtime (dynamic polymorphism).

JVM vs JRE vs JDK?

The JVM executes bytecode. The JRE is the JVM plus the core libraries needed to run applications. The JDK is the JRE plus the compiler and developer tools needed to build them.

Why is String immutable, and what is the String pool?

Immutability makes strings safe to share and cache, safe as HashMap keys (their hash never changes), and more secure. The String pool reuses identical string literals to save memory.

Collections Framework

ArrayList vs LinkedList?

ArrayList is backed by a resizable array - O(1) random access but costly inserts/removals in the middle. LinkedList is a doubly linked list - O(1) insert/remove at a known node but O(n) access. Default to ArrayList unless you insert/delete heavily at the ends.

HashMap vs Hashtable vs ConcurrentHashMap?

HashMap is unsynchronised and allows one null key. Hashtable is a legacy, fully synchronised (and slow) class. ConcurrentHashMap gives thread safety with fine-grained bucket-level locking, so it scales far better under concurrency.

How does HashMap work internally?

A key's hashCode is mapped to a bucket. Entries in the same bucket chain in a linked list that converts to a balanced tree past a threshold (Java 8+). This gives O(1) average lookups and O(log n) worst case.

Why must you override equals() and hashCode() together?

The contract says equal objects must return equal hash codes. If you override only equals(), hash-based collections put 'equal' objects in different buckets and lookups fail. Always override both for objects used as keys.

Fail-fast vs fail-safe iterators?

Fail-fast iterators (ArrayList, HashMap) throw ConcurrentModificationException if the collection is structurally modified during iteration. Fail-safe iterators (CopyOnWriteArrayList, ConcurrentHashMap) iterate over a snapshot and don't throw.

Exceptions & error handling

Checked vs unchecked exceptions?

Checked exceptions (e.g. IOException) are checked at compile time and must be declared or handled - use them for recoverable conditions. Unchecked exceptions (RuntimeException subclasses like NullPointerException) signal programming bugs and aren't forced on callers.

Why prefer try-with-resources over finally?

try-with-resources auto-closes anything implementing AutoCloseable when the block exits, even on exception. It removes verbose, error-prone finally blocks and prevents resource leaks.

throw vs throws, and what if you return in finally?

throw actually raises an exception instance; throws declares that a method might throw one. A return or exception in a finally block overrides one from try - avoid it, because it silently swallows the original error.

Multithreading (the section that separates candidates)

Process vs thread, and how do you create a thread in Java?

A process has its own memory; threads within a process share memory but have their own stack, so they're cheaper to create and switch. Create a thread by extending Thread, implementing Runnable, or - preferred - submitting tasks to an ExecutorService.

What does synchronized do?

It enforces mutual exclusion: only one thread at a time holds a given monitor, and it also guarantees visibility of changes across threads. A synchronized method locks 'this' (or the Class for static methods); a synchronized block locks an object you choose.

What is a deadlock and how do you avoid it?

A deadlock is two or more threads each holding a lock the other needs, so none proceeds. Avoid it by acquiring locks in a consistent global order, using timeouts (tryLock), or minimising the scope of locking.

volatile vs synchronized?

volatile guarantees visibility of a single variable across threads but not atomicity of compound actions (like i++). synchronized guarantees both visibility and atomicity, at the cost of locking. Use volatile for simple flags, synchronized for compound updates.

How to actually get ready

Reading these answers builds recognition, but interviews test recall under pressure. Practice retrieving, not re-reading: take timed MCQ rounds on exactly these areas, read the explanation for anything you miss, and revisit weak spots the next day until the answers come out automatically.

A good weekly rhythm is one core-Java round, one collections-and-multithreading round, and one mixed round that also touches data structures and DBMS - because real interviews jump across topics without warning. If you're heading into campus placements, interleave aptitude and reasoning too, since almost every company gates the technical round behind an aptitude test.

The bottom line

Now go test yourself

Java interviews reward depth over breadth. You don't need to memorise a thousand questions - you need to understand OOP, know how the core collections work internally, handle exceptions cleanly, and reason about threads. Nail those four areas and follow-up questions stop being scary.

The fastest way to find out whether you actually know this material - rather than just recognise it - is to be tested on it. Start a Java quiz, answer from memory, and let the explanations catch every gap before an interviewer does.

FAQs

Frequently asked questions

What topics should freshers focus on for a Java interview?

Core Java and OOP, the collections framework, exception handling, and multithreading cover the majority of fresher and service-company placement questions. Add basic DSA and SQL for a strong all-round profile.

How do I prepare for Java interviews quickly?

Practice active recall, not passive reading. Take timed MCQ rounds on core Java, collections and multithreading, read the explanation for anything you miss, and revisit weak areas the next day.

Are these Java questions enough to clear placement tests?

They cover the Java portion well. Most placement tests also include aptitude, logical reasoning and basic coding, so pair Java practice with those sections for full coverage.

What are the most important Java collections interview questions?

How HashMap works internally (hashing, buckets, collision handling), ArrayList vs LinkedList, HashMap vs ConcurrentHashMap, and why you must override equals() and hashCode() together. Collections come up in nearly every Java interview.

Is Java multithreading asked in fresher interviews?

Yes - at least the basics. Be ready to explain the difference between a process and a thread, what synchronized does, how to avoid a deadlock, and volatile vs synchronized. Strong multithreading answers often decide who advances.

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

== compares references (whether two variables point to the same object), while equals() compares values and is overridden by classes like String and Integer to compare content. Using == to compare strings is a classic bug.

Do I need to know Java 8 features for interviews?

Increasingly, yes. Streams, lambdas, functional interfaces, method references and Optional come up even in fresher interviews, so be comfortable rewriting a loop as a stream pipeline.

How many Java interview questions should I practice?

Quality beats quantity. It's better to master the 25 core questions above until you can answer each from memory than to skim hundreds. Drill them as timed MCQs and review every miss.

How do I answer Java interview questions confidently?

State the concept in one sentence, then give a one-line example - for instance, 'a HashMap stores key-value pairs by hashing the key; on a collision it chains entries in a bucket'. Practising out loud makes the phrasing automatic under pressure.

Related quizzes

Put it into practice

Keep reading

Related articles

Browse all articles →

Test yourself in two minutes

Six adaptive questions, every answer explained by an AI tutor. Free.

▶ Start an AI quiz