Interview

50 Java Interview Questions You Must Know in 2026

August 10, 202612 min read
50 Java Interview Questions You Must Know in 2026
On this page

50 Java Interview Questions You Must Know in 2026

If you have a Java interview coming up, don't worry — you don't need to memorize an entire Java book.

What you actually need is a solid understanding of the concepts that interviewers ask again and again.

So in this guide, let's go through 50 Java interview questions in a simple way. I'll explain each concept like we're sitting together and preparing for an interview, instead of giving you complicated textbook definitions.

We'll start with the basics and gradually move toward OOP, collections, exceptions, multithreading, JVM, and modern Java concepts.

Let's get started.


1. What is Java?

Let's start with the obvious one.

If an interviewer asks "What is Java?", don't overcomplicate your answer.

Java is a high-level, object-oriented programming language that was originally developed by Sun Microsystems and released in 1995.

The interesting thing about Java is that you don't normally compile your code directly into machine code for one specific operating system.

Instead, Java code gets compiled into something called bytecode, and that bytecode runs on the JVM.

That's where the famous Java idea comes from:

Write Once, Run Anywhere.

For example, you can write a Java program on Windows, compile it, and run the same bytecode on Linux or macOS as long as a compatible JVM is available.

Java is widely used for backend development, enterprise applications, APIs, Android development, and large-scale software systems.


2. What are the main features of Java?

If the interviewer asks you about Java's features, you can mention things like:

  • Object-oriented

  • Platform independent

  • Secure

  • Robust

  • Multithreaded

  • Portable

  • High performance

  • Automatic memory management

But don't just throw these words at the interviewer.

For example, when we say platform independent, we're talking about the JVM and bytecode.

When we say automatic memory management, we're talking about Java's garbage collector.

So, if you mention a feature, be ready to explain it in one or two sentences.


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

This is one of those questions that almost every Java learner eventually gets asked.

The easiest way to remember it is:

JDK → Develop

JRE → Run

JVM → Execute

Let's break it down.

JVM

The Java Virtual Machine is responsible for running Java bytecode.

JRE

The Java Runtime Environment provides what you need to run Java applications, including the JVM and required runtime libraries.

JDK

The Java Development Kit is what developers use to build Java applications. It includes development tools such as the Java compiler along with runtime components.

So, if you're actually writing Java applications, you'll typically install a JDK.


4. Why is Java platform independent?

Here's the simple story.

Suppose you write:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}

When you compile this code, Java doesn't directly produce Windows-specific machine code.

Instead, it produces bytecode.

That bytecode can then be executed by a JVM available for Windows, Linux, macOS, and other supported platforms.

So the idea is:

Java Code → Compiler → Bytecode → JVM → Operating System

That's why Java is called platform independent.


5. What is a class in Java?

Think about a class like a blueprint.

Imagine you're designing a house.

The blueprint tells you:

  • How many rooms there are

  • Where the doors go

  • Where the windows go

But the blueprint itself isn't an actual house.

That's basically what a class is.

For example:

class Car {
    String brand;

    void drive() {
        System.out.println("Car is driving");
    }
}

Here, Car is the blueprint.

It tells us that a car has a brand and can perform a drive() operation.


6. What is an object in Java?

If a class is the blueprint, an object is the actual thing created from that blueprint.

For example:

Car car = new Car();

Here, Car is the class and car is the object.

Think about it like this:

Class = House blueprint

Object = Actual house

You can create multiple objects from the same class:

Car car1 = new Car();
Car car2 = new Car();
Car car3 = new Car();

All three objects come from the same Car class.


7. What are the four pillars of OOP?

This is a very important Java interview question.

There are four major concepts you should remember:

  1. Encapsulation

  2. Inheritance

  3. Polymorphism

  4. Abstraction

If you understand these four properly, a lot of Java suddenly becomes easier.

Let's quickly understand each one.

Encapsulation means keeping data and the code that works with that data together while controlling access to it.

Inheritance means one class can inherit functionality from another class.

Polymorphism means the same operation can behave differently depending on the object or context.

Abstraction means hiding unnecessary implementation details and exposing what the user actually needs.


8. What is encapsulation?

