# Top Java Interview Questions for Freshers — With Short, Correct Answers

Source: https://skills101.in/learn/java/java-interview-questions — Skills101 free tutorial (Java Programming). Updated 2026-11-09.

Use this page to revise before interviews. Each answer is short enough to say in 30 seconds — then explain more if the interviewer asks.

![JDK contains JRE contains JVM — question 1 in almost every Java interview](https://skills101.in/learn-img/java/jdk-jre-jvm.svg)

## Basics

**1. JDK vs JRE vs JVM?** JVM runs bytecode; JRE = JVM + libraries (to run); JDK = JRE + tools like javac (to develop).

**2. Why is Java platform-independent?** javac produces bytecode, and every OS has a JVM that runs the same bytecode.

**3. Why is `main` public static void?** public — the JVM calls it from outside; static — no object exists yet; void — it returns nothing to the JVM.

**4. Primitive vs wrapper?** `int` stores a value; `Integer` is an object (needed in collections, can be null). Autoboxing converts between them.

**5. Stack vs heap?** Stack: method calls and local variables (one per thread). Heap: all objects (shared); cleaned by the garbage collector.

## OOP

**6. The four pillars?** Encapsulation, Abstraction, Inheritance, Polymorphism.

**7. Overloading vs overriding?** Overloading: same name, different parameters, same class, compile time. Overriding: same signature in a subclass, runtime.

**8. Abstract class vs interface?** Abstract class: state + code, constructors, extend one. Interface: contract, default/static methods, constants, implement many.

**9. Can we override a static method?** No. A static method with the same signature in a subclass **hides** the parent's; it is not runtime polymorphism.

**10. Can a constructor be private?** Yes — used in the Singleton pattern and utility classes.

**11. What is `super` / `this`?** `this` = current object (or `this(...)` constructor chaining); `super` = parent's members or constructor.

## Strings

**12. Why are Strings immutable?** Security, string-pool sharing, thread safety and safe hash keys.

**13. == vs equals()?** `==` compares references; `equals()` compares content.

```java
public class Main {
    public static void main(String[] args) {
        String a = "skills", b = "skills", c = new String("skills");
        System.out.println((a == b) + " " + (a == c) + " " + a.equals(c));
    }
}
```

```text
true false true
```

**14. String vs StringBuilder vs StringBuffer?** String immutable; StringBuilder mutable and fast; StringBuffer mutable and synchronized (slower).

## Collections

**15. ArrayList vs LinkedList?** ArrayList: O(1) get, best default. LinkedList: O(1) insert/remove at known nodes, O(n) get.

**16. How does HashMap work?** hashCode → bucket index; collisions chained (tree after 8); equals finds the key; resizes at load factor 0.75; O(1) average.

**17. Why override hashCode with equals?** Equal objects must have equal hash codes, or hash collections can't find them.

**18. HashMap vs ConcurrentHashMap?** HashMap is not thread-safe; ConcurrentHashMap is safe and fast for concurrent use.

**19. Comparable vs Comparator?** Comparable: one natural order (`compareTo`) inside the class. Comparator: any number of external orders.

## Exceptions

**20. Checked vs unchecked?** Checked (IOException) must be caught or declared; unchecked (RuntimeException) need not be.

**21. final vs finally vs finalize?** final — constant/no override/no extend; finally — always-run block; finalize — deprecated GC hook.

**22. Can finally be skipped?** Only if the JVM exits (`System.exit`) or crashes.

## Java 8 and threads

**23. What is a functional interface?** An interface with exactly one abstract method; can be implemented with a lambda.

**24. map vs flatMap?** map transforms each element to one element; flatMap transforms each to a stream and flattens them.

```java
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        List<List<Integer>> nested = List.of(List.of(1, 2), List.of(3), List.of(4, 5));
        System.out.println(nested.stream().map(List::size).toList());
        System.out.println(nested.stream().flatMap(List::stream).toList());
    }
}
```

```text
[2, 1, 2]
[1, 2, 3, 4, 5]
```

**25. start() vs run()?** start() creates a new thread; run() executes in the current thread.

## How to answer well

1. Give the **one-line answer** first.
2. Add an **example** (a tiny code snippet or real use).
3. Mention a **trade-off** or common mistake — that shows real understanding.

## Common mistakes

- Memorising definitions without being able to give an example.
- Saying "Java is pass-by-reference" (it is always pass-by-value).
- Confusing `final`, `finally` and `finalize`.

## Quick recap

- Revise: JVM/JRE/JDK, OOP pillars, overloading vs overriding, String pool, HashMap internals, exceptions, Java 8.
- Answer short → example → trade-off.
- Practise coding problems in Java on the [Skills101 judge](https://skills101.in/practice/code).


Practice quiz and free certificate: https://skills101.in/learn/java/java-interview-questions