Interview questionsUpdated 12 Oct 2026 · Team InterviewPlan

Java Developer Interview Questions and Answers

Java developer interviews still start with core Java, but in 2026 most panels quickly move to Spring Boot, microservices, concurrency and how you debug real production issues. These questions reflect what Java candidates are asked at services firms like TCS and Infosys, banks and product companies, with model answers from real project work.

What interviewers test in a Java developer interview

Most loops include a core Java round, a coding round on data structures, a Spring Boot and microservices round, and for experienced candidates a design or production-support discussion. Panels check whether you understand how things work underneath, not just how to use an annotation.

Expect follow-ups like what happens if two threads call this method at once, or how would this behave with a million records. Answer with the internals and a concrete example.

  • Core Java: OOP, immutability, exceptions, generics and collections
  • Concurrency: synchronization, locks, ExecutorService, CompletableFuture and virtual threads
  • JVM: heap and stack, garbage collectors, memory leaks and tuning flags
  • Spring: IoC, bean scopes, Spring Boot auto-configuration, Spring Security basics
  • Data and services: JPA, transactions, REST, Kafka and resilience patterns

Technical topics to revise

Revise with code. Write a small Spring Boot service with a REST endpoint, a JPA repository and a unit test, and be ready to explain every annotation in it.

  • HashMap, ConcurrentHashMap, ArrayList versus LinkedList and TreeMap
  • Streams, Optional, lambdas, records, sealed classes and pattern matching
  • Virtual threads in Java 21 and when they help
  • G1 and ZGC basics, heap dumps and thread dumps
  • Spring Boot: @Transactional, profiles, actuator and exception handling
  • Hibernate: N+1 queries, fetch types, caching and pagination
  • Microservices: circuit breakers with Resilience4j, API gateways and Kafka consumers
  • Testing: JUnit 5, Mockito and Testcontainers

How to structure your answers

For concept questions, give a one-line definition, explain the internals and finish with when you used it or a pitfall you hit. For coding, talk through your approach and complexity before writing code.

For project questions, describe the architecture briefly, your specific contribution and a measurable result, such as reducing p95 latency or cutting a batch job's run time.

How InterviewPlan AI helps you prepare

Java mock interviews ask core Java, Spring Boot and scenario questions and give feedback on depth and clarity. Coding help is available for practice problems, and Resume AI turns project descriptions into impact bullets.

In live technical interviews, Interview Copilot provides speaker-labelled transcription and resume-grounded answer drafts in under a second. Once you are hired, Java Job Support gives live expert-plus-AI help with tickets, code reviews and stand-ups in your first 90 days, at $5 per hour with 200 AI credits included.

Questions and model answers