Let's say we have a bank account.

Would you want every piece of code in your application to directly change your account balance?

Probably not.

Instead, you want the balance to be protected and provide controlled methods for operations like depositing money.

For example:

class BankAccount {
    private double balance;

    public double getBalance() {
        return balance;
    }

    public void deposit(double amount) {
        balance += amount;
    }
}

Here, balance is private.

Other classes can't directly modify it.

They have to use the methods provided by the class.

That's the basic idea behind encapsulation.


9. What is inheritance?

Inheritance is basically Java saying:

"Hey, this new class is related to that existing class, so let's reuse some of its functionality."

For example:

class Animal {
    void eat() {
        System.out.println("Eating");
    }
}

class Dog extends Animal {
    void bark() {
        System.out.println("Barking");
    }
}

Now Dog automatically gets access to the eat() method from Animal.

So:

Dog dog = new Dog();

dog.eat();
dog.bark();

The dog can eat because it inherited that behavior from Animal.

This represents an is-a relationship.

A Dog is an Animal.


10. What is polymorphism?

Don't let the name scare you.

Polymorphism basically means "many forms."

Imagine you have:

Animal animal;

That reference could point to a Dog, a Cat, or another subclass.

For example:

class Animal {
    void sound() {
        System.out.println("Animal sound");
    }
}

class Dog extends Animal {
    @Override
    void sound() {
        System.out.println("Bark");
    }
}

Now:

Animal animal = new Dog();
animal.sound();

Even though the reference type is Animal, Java executes the Dog implementation.

That's runtime polymorphism.


11. What is method overloading?

Suppose I have an add() method.

I might want to add two numbers:

int add(int a, int b)

But sometimes I might want to add three:

int add(int a, int b, int c)

Java allows us to have both methods with the same name.

That's called method overloading.

For example:

class Calculator {

    int add(int a, int b) {
        return a + b;
    }

    int add(int a, int b, int c) {
        return a + b + c;
    }
}

The important thing is that the parameter list must be different.

Changing only the return type isn't enough.


12. What is method overriding?

Now let's say the parent class already has a method, but the child class wants to provide its own version.

That's method overriding.

class Animal {
    void sound() {
        System.out.println("Animal sound");
    }
}

class Dog extends Animal {

    @Override
    void sound() {
        System.out.println("Bark");
    }
}

The Dog class is basically saying:

"I know the parent has a sound() method, but I want my own implementation."

That's overriding.


13. Overloading vs overriding — what's the difference?

This one is easy to mix up.

Remember this:

Overloading → same name, different parameters

Overriding → child class changes parent method

Here's a quick comparison:

Overloading

Overriding

Usually happens within a class

Happens between parent and child

Parameters must differ

Parameters generally match

Compile-time polymorphism

Runtime polymorphism

Same method name

Same method signature

If you remember those four points, you're good.


14. What is an abstract class?

Sometimes you have a class that you don't want people to create objects of directly.

Instead, you want it to act as a base class.

That's where an abstract class can be useful.

For example:

abstract class Animal {

    abstract void sound();

    void sleep() {
        System.out.println("Sleeping");
    }
}

Notice something interesting.

The class has an abstract method:

abstract void sound();

It doesn't tell us exactly how the animal sounds.

The child class can decide that.

At the same time, sleep() already has an implementation.

So an abstract class can contain both abstract and concrete methods.


15. What is an interface?

Think of an interface as a contract.

Suppose we have:

interface Payment {
    void pay();
}

We're basically saying:

"Any class that implements Payment must provide a pay() implementation."

For example:

class UPI implements Payment {

    public void pay() {
        System.out.println("Payment using UPI");
    }
}

This is useful when you want different classes to follow the same contract.


16. Abstract class vs interface

This is another classic interview question.

Don't try to memorize a huge table.

Think about the use case.

If you have closely related classes and want to share common state and implementation, an abstract class can make sense.

If you mainly want to define a common contract that different classes can implement, an interface is often a better fit.

For example, a Vehicle abstract class could contain common vehicle behavior.

But an interface like:

interface Flyable {
    void fly();
}

could be implemented by completely different classes that can fly.

