Home · Interview questions · Java Developer

Java Developer interview questions

Java interviews often go deep. Expect questions on collections and memory, threads, and how Spring Boot actually works behind its annotations.

What interviewers look for

How the interview usually runs

  1. Recruiter call.
  2. Online coding test.
  3. Technical rounds on Java and Spring.
  4. Design and behavioural rounds.

Stages vary by company, so ask the recruiter what to expect before you start preparing.

10 Java Developer interview questions, and how to answer them

1. How does a HashMap work?

What they want to see: Internals, not just use.

How to answer: Cover buckets, hashing, collisions, treeification and why equals and hashCode must agree.

2. What's the difference between checked and unchecked exceptions?

What they want to see: Language design judgement.

How to answer: Explain each, and say when you'd wrap or rethrow.

3. How does garbage collection work?

What they want to see: JVM awareness.

How to answer: Describe generations and G1, and how you'd read a GC log for long pauses.

4. How do you diagnose a memory leak?

What they want to see: Production debugging.

How to answer: Take a heap dump, analyse in Eclipse MAT, and look for growing caches or listeners.

5. synchronized or a Lock?

What they want to see: Concurrency tools.

How to answer: Locks offer tryLock and fairness. Use java.util.concurrent types before rolling your own.

6. What does @Transactional actually do?

What they want to see: Spring beyond annotations.

How to answer: It's proxy-based, so self-invocation skips it. Cover propagation and rollback rules.

7. How does Spring dependency injection work?

What they want to see: Framework internals.

How to answer: Explain the container, bean scopes and constructor injection.

8. How do you fix slow JPA queries?

What they want to see: Data access performance.

How to answer: Check for N+1 with fetch joins, use projections and look at the SQL produced.

9. What changed in recent Java versions that you use?

What they want to see: Staying current.

How to answer: Mention records, pattern matching or virtual threads, with where you'd use them.

10. How do you deal with a legacy codebase?

What they want to see: Pragmatism.

How to answer: Add tests around behaviour, then refactor in small steps.

A sample answer

How do you diagnose a memory leak?

A service restarted every few days with OutOfMemoryError. I captured a heap dump and found a static map keyed by session that was never cleared. I replaced it with a Caffeine cache with a size limit and expiry, and added a heap alert. Memory then stayed flat, and restarts stopped.

A made-up example to show the structure. Use your own experience and real numbers.

Common mistakes

Practise this out loud

Run a mock interview for a Java Developer role. Questions change every time, you answer by voice or typing, and each answer gets a score with feedback.

Frequently asked questions

Which Java topics come up most?

Collections, concurrency, JVM memory and Spring Boot are the usual core. Stream API questions are common at junior and mid level.

Do I need to know Kotlin for Java roles?

Usually not, though it's useful if the team uses it. Check the job description.

Related roles