Top 20 JVM Interview Questions and Answers

Top 20 JVM Interview Questions and Answers Work through these 20 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.

  1. HashMap vs ConcurrentHashMap — when and why?

    HashMap for single-threaded or external synchronization. ConcurrentHashMap for shared concurrent maps — finer-grained locking than Hashtable. Cannot store null keys/values in...

    Full answer

  2. Explain garbage collection basics in the JVM.

    New objects allocate in Eden; minor GC copies survivors to survivor spaces, then old gen. When old gen fills, major/full GC runs — longer pauses. Tune -Xmx, choose G1 for...

    Full answer

  3. How do CompletableFuture and virtual threads compare for concurrency?

    Use virtual threads when business logic is naturally blocking — call DB, call HTTP, return. Use CompletableFuture when composing multiple independent async results with...

    Full answer

  4. IdentityHashMap vs HashMap — when would you use IdentityHashMap?

    Use when identity matters not value — tracking object visitation in deep graph walk. Business keys (userId, email) belong in HashMap with proper equals/hashCode....

    Full answer

  5. Compare G1, ZGC, and Shenandoah garbage collectors.

    Default G1 fine for most Spring Boot services — tune -XX:MaxGCPauseMillis=200. Payment API p99 SLA <10ms GC pause: try -XX:+UseZGC on Java 21 large heap. Benchmark with JMH and...

    Full answer

  6. What is Metaspace and how do class loading issues cause memory leaks?

    Production set MaxMetaspaceSize 256m with monitoring. Investigate Metaspace OOM: heap dump + classloader histogram. Avoid generating unlimited dynamic proxies. OSGi/script...

    Full answer

  7. JVM container awareness and memory settings for Kubernetes?

    Container limit 1Gi: JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=50.0. Monitor container memory vs heap used in Actuator metrics. Leave headroom for...

    Full answer

  8. Explain JIT compilation tiers (C1, C2) and warmup.

    JMH @Warmup iterations required. Production: readiness probe after warmup traffic or use Kubernetes minReadySeconds. Serverless: GraalVM native or tiered warmup requests....

    Full answer

  9. Your application memory usage keeps increasing over time. What do you suspect?

    Suspect memory leak if heap used grows after GC without traffic drop. Capture heap dump on OOM (`-XX:+HeapDumpOnOutOfMemoryError`), compare dominator tree. Common in Spring:...

    Full answer

  10. Autoscaling enabled but error rate increases. Why?

    New pods accept traffic before JVM/Caffeine warm. HPA adds API pods but Postgres max connections fixed. ```yaml readinessProbe: initialDelaySeconds: 30 ``` Scale connection...

    Full answer

  11. When do useMemo and useCallback actually help — and when do they make things worse?

    I memoize a filtered 10k-row list or a value passed into a memoized DataGrid. I do not wrap every onClick. Profiler + why-did-you-render first. In React 19 I let the compiler...

    Full answer

  12. What are hidden classes in JDK 15, and which runtime frameworks rely on them?

    I do not write hidden classes in business code. I know JDK 15+ lambdas and several proxy libraries use them so generated bytecode unloads cleanly. If a heap dump shows...

    Full answer

  13. Which JVM and library changes in JDK 15 show up in production ops, not just language trivia?

    If we touched 15 on the way to 17/21, I check three ops items: collector is no longer experimental so flags change, ZGC may uncommit so RSS graphs look different, and any...

    Full answer

  14. What did generational ZGC change in JDK 21, and when would you pick it over G1?

    For a large-heap, latency-sensitive API I trial generational ZGC in staging: p99 pause, allocation rate, and RSS. I keep G1 if throughput or CPU is the SLO. I never flip...

    Full answer

  15. JDK 27 is not LTS. What do you inherit on upgrade without writing new application code?

    I would not pin 27 as LTS — 25 is still the pin. On a 27 canary I inherit G1 in CI that used to pick Serial, compact headers, and hybrid TLS if the JDK terminates TLS. I...

    Full answer

  16. Why did JDK 27 make G1 the default GC everywhere, and when would you still pick Serial or ZGC?

    First I check the collector in the new CI log. If it flipped Serial → G1, that is JEP 523 — not a 27 regression. I keep G1 in prod with equal heap and a pause goal. I only...

    Full answer

  17. What does Spring Boot do versus what LangChain4j does in the same Java service?

    Boot is the host. LangChain4j is how that host talks to models. I keep REST, JWT, and JPA on Spring. I inject ChatLanguageModel from a langchain4j-*-spring-boot-starter and...

    Full answer

  18. When do you pick LangChain4j instead of Spring AI on the same Spring Boot service?

    I never say “LangChain4j is better.” I say which API the service already standardized on. Pick Spring AI when the team wants the official Spring project and advisors. Pick...

    Full answer

  19. What is Anthropic prompt caching in LangChain4j 1.22.0, and when is it worth turning on?

    I put the interviewer persona, tool JSON, and the static policy appendix in the cached system prefix. The user question and this-request RAG chunks stay dynamic. If the prefix...

    Full answer

  20. Explain the difference between == and .equals() in Java.

    For primitives, == compares values. For objects, == asks if two references point to the same instance. equals() compares content when overridden — String overrides it for...

    Full answer

JVM Interview Questions and Answers · Top 50 JVM Interview Questions and Answers (2026 Edition) · Top 40 JVM Interview Questions | Must-Prepare before interview. · JVM Interview Questions Every Fresher Must Know

All interview question lists · Interview guides · Home · Support the platform