Modern Java interfaces can also contain default and static methods.


17. What is a constructor?

A constructor is basically the code that runs when you create an object.

For example:

class Student {
    String name;

    Student(String name) {
        this.name = name;
    }
}

Now when we write:

Student student = new Student("Rahul");

the constructor receives "Rahul" and initializes the object.

One thing you should remember:

A constructor does not have a return type.


18. What is this in Java?

this basically means:

"the current object."

For example:

class Student {
    String name;

    Student(String name) {
        this.name = name;
    }
}

Here we have two things called name.

One is the instance variable:

String name;

and one is the constructor parameter:

Student(String name)

So:

this.name

means the object's name.


19. What is super?

If this refers to the current object, super is used to access members of the parent class.

For example:

class Animal {
    String name = "Animal";
}

class Dog extends Animal {
    String name = "Dog";

    void printName() {
        System.out.println(this.name);
        System.out.println(super.name);
    }
}

this.name gives us the child class value.

super.name gives us the parent class value.

Easy enough.


20. What does static mean?

Here's a simple way to think about static.

Normally, a variable belongs to an individual object.

But a static variable belongs to the class itself.

For example:

class Counter {
    static int count = 0;
}

You don't need a separate copy of count for every object.

All objects can share the same static variable.

You'll commonly see static with utility methods, constants, and class-level data.


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

This question catches a lot of beginners.

When you're dealing with objects, == generally checks whether two references point to the same object.

.equals() is generally used to check logical equality, assuming the class implements it appropriately.

For example:

String a = new String("Java");
String b = new String("Java");

System.out.println(a == b);
System.out.println(a.equals(b));

The first comparison checks references.

The second checks the string content.

That's why you shouldn't casually use == when you actually want to compare object values.


22. Why is String immutable?

This sounds complicated, but the idea is simple.

Once a String object is created, you can't change that object.

For example:

String name = "Java";
name = name + " Programming";

It looks like we're modifying name.

But we're actually creating another String value and making name refer to it.

String immutability is useful for things like security, caching, thread safety, and predictable behavior.


23. What is the String Pool?

Java has a special mechanism called the String Pool.

Consider this:

String a = "Java";
String b = "Java";

Java can reuse the same pooled String object rather than creating a completely separate object for each literal.

That's useful because Strings are immutable.

But if you do:

String a = new String("Java");

you're explicitly asking for a new String object.

This is why interviewers sometimes use String examples to test whether you understand references and object creation.


24. String vs StringBuilder vs StringBuffer

Here's the easiest way to remember this.

String

Immutable.

So repeated modifications can create additional String objects.

StringBuilder

Mutable and generally preferred when you're repeatedly building or modifying strings in a single-threaded context.

StringBuffer

Also mutable, but its methods are synchronized.

For example, if you're doing a lot of string manipulation inside a loop, StringBuilder is usually worth considering.


25. What is an exception?

Imagine your program is running normally and suddenly something goes wrong.

Maybe you're trying to divide by zero:

int result = 10 / 0;

Java throws an exception.

An exception represents a problem that interrupts the normal flow of execution.

Java gives us tools such as:

try
catch
finally
throw
throws

to deal with these situations.


26. Checked vs unchecked exceptions

This is another common one.

Checked exceptions

The compiler wants you to deal with these.

Examples include:

  • IOException

  • SQLException

Unchecked exceptions

These generally extend RuntimeException.

Examples:

  • NullPointerException

  • ArithmeticException

  • ArrayIndexOutOfBoundsException

A quick way to remember:

Checked → compiler checks

Unchecked → runtime


27. throw vs throws

These two look almost identical, so beginners often mix them up.

throw is used when you actually want to throw an exception.

throw new IllegalArgumentException("Invalid age");

throws is used in the method declaration to indicate that a method may propagate an exception.

void readFile() throws IOException {
}

So remember:

throw → throw an exception

throws → declare an exception


28. What is finally?

The finally block is commonly used when you have cleanup code that should run after exception handling.

For example:

try {
    // risky code
} catch (Exception e) {
    // handle error
} finally {
    // cleanup
}

You might use it for releasing resources in older resource-management patterns.

