Java Interview Questions and Answers

Java interviews test three things: how well you know the language (OOP, collections, generics, exceptions, streams), how you reason about concurrency and memory (threads, locks, the Java memory model, garbage collection), and how you apply it to real services (Spring, databases, performance). The questions below cover all three, each with a worked answer and code.

Start with the fundamentals, then move to concurrency and JVM internals, which is where mid-level and senior interviews spend most of their time. Mark what you have read, revise what you missed, and use the coding problems to practise the same ideas under a timer.

Questions

Related

Frequently asked questions

What are the most asked Java interview topics?

Object-oriented design, the collections framework (HashMap internals especially), multithreading and the java.util.concurrent package, exceptions, the JVM memory model and garbage collection, Java 8 streams and lambdas, and Spring for backend roles.

How should I prepare for a Java interview in a week?

Spend the first days on collections, OOP and exceptions, then concurrency and JVM internals, and finish with a few coding problems and one design question. Reading each answer and then explaining it aloud works better than rereading.

Do I need to know Spring for a Java interview?

For most backend roles, yes: dependency injection, how a request flows through a Spring Boot application, transactions and configuration. See the Spring Boot questions linked on this page.

Are these Java questions free?

A sample is free to read without paying. Create a free account to unlock more, and Premium unlocks every answer.