PrepTen

Top Java Interview Questions & Answers

The core Java questions interviewers keep coming back to — explained simply.

Updated: June 2026 · ~9 min read

Java remains one of the most asked-about languages in technical interviews, from campus placements to senior backend roles. The good news: most interviews draw from a predictable set of fundamentals. If you can explain these clearly — in your own words, not memorized — you'll handle the majority of Java rounds with confidence. Below are the questions that come up most, grouped by topic.

Core Java

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

The JVM (Java Virtual Machine) runs your compiled bytecode and makes Java platform-independent. The JRE (Java Runtime Environment) is the JVM plus the standard libraries needed to run programs. The JDK (Java Development Kit) is the JRE plus development tools like the compiler (javac) — what you need to write and build programs.

2. Why is Java called platform-independent?

Java source compiles to bytecode rather than machine code. That bytecode runs on any device with a compatible JVM, so the same .class file works across Windows, macOS, and Linux — "write once, run anywhere."

3. What is the difference between == and .equals()?

== compares references (whether two variables point to the same object), while .equals() compares values (logical equality). For Strings especially, always use .equals() to compare content.

4. What is the difference between final, finally, and finalize?

final is a keyword for constants, preventing inheritance/overriding. finally is a block that always runs after try/catch, used for cleanup. finalize() was a method called by the garbage collector before reclaiming an object (now deprecated). Three different concepts that share a prefix — a classic trick question.

Object-Oriented Programming

5. What are the four pillars of OOP?

Encapsulation (bundling data with methods, hiding internals), Inheritance (reusing behavior from a parent class), Polymorphism (one interface, many implementations), and Abstraction (exposing essentials, hiding complexity).

6. What is the difference between an abstract class and an interface?

An abstract class can have both abstract and concrete methods, instance fields, and constructors — and a class can extend only one. An interface defines a contract; since Java 8 it can have default and static methods, and a class can implement many interfaces. Use an interface for capability ("can do"), an abstract class for shared base behavior ("is a").

7. What is method overloading vs. method overriding?

Overloading is multiple methods with the same name but different parameters in the same class (compile-time polymorphism). Overriding is a subclass redefining a parent method with the same signature (runtime polymorphism).

Collections

8. What is the difference between ArrayList and LinkedList?

ArrayList uses a dynamic array — fast random access (O(1)) but slower inserts/deletes in the middle. LinkedList uses a doubly linked list — fast inserts/deletes (O(1) at the ends) but slower random access (O(n)). Use ArrayList for read-heavy work, LinkedList for frequent insertion/removal.

9. What is the difference between HashMap and HashTable?

HashMap is not synchronized (faster, allows one null key), while HashTable is synchronized (thread-safe but slower, no null keys). For thread-safe maps today, prefer ConcurrentHashMap over the legacy HashTable.

10. How does a HashMap work internally?

It stores entries in buckets indexed by the key's hash code. Collisions are handled with linked lists (converted to balanced trees after a threshold in modern Java). Good hashCode() and equals() implementations keep lookups close to O(1).

Exceptions

11. What is the difference between checked and unchecked exceptions?

Checked exceptions (e.g., IOException) are checked at compile time and must be handled or declared. Unchecked exceptions (e.g., NullPointerException) extend RuntimeException and occur at runtime, usually from programming bugs.

12. What is the difference between throw and throws?

throw actually raises an exception in code; throws declares in a method signature which exceptions it might propagate.

Multithreading & Memory

13. What is the difference between a process and a thread?

A process is an independent program with its own memory; a thread is a lightweight unit of execution that shares memory with other threads in the same process. Threads are cheaper to create and communicate, but shared memory means you must guard against race conditions.

14. What is the difference between String, StringBuilder, and StringBuffer?

String is immutable. StringBuilder is mutable and not thread-safe (faster). StringBuffer is mutable and thread-safe (synchronized, slower). For heavy string concatenation in a single thread, use StringBuilder.

15. What is garbage collection in Java?

The JVM automatically reclaims memory from objects that are no longer reachable, so developers don't manually free memory. You can suggest collection with System.gc(), but you can't force it.

Quick-fire round

Be ready to give one- or two-sentence answers to these:

How to actually prepare

Reading answers is the easy part — the hard part is explaining them out loud under mild pressure. Pick five questions above, close this page, and try saying each answer as if an interviewer just asked it. If you stumble, that's exactly the gap to close before the real interview.

Practice these in a real mock interview

PrepTen's AI interviewer asks Java questions like these, listens to your answers, and gives you an instant scorecard. Your first question is free.

Start a Free Java Mock Interview

← Back to all articles