For modern Java, try-with-resources is often preferable when working with closeable resources.


29. What is the Java Collections Framework?

Imagine you need to store 100 student names.

You could use an array, but Java provides much more flexible data structures through the Collections Framework.

Some important interfaces are:

  • List

  • Set

  • Map

  • Queue

  • Deque

And some common implementations are:

  • ArrayList

  • LinkedList

  • HashSet

  • TreeSet

  • HashMap

  • TreeMap

  • PriorityQueue

You should definitely know these before a Java technical interview.


30. ArrayList vs LinkedList

Let's keep this practical.

ArrayList is backed by a dynamically resizable array.

Because of that, getting an element by index is generally fast.

LinkedList uses linked nodes.

It can be useful for certain insertion and removal patterns, particularly when you already have the appropriate position.

But here's the important practical point:

Don't automatically choose LinkedList just because you heard insertion is faster.

In real applications, ArrayList is often the better default because of its memory locality and fast indexed access.


31. List vs Set vs Map

This is super easy if you think about what you're storing.

List

You want a collection of values and duplicates are allowed.

List<String> names = new ArrayList<>();

Set

You want unique values.

Set<String> names = new HashSet<>();

Map

You want key-value pairs.

Map<Integer, String> students = new HashMap<>();

So remember:

List → collection of values

Set → unique values

Map → key + value


32. How does HashMap work?

This is where interviews start getting more interesting.

A HashMap stores data using key-value pairs.

For example:

Map<Integer, String> students = new HashMap<>();

students.put(101, "Rahul");
students.put(102, "Amit");

When you give Java a key, hashing helps determine where the entry should be stored.

When you later call:

students.get(101);

Java uses the key's hash information to locate the relevant entry.

For this to work correctly, hashCode() and equals() are extremely important.

If you're preparing for an intermediate or experienced Java interview, don't stop at "HashMap stores key-value pairs." Understand how hashing and collisions work too.


33. HashMap vs Hashtable

Hashtable is an older, legacy collection.

HashMap is generally the modern choice when you don't need synchronization provided by the collection itself.

Another difference is null handling:

HashMap allows one null key and can contain null values.

Hashtable doesn't allow null keys or values.

For concurrent applications, modern Java provides better choices such as ConcurrentHashMap depending on the use case.


34. What is HashSet?

If you need unique values, HashSet is one of the first collections you should think about.

For example:

Set<Integer> numbers = new HashSet<>();

numbers.add(10);
numbers.add(20);
numbers.add(10);

The second 10 doesn't create another duplicate entry.

Also remember that HashSet doesn't guarantee sorted order.

If you need sorted elements, you might look at something like TreeSet.


35. Comparable vs Comparator

Both are related to sorting, but there's a useful difference.

Suppose you have a Student class.

If you want the class itself to define its natural ordering, you can implement Comparable.

class Student implements Comparable<Student> {

    public int compareTo(Student other) {
        return this.age - other.age;
    }
}

But what if sometimes you want to sort students by name and sometimes by age?

That's where Comparator becomes useful.

You can define separate comparison strategies without changing the class's natural ordering.

So:

Comparable → natural ordering

Comparator → custom ordering


36. What is an Iterator?

An Iterator gives you a standard way to move through elements of a collection.

For example:

Iterator<String> iterator = names.iterator();

while (iterator.hasNext()) {
    System.out.println(iterator.next());
}

You can think of it as saying:

"Give me the next item until there are no more items."

Iterators are also useful when you need to remove elements safely during iteration using the iterator's removal operation.


37. What is multithreading?

Imagine your application has multiple things to do.

Instead of making one thread do everything one after another, you can have multiple threads perform work concurrently.

That's basically the idea behind multithreading.

Java provides several tools for this, including:

  • Thread

  • Runnable

  • Callable

  • Executor services

  • Synchronization utilities

  • Concurrent collections

The tricky part isn't creating threads.

The tricky part is making sure those threads don't mess up shared data.


38. Process vs thread

Think about a process as an entire running application.

A thread is one execution path inside that application.

For example, your application could have:

  • One thread handling a request

  • Another processing background work

  • Another handling some other task

Threads within the same process can share resources such as heap memory.

