22 questions · Updated June 2026

Top Java Interview Questions and Answers (2026)

These questions reflect what Chennai-based product and service companies actually ask in 2026. Each answer is short enough to remember and accurate enough to defend in a follow-up.

Book a free demo
  1. Q01.What is the difference between JDK, JRE and JVM?

    The JVM (Java Virtual Machine) executes bytecode. The JRE (Java Runtime Environment) bundles the JVM with core libraries needed to run programs. The JDK (Java Development Kit) adds the compiler and developer tools needed to build them.

  2. Q02.Why is Java called platform-independent?

    Source compiles to bytecode that runs on any platform with a compatible JVM. The JVM, not Java, handles platform-specific differences.

  3. Q03.What's the difference between == and equals()?

    `==` compares object references (memory identity). `equals()` compares logical equality and should be overridden alongside `hashCode()` for value-style objects.

  4. Q04.Why must equals() and hashCode() be overridden together?

    Collections like HashMap use `hashCode()` to find buckets and `equals()` to compare entries. If they disagree, lookups silently fail.

  5. Q05.Explain the difference between ArrayList and LinkedList.

    ArrayList is backed by a dynamic array — O(1) random access, slow inserts in the middle. LinkedList is a doubly-linked list — O(1) inserts at known positions, O(n) random access.

  6. Q06.What is the difference between HashMap and ConcurrentHashMap?

    HashMap is not thread-safe. ConcurrentHashMap allows concurrent reads and segmented writes without external locking, suitable for high-throughput multi-threaded code.

  7. Q07.What are checked and unchecked exceptions?

    Checked exceptions extend `Exception` and must be declared or caught. Unchecked exceptions extend `RuntimeException` and don't need to be declared.

  8. Q08.What does the volatile keyword do?

    It guarantees that reads and writes to a variable go directly to main memory, providing visibility across threads — but not atomicity for compound operations like `i++`.

  9. Q09.What is a functional interface?

    An interface with a single abstract method, like `Runnable` or `Function<T,R>`. It can be the target type of a lambda expression.

  10. Q10.What is the Stream API used for?

    Declarative transformations on collections — filter, map, reduce, collect — with support for lazy evaluation and parallelism.

  11. Q11.Difference between abstract class and interface?

    Abstract classes can carry state and constructors and use single inheritance. Interfaces define contracts, support multiple inheritance, and (since Java 8) allow default methods.

  12. Q12.What is dependency injection?

    A design pattern where objects receive their dependencies from outside instead of constructing them. Spring's IoC container is the most common Java implementation.

  13. Q13.What is the Spring Boot starter pattern?

    Curated dependency bundles (`spring-boot-starter-web`, `spring-boot-starter-data-jpa`, etc.) that pull in compatible versions and auto-configure sensible defaults.

  14. Q14.What is the difference between @Component, @Service and @Repository?

    All three are stereotypes that register beans. `@Service` marks business logic, `@Repository` marks data-access classes (and translates persistence exceptions), `@Component` is the generic catch-all.

  15. Q15.How does Spring Boot auto-configuration work?

    On startup, Spring scans the classpath, evaluates `@Conditional` rules, and creates beans for the dependencies it finds — for example, an embedded Tomcat when `spring-boot-starter-web` is present.

  16. Q16.What is JPA and how does it differ from Hibernate?

    JPA is a specification for ORM in Java. Hibernate is the most common implementation. Application code targets JPA interfaces so it can swap implementations without rewrites.

  17. Q17.Difference between String, StringBuilder and StringBuffer?

    String is immutable. StringBuilder is mutable and not thread-safe (use it for local work). StringBuffer is the thread-safe equivalent — rarely needed today.

  18. Q18.What does the synchronized keyword do?

    It acquires a monitor lock on the target object or class, ensuring only one thread at a time executes the protected block.

  19. Q19.Explain garbage collection generations.

    Heap is split into young and old generations. New objects start in the young generation; survivors get promoted. Generational GC works because most objects die young.

  20. Q20.What is the difference between SOAP and REST?

    SOAP is a strict, XML-based protocol with built-in standards for security and contracts. REST is an architectural style over HTTP using JSON, lighter and easier to consume.

  21. Q21.What is a record class in modern Java?

    A concise way to declare an immutable data carrier. The compiler generates constructor, accessors, `equals`, `hashCode` and `toString`.

  22. Q22.How would you secure a Spring Boot REST API?

    Add Spring Security with JWT or OAuth2 resource server, enforce HTTPS, validate inputs, restrict CORS origins, and audit dependencies with `dependency-check`.

Interview prep support

Get 1:1 prep on Java

Our mentors will reach out with a personalised prep plan, mock interview slots and target-company question banks.