9 questions you are likely to hear.

  1. How does HashMap work internally?

    Why they ask: This is the most asked core Java question and tests understanding of hashing, collisions and performance.

    Sample answer: HashMap stores entries in an array of buckets. When I put a key, it calls hashCode, spreads the bits and uses the result to pick a bucket index. If two keys land in the same bucket, entries form a linked list, and since Java 8, once a bucket passes eight entries and the table is large enough, it converts to a red-black tree so lookups stay O(log n). When size exceeds capacity times the load factor of 0.75, the table doubles and entries are redistributed. That is why mutable keys are dangerous: if hashCode changes after insertion, the entry becomes unreachable.

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

    Why they ask: Interviewers test the contract between the two methods and practical consequences.

    Sample answer: The contract says equal objects must have equal hash codes. Hash-based collections first use hashCode to find a bucket and then equals to find the exact entry. If I override equals but not hashCode, two logically equal objects may land in different buckets, so a HashSet can hold duplicates and a HashMap get can return null for a key that is present. I usually generate both from the same fields, or use a Java record, which provides both automatically. I once fixed a deduplication bug in a customer import job caused exactly by this.

  3. What is the difference between synchronized, ReentrantLock and ConcurrentHashMap?

    Why they ask: This checks practical concurrency knowledge.

    Sample answer: synchronized is a built-in monitor lock that is simple and released automatically when the block exits. ReentrantLock gives more control: tryLock with a timeout, interruptible locking and optional fairness, but I must unlock in a finally block. ConcurrentHashMap is a thread-safe map that avoids locking the whole map, using CAS operations and fine-grained locking per bin, and offers atomic methods like computeIfAbsent. In a pricing service, replacing a synchronized HashMap cache with ConcurrentHashMap and computeIfAbsent removed a lock contention hotspot and improved throughput noticeably under load tests.

  4. How would you find and fix a memory leak in a Java service?

    Why they ask: This tests production debugging skills, which matter more than theory for experienced roles.

    Sample answer: I start with monitoring: if heap usage after each full GC keeps climbing, that suggests a leak. I take a heap dump with jcmd or enable HeapDumpOnOutOfMemoryError, then analyse it in Eclipse MAT to find the dominator tree and the objects retaining the most memory. Common causes are static collections that only grow, caches without eviction, unclosed resources and ThreadLocal values in thread pools. In one Spring Boot service, MAT showed a static map of session objects that was never cleaned. Switching to a Caffeine cache with expiry fixed weekly out-of-memory restarts.

  5. Explain how @Transactional works in Spring and a common pitfall.

    Why they ask: Transactions are core to most enterprise Java work and often misunderstood.

    Sample answer: @Transactional works through a Spring proxy: when a call enters the proxy, it starts or joins a transaction, and on return it commits, or rolls back on unchecked exceptions by default. The most common pitfall is self-invocation: calling a transactional method from another method in the same class bypasses the proxy, so no transaction starts. Another is that checked exceptions do not trigger rollback unless I set rollbackFor. I hit the self-invocation issue in an order service where partial writes stayed in the database. Moving the method into a separate service bean fixed it.

  6. What is the N+1 query problem in Hibernate and how do you solve it?

    Why they ask: This is a very common performance issue in JPA applications.

    Sample answer: N+1 happens when I load a list of parent entities with one query and Hibernate then runs one extra query per parent to load a lazy association. Loading 200 orders and their items can mean 201 queries. I detect it by enabling SQL logging or using a tool like Hibernate statistics. Fixes include a JOIN FETCH in JPQL, an entity graph, or batch fetching with a batch size setting. For read-only screens I often use a DTO projection instead. In one reporting API this reduced the queries per request from a few hundred to two, and response time fell from about 3 seconds to under 300 milliseconds.

  7. How do you make microservices resilient when a downstream service is slow?

    Why they ask: Interviewers check practical distributed systems knowledge.

    Sample answer: I set explicit timeouts on every outbound call, because default timeouts are often far too long. I add a circuit breaker with Resilience4j so that after a failure threshold, calls fail fast and return a fallback, like cached data or a clear error. Retries are limited, use exponential backoff and are only applied to idempotent operations. Bulkheads keep one slow dependency from exhausting all threads. In a payments platform, adding a 2-second timeout and a circuit breaker on a fraud-check service stopped a slowdown in that service from taking down the entire checkout flow.

  8. What are virtual threads in Java 21 and when would you use them?

    Why they ask: This checks whether you keep up with modern Java.

    Sample answer: Virtual threads are lightweight threads managed by the JVM rather than the operating system, so I can run hundreds of thousands of them. When a virtual thread blocks on I/O, the JVM unmounts it from the carrier thread, which lets simple blocking code scale like asynchronous code. They suit I/O-heavy workloads such as REST calls and database queries, not CPU-heavy tasks. Pitfalls include pinning when blocking inside synchronized blocks and libraries that rely on ThreadLocal heavily. In Spring Boot 3.2 and later I can enable them with a single property and then load test before rolling out.

  9. Tell me about a difficult production issue you resolved.

    Why they ask: This behavioral-technical question reveals ownership and debugging approach.

    Sample answer: Our order service at a retail client began timing out every day around noon. Thread dumps showed most request threads waiting on database connections from HikariCP. Looking at slow query logs, a reporting query added in the last release was running a full table scan at peak time and holding connections for seconds. I added a composite index on the filtered columns, moved the report to a read replica and set a connection timeout with a clear alert. Timeouts stopped the same day, and I added slow query checks to our release checklist.

FAQ

Questions people ask about java developer.

Which Java version should I prepare for interviews?

Prepare Java 17 and 21, which are the most common long-term support versions in 2026. Know streams, records, sealed classes, pattern matching for switch and virtual threads, and be able to explain why your team chose its version.

How important is Spring Boot in Java interviews?

Very important for most backend roles. Expect questions on dependency injection, bean lifecycle, auto-configuration, transactions, exception handling, Spring Security basics and testing. Be ready to explain what happens when a request reaches a controller.

Do Java interviews include data structures and algorithms?

Most do, especially product companies. Expect arrays, strings, hash maps, trees and some graph or dynamic programming problems. Services firms often focus more on core Java and Spring, but one coding round is common everywhere.

Can I get help after joining a Java project?

Yes. InterviewPlan AI's Java Job Support provides live expert-plus-AI help during your first 90 days on a new job with stand-ups, tickets and code reviews. It is $5 per hour including 200 AI credits, and hours never expire.

P.S.

Reading helps. Practising out loud helps more.

Start free with 5 live minutes and 100 AI credits for Resume AI, Job Search, Auto-Apply, mock interviews and Behavioral Coach.