Career Scan

Interview practice with an AI panel

Interview questions

Java developer interview questions

Java interviews usually move in three layers: core language and collections, then how you build real services (Spring, databases, testing), then how the JVM and concurrency behave under load. Interviewers listen for whether you understand why something works, not just its name.

The questions below are grouped by level. Under each one is what a strong answer covers, so you can check your own answer against it rather than memorise a script.

Looking for questions for freshers and graduates? Java interview questions for freshers

What interviewers assess

Basic questions

  1. What is the difference between == and equals() in Java?

    What a good answer covers: == compares references for objects (values for primitives); equals() compares logical equality as defined by the class. Mention that String and wrapper types override equals(), and that the Integer cache makes == look like it works for small values.

  2. Why must you override hashCode() when you override equals()?

    What a good answer covers: The contract: equal objects must have equal hash codes, otherwise HashMap and HashSet put them in different buckets and lookups fail. A good answer gives a short example of a broken map lookup.

  3. Explain the difference between ArrayList and LinkedList. When would you use each?

    What a good answer covers: Array-backed vs node-based; O(1) random access vs O(n); amortised O(1) append for both; LinkedList's extra memory and poor cache locality. Most candidates who know their stuff say ArrayList is the right default almost always.

  4. What are checked and unchecked exceptions?

    What a good answer covers: Checked exceptions must be declared or caught (IOException); unchecked extend RuntimeException (NullPointerException, IllegalArgumentException). A strong answer gives an opinion on when to use each and mentions not swallowing exceptions.

  5. What does it mean for a class to be immutable, and how do you make one?

    What a good answer covers: Final class or private constructor, private final fields, no setters, defensive copies of mutable inputs and outputs. Benefits: thread safety, safe as map keys. Records are a modern shortcut for simple cases.

Intermediate questions

  1. How does HashMap work internally?

    What a good answer covers: Array of buckets, index from the hash, collisions chained in lists that become balanced trees after a threshold (Java 8+), resizing when the load factor (0.75) is exceeded. Bonus: why HashMap isn't thread-safe and what ConcurrentHashMap does differently.

  2. Walk me through how a request reaches your controller in a Spring Boot application.

    What a good answer covers: Embedded server (Tomcat) receives it, DispatcherServlet routes it via handler mappings, filters and interceptors run, arguments are bound and validated, the controller calls services, and the response is serialised (usually by Jackson). Strong candidates tie this to something they debugged.

  3. What is dependency injection and why does Spring use it?

    What a good answer covers: Objects receive their collaborators instead of creating them, which decouples code and makes testing easy. Mention constructor injection as the preferred style, bean scopes, and how it lets you swap a real repository for a mock in tests.

  4. What is the N+1 query problem in JPA/Hibernate and how do you fix it?

    What a good answer covers: Loading a list and then lazily loading a relationship per row triggers one extra query per item. Fixes: fetch joins, entity graphs, batch fetching, or DTO projections. A strong answer explains how they noticed it (SQL logs, slow endpoint).

  5. How do streams differ from loops, and when would you avoid a stream?

    What a good answer covers: Declarative pipeline, lazy evaluation, easy parallelism. Avoid when you need checked exceptions, early exit with complex state, or when a simple loop is clearer. Mention that parallel streams are not a free speed-up.

Advanced questions

  1. Explain the Java Memory Model and what volatile guarantees.

    What a good answer covers: Happens-before relationships; volatile gives visibility and ordering for a single variable but not atomicity for compound actions like count++. Compare with synchronized and the atomic classes.

  2. How would you diagnose a Java service whose memory keeps growing until it crashes?

    What a good answer covers: Confirm with GC logs and metrics, take heap dumps, analyse with a tool such as Eclipse MAT, look for growing collections, caches without eviction, ThreadLocals and listeners that are never removed. Interviewers want a methodical process, not a guess.

  3. Compare garbage collectors such as G1 and ZGC. How do you choose?

    What a good answer covers: G1 as the balanced default with region-based collection and pause targets; ZGC for very low pauses on large heaps at some throughput cost. Choose by measuring latency targets and heap size, not by fashion.

  4. How do virtual threads (Java 21) change the way you write concurrent code?

    What a good answer covers: Cheap threads managed by the JVM let you write simple blocking code for high-concurrency I/O instead of reactive chains. Caveats: pinning inside synchronized blocks, and they don't speed up CPU-bound work.

  5. Design an idempotent payment endpoint in Spring Boot. What could go wrong?

    What a good answer covers: Idempotency keys stored with a unique constraint, transactions around the state change, handling retries and timeouts from the client, and what happens when the downstream provider succeeds but your response is lost. Strong answers discuss failure cases first.

Common mistakes

How to prepare

Reading questions only goes so far: the real test is answering them aloud, under follow-up questions. Career Scan builds a mock interview from your own resume and the job, then shows exactly which answers need work.

Frequently asked questions

Which Java version should I prepare for?

Prepare core concepts that apply to every version, then know what changed in Java 8 (streams, lambdas, Optional), 17 (records, sealed classes) and 21 (virtual threads, pattern matching). Many companies run 17 or 21 today.

Do Java interviews include coding rounds?

Usually, yes. Expect at least one problem-solving round using collections and algorithms, and for experienced roles a design or code-review discussion as well.

How many questions does a Java technical round usually have?

It varies by company, but a one-hour round often covers five to ten main questions, with follow-ups that go deeper on whatever you say.

Related interview questions