So remember:

Process → independent running environment

Thread → execution unit inside a process


39. What is synchronization?

Here's the problem.

Suppose two threads are both changing the same variable:

count++;

You might assume that count++ is one simple operation.

But internally, it involves reading the value, modifying it, and writing it back.

If two threads do this at the same time, you can get unexpected results.

Synchronization helps control access to shared resources.

For example:

synchronized void increment() {
    count++;
}

The important point is that synchronization can solve certain race conditions, but excessive locking can hurt performance and poor lock design can lead to deadlocks.


40. sleep() vs wait()

This is a classic interview trap.

sleep() belongs to Thread.

Thread.sleep(1000);

It basically says:

"Pause this thread for a while."

wait() is associated with an object's monitor.

It basically says:

"I can't continue until I'm notified or otherwise awakened."

And here's the important difference:

wait() releases the object's monitor while waiting.

sleep() does not release monitors held by the thread.

That's the part interviewers often want to hear.


41. What is deadlock?

Imagine two people each holding something the other person needs.

Person A has resource 1 and waits for resource 2.

Person B has resource 2 and waits for resource 1.

Nobody can move.

That's basically a deadlock.

In Java:

  • Thread A holds Lock 1 and waits for Lock 2.

  • Thread B holds Lock 2 and waits for Lock 1.

Both threads are stuck.

One common way to reduce this risk is to always acquire multiple locks in a consistent order.


42. What is the JVM?

The JVM is the part of Java that actually executes Java bytecode.

But it does much more than simply "run code."

The JVM handles things such as:

  • Class loading

  • Bytecode execution

  • Memory management

  • Garbage collection

  • Runtime optimizations

That's why understanding the JVM becomes increasingly important as you move from beginner Java interviews toward experienced developer interviews.


43. What is garbage collection?

One of the nice things about Java is that you generally don't have to manually free every object you create.

Java has a garbage collector.

Imagine you create an object:

Student student = new Student();

Later, suppose there are no reachable references to that object.

At that point, the object can become eligible for garbage collection.

The JVM can eventually reclaim the memory.

One important point:

Eligible for garbage collection does not mean "deleted immediately."

The JVM decides when and how garbage collection happens.


44. Stack vs heap memory

This is a very common JVM interview topic.

Think of the stack as being closely related to method execution.

When a method runs, it gets an execution frame containing things such as local variables and other execution information.

The heap is where Java dynamically allocates objects.

For example:

Student student = new Student();

Here, student is a reference, while the Student object is generally allocated on the heap.

Don't fall into the trap of saying "all variables are on the stack." The exact memory behavior can involve JVM implementation details and optimizations.

For an interview, focus on the conceptual distinction.


45. What is JIT compilation?

JIT stands for Just-In-Time compilation.

Here's the simple idea.

The JVM can notice that certain pieces of code are being executed frequently.

Instead of repeatedly interpreting that bytecode, the JVM can compile suitable code into native machine instructions at runtime.

This can significantly improve performance for frequently executed code.

So Java isn't simply:

Bytecode → interpret everything forever

Modern JVMs use runtime profiling and optimization techniques, including JIT compilation.


46. What is a functional interface?

A functional interface is an interface with exactly one abstract method.

For example:

@FunctionalInterface
interface Calculator {
    int calculate(int a, int b);
}

Now we can use a lambda:

Calculator add = (a, b) -> a + b;

Some commonly used functional interfaces in Java include:

  • Predicate

  • Function

  • Consumer

  • Supplier

This concept becomes especially important when learning Java 8+ features.


47. What is a lambda expression?

A lambda is basically a shorter way of writing behavior that can be passed around.

Instead of creating a whole class or anonymous implementation, you can write:

name -> System.out.println(name)

For example:

List<String> names =
        List.of("Amit", "Rahul", "Priya");

names.forEach(
        name -> System.out.println(name)
);

Lambdas are heavily used with functional interfaces and the Stream API.


48. What is the Stream API?

Suppose you have a list:

List<Integer> numbers =
        List.of(1, 2, 3, 4, 5);

And you only want the even numbers.

You could write a traditional loop.

Or you could use a stream:

List<Integer> evenNumbers =
        numbers.stream()
               .filter(n -> n % 2 == 0)
               .toList();

Here, we're basically saying:

"Take these numbers, keep the ones that are even, and give me the result as a list."

That's the basic idea behind the Stream API.

Streams are especially useful when you're performing operations such as:

  • Filtering

  • Mapping

  • Sorting

  • Collecting

  • Reducing


49. What is Optional?

If you've worked with Java for a while, you've probably encountered NullPointerException.

Optional provides a way to explicitly represent the possibility that a value may not exist.

For example:

Optional<String> name =
        Optional.ofNullable(getName());

Then:

name.ifPresent(
        value -> System.out.println(value)
);

The idea is to make "value might be missing" more explicit.

However, don't blindly use Optional everywhere. It is primarily useful as a return type and for expressing optional results, while local variables and fields often don't need it.


50. What are records in Java?

Records are one of the modern Java features worth knowing.

Suppose you just want a simple class to hold student data.

Traditionally, you might write a class with fields, a constructor, getters/accessors, equals(), hashCode(), and toString().

With a record, you can write:

public record Student(
    String name,
    int age
) {
}

That's it.

Java generates the standard members based on those components.

Records are especially useful when you're creating simple data-carrying types, such as DTO-style objects.


Quick Revision: 50 Java Interview Questions

Okay, you've reached the end.

Before your interview, don't just read this article once and forget everything.

Try to explain each topic yourself.

Here's your quick revision list:

#

Question

1

What is Java?

2

What are Java's main features?

3

JDK vs JRE vs JVM

4

Why is Java platform independent?

5

What is a class?

6

What is an object?

7

What are the four pillars of OOP?

8

What is encapsulation?

9

What is inheritance?

10

What is polymorphism?

11

What is method overloading?

12

What is method overriding?

13

Overloading vs overriding

14

What is an abstract class?

15

What is an interface?

16

Abstract class vs interface

17

What is a constructor?

18

What is this?

19

What is super?

20

What does static mean?

21

== vs .equals()

22

Why is String immutable?

23

What is the String Pool?

24

String vs StringBuilder vs StringBuffer

25

What is an exception?

26

Checked vs unchecked exceptions

27

throw vs throws

28

What is finally?

29

What is the Collections Framework?

30

ArrayList vs LinkedList

31

List vs Set vs Map

32

How does HashMap work?

33

HashMap vs Hashtable

34

What is HashSet?

35

Comparable vs Comparator

36

What is an Iterator?

37

What is multithreading?

38

Process vs thread

39

What is synchronization?

40

sleep() vs wait()

41

What is deadlock?

42

What is the JVM?

43

What is garbage collection?

44

Stack vs heap

45

What is JIT compilation?

46

What is a functional interface?

47

What are lambda expressions?

48

What is the Stream API?

49

What is Optional?

50

What are records?


How Should You Prepare These Questions?

Here's my biggest advice: don't memorize these answers word-for-word.

That's one of the worst ways to prepare for a technical interview.

Instead, take each question and try to explain it without looking at the answer.

For example, if someone asks:

"What is inheritance?"

Don't try to remember a textbook definition.

Explain it naturally:

"Inheritance allows a child class to reuse properties and methods from a parent class. For example, a Dog can extend Animal and reuse the Animal's eat method."

That's a much better interview answer.

Then, if the interviewer asks a follow-up question, you'll actually understand what you're talking about.

Also, don't ignore coding.

If you're preparing for a Java developer interview, combine these concepts with:

Java Basics → OOP → Collections → Exception Handling → Generics → Streams → Multithreading → JVM → DSA

That's a much stronger preparation path than simply memorizing 50 definitions.


Final Takeaway

If you can confidently explain these 50 Java interview questions, write small examples for the important concepts, and solve basic Java coding problems, you'll have a strong foundation for many Java technical interviews.

And remember, interviews aren't usually about proving that you can memorize the Java documentation.

The interviewer wants to see whether you understand why something works, when you would use it, and what happens behind the scenes.

So don't just memorize.

Understand the concept, write some code, break it, fix it, and then explain it in your own words.

That's when you really start getting good at Java.