QuizCluster
Java EcosystemJava Developer to Lead Java Architect18 min read

How to Prepare for Java Developer Interview: Core to Spring Boot & JVM

Complete Guide to Cracking Senior Java, Spring Boot 3, JVM Internals & Concurrency Rounds

Siddharth Rao
Staff Backend Architect & Java Community Speaker
12+ Years in Java High-Throughput Trading Systems
Prep Timeline
6 to 8 Weeks
Format
Core Java, Frameworks, JVM Internals, LLD/Design
Conversion
+85% Technical Pass Rate
How to Prepare for Java Developer Interview: Core to Spring Boot & JVM
Executive Summary & Key Takeaways

What You Must Master to Clear This Track

  • Understand the inner workings of HashMap (B-tree red-black tree thresholding after size 8) and ConcurrentHashMap (segment-level lock stripping & CAS).
  • Explain the exact JVM Memory layout: Heap (Eden, Survivor, Tenured), Metaspace, Stack Frames, and JIT compilation tiers.
  • Master Garbage Collectors: G1GC, ZGC (sub-millisecond pause times), and Generational ZGC in Java 21.
  • Deep dive into Spring Framework: Bean lifecycle, circular dependency resolution, Proxying (JDK vs CGLIB), and transactional propagation modes.
  • Leverage Java 21 Virtual Threads (Project Loom) and Structured Concurrency over traditional heavy OS thread pools.
Structured Preparation Timeline

Step-by-Step Study Plan

Follow this sequential roadmap designed to take you from core foundations to advanced architecture and mock interviews.

Phase 1 (Weeks 1-2)

Language Internals & Collections Mastery

Core Java, Collections & OOP Foundations

Hash collisions, equals/hashCode contract, String pool immutability, Generics type erasure, and Java 8-21 stream features.

Key Milestones
  • Explain bucket collision chaining and treeification in java.util.HashMap.
  • Write clean Functional Interfaces, Streams, Lambdas, and Optional pipeline logic.
  • Master Java 17-21 features: Pattern Matching for switch, Record classes, Sealed classes, and Text Blocks.
Recommended Actions
  • Always implement both equals() and hashCode() when creating custom Map keys.
  • Know the difference between fail-fast (ArrayList) and fail-safe (CopyOnWriteArrayList) iterators.
Phase 2 (Weeks 3-4)

Thread Safety, Memory Model & Garbage Collection

Multithreading, Concurrency & JVM Internals

ReentrantLock, Semaphore, CountDownLatch, CompletableFuture, JMM happens-before guarantees, Metaspace, and GC tuning.

Key Milestones
  • Explain volatile vs AtomicInteger vs synchronized in CPU cache coherency (MESI protocol).
  • Profile memory leaks using JVM flags, heap dumps (jcmd/jmap), and GC log flags.
  • Compare Java 21 Virtual Threads with standard platform threads in I/O bound workloads.
Recommended Actions
  • Avoid using raw synchronized blocks; master java.util.concurrent (ExecutorService, ThreadPoolExecutor).
  • Know common JVM flags: -Xms, -Xmx, -XX:+UseG1GC, -XX:+UseZGC.
Phase 3 (Weeks 5-6)

Dependency Injection, AOP, JPA & Microservices

Spring Boot 3, Hibernate & Enterprise Architecture

Spring Bean lifecycle, @Transactional rollback gotchas, N+1 query problem in Hibernate, and Spring Cloud / Kafka integration.

Key Milestones
  • Trace bean creation: BeanDefinition -> Instantiation -> Population -> Aware interfaces -> PostConstruct -> Proxies.
  • Resolve Hibernate LazyInitializationException and N+1 query issues using JOIN FETCH and EntityGraphs.
  • Build production-grade REST APIs with Spring Boot 3, Actuator metrics, and OpenAPI documentation.
Recommended Actions
  • Understand why calling a @Transactional method from inside the same class bypasses the CGLIB proxy.
  • Practice writing JUnit 5 and Mockito unit/integration tests with Testcontainers.
Deep-Dive Architecture & Concepts

1. Core Java & Collection Internals (The Must-Knows)

Interviewers frequently probe your understanding of Java collections down to pointer operations and bucket allocation.

HashMap Internals (Java 8+)

Array of Node<K,V> buckets with initial capacity 16 and load factor 0.75. When a bucket length exceeds TREEIFY_THRESHOLD (8) and total capacity >= 64, it transforms into a Red-Black Tree (TreeNode) for O(log N) lookup.

ConcurrentHashMap Synchronization

Java 8+ uses CAS (Compare-And-Swap) for empty bucket insertion and fine-grained synchronized locking on the individual head node of each bucket, avoiding global table locking.

String Immutability & String Constant Pool

Strings are immutable for security, thread safety, and memory caching in the String Pool located in the Heap.

Java 21 Modern Features: Records, Sealed Types & Pattern Matching
java
// Sealed hierarchy for expressive domain modeling
public sealed interface PaymentStatus permits Success, Failed, Pending {}

public record Success(String txId, BigDecimal amount) implements PaymentStatus {}
public record Failed(String reasonCode, String errorMsg) implements PaymentStatus {}
public record Pending(Instant initiatedAt) implements PaymentStatus {}

// Pattern Matching Switch in Java 21
public static String formatPayment(PaymentStatus status) {
    return switch (status) {
        case Success s -> "Captured $" + s.amount() + " (TX: " + s.txId() + ")";
        case Failed f when f.reasonCode().equals("INSUFFICIENT_FUNDS") -> "User needs to top-up";
        case Failed f -> "Payment declined: " + f.errorMsg();
        case Pending p -> "Processing since " + p.initiatedAt();
    };
}
Why it matters: Java 21 Sealed Interfaces and Records provide exhaustive compile-time checking, replacing brittle boilerplate instanceof ladders.
Deep-Dive Architecture & Concepts

2. JVM Memory Layout & Garbage Collection Architecture

Senior Java candidates are expected to diagnose out-of-memory errors, GC pause spikes, and thread starvation in production.

JVM Memory Structure

Heap (Young Gen: Eden, Survivor S0/S1; Old/Tenured Gen), Metaspace (Class metadata, method bytecodes; resides in Native Memory), Thread Stacks (Stack frames, local primitives, method call references), Program Counter (PC) Register.

Garbage Collection Lifecycles

Minor GC cleans Eden and copies surviving objects between S0 and S1. After surviving threshold (default MaxTenuringThreshold=15), objects promote to Old Gen. Major/Full GC cleans Old Gen.

Modern GC Comparison (G1 vs ZGC)

G1GC divides heap into 2048 equal regions and targets predictable pause times (e.g. -XX:MaxGCPauseMillis=200). ZGC uses colored pointers and load barriers to achieve sub-millisecond pauses on terabyte heaps.

Interviewer Insights & Pro Tips
  • When asked about OutOfMemoryError, always distinguish between java.lang.OutOfMemoryError: Java heap space (heap exhaustion) vs Metaspace (class loader leak) vs unable to create new native thread (OS thread limit reached).
Deep-Dive Architecture & Concepts

3. Spring Boot 3, Dependency Injection & JPA Hibernate

Spring Boot eliminates XML configuration, but you must know what happens under the hood when @SpringBootApplication starts.

@SpringBootApplication Trio

Combines @Configuration, @EnableAutoConfiguration (scans META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports), and @ComponentScan.

Spring Bean Scope & Lifecycle

Default scope is Singleton. Lifecycle: Instantiate -> Populate Properties -> BeanNameAware / BeanFactoryAware -> BeanPostProcessor (BeforeInit) -> @PostConstruct -> InitializingBean -> BeanPostProcessor (AfterInit: Proxy wraps bean) -> Ready -> @PreDestroy.

Hibernate N+1 Query Problem

Occurs when loading N parent entities executes 1 query, and accessing each parent's @OneToMany child relationship triggers N additional queries. Fix using JOIN FETCH in JPQL or @EntityGraph.

Resolving Spring @Transactional Self-Invocation & Proxy Pitfall
java
@Service
public class OrderService {

    @Autowired
    private OrderRepository orderRepository;
    
    // Self-injection workaround or delegate to a dedicated collaborator
    @Autowired
    @Lazy
    private OrderService self;

    public void processBatch() {
        // Calling this.saveOrderInternal() DIRECTLY bypasses Spring's CGLIB proxy!
        // Incorrect: saveOrderInternal();
        
        // Correct: Call via proxy or separate helper service bean
        self.saveOrderInternal();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void saveOrderInternal() {
        // Executes within a clean, isolated physical database transaction
    }
}
Why it matters: Spring's transactional mechanism relies on AOP proxies. Self-invocation using 'this' bypasses the interceptor proxy, causing @Transactional to silently fail.
Real-World Interview Questions

Top Must-Know Interview Questions & Model Answers

Java 21 & ConcurrencyMust-Know

Q1: How do Java 21 Virtual Threads (Project Loom) differ from Reactive Programming (WebFlux)?

Executive Answer:Virtual threads allow writing sequential, readable blocking code that scales to millions of concurrent tasks on a tiny pool of carrier threads, whereas Reactive WebFlux uses complex async Monos/Fluxes with high cognitive overhead.
Deep Dive Analysis:
  • Platform threads map 1:1 to OS kernel threads, consuming ~1MB stack memory per thread. 10,000 platform threads exhaust OS limits.
  • Virtual threads are managed entirely by the JVM in user space, occupying ~few hundred bytes on heap and parking automatically on blocking I/O operations.
Interviewer Takeaway: For new I/O-bound microservices on Java 21, Spring Boot 3 with Virtual Threads is the recommended standard over WebFlux.
Core JavaMedium

Q2: Explain the contract between equals() and hashCode() and what happens if violated in a HashSet.

Executive Answer:If two objects are equal according to equals(), their hashCode() MUST return the same integer. If violated, HashSets and HashMaps cannot reliably find or deduplicate stored objects.
Deep Dive Analysis:
  • If hashCode() is not overridden, two objects with identical fields will generate different memory-based hashcodes, landing in different buckets.
  • A HashSet lookup will check the bucket hashcode first, fail to find the existing object, and insert a duplicate.
Interviewer Takeaway: Always use IDE generator or Java Record classes to implement both equals() and hashCode() simultaneously.
Databases & JPAHard

Q3: What are the different Isolation Levels in Database Transactions and what anomalies do they prevent?

Executive Answer:Read Uncommitted, Read Committed (Default in Postgres), Repeatable Read (Default in MySQL), and Serializable.
Deep Dive Analysis:
  • Dirty Read: Reading uncommitted changes made by another tx (Prevented by Read Committed).
  • Non-Repeatable Read: Reading the same row twice returns different values because another tx committed an update (Prevented by Repeatable Read).
  • Phantom Read: Re-executing a range query returns new rows inserted by another committed tx (Prevented by Serializable or MVCC snapshot isolation).
Interviewer Takeaway: Higher isolation levels increase locking contention and decrease transaction throughput.
Assessment Integration

Recommended Practice Quizzes on QuizCluster

Test your retention and prepare for timed live coding and MCQ technical screening rounds:

Frequently Asked Questions

Which Java version should I study for technical interviews?

Focus on Java 17 LTS and Java 21 LTS. Be ready to discuss Records, Sealed Classes, Pattern Matching, and Virtual Threads.

Is Spring Boot knowledge required for all Java interviews?

For enterprise, banking, and fintech backend roles, Spring Boot 3 is mandatory. For Big Tech (Google, Meta), algorithmic DSA and system design take precedence, but Java language depth is still heavily evaluated.

Explore Other Preparation Guides

Software Engineering
How to Prepare for SDE Interview: Complete 2026 Roadmap
16 min readRead →
Microservices & Distributed Systems
How to Prepare for Microservices Developer Interview: Distributed Architecture & Cloud
17 min readRead →
System Design
System Design Interview Guide: Complete 2026 Roadmap
21 min readRead →
Databases
SQL Interview Questions & Preparation Guide: Beginner to Advanced
17 min readRead →
Programming Languages
Python Interview Preparation: Complete Guide for 2026
17 min readRead →
Frontend Engineering
React Interview Preparation: React 19 & Next.js Guide
17 min readRead →
Cloud & DevOps
Kubernetes Interview Guide: Architecture, Pods, Networking & Troubleshooting
17 min readRead →
Cloud & DevOps
AWS Solutions Architect Interview Guide: Real Architecture Scenarios
17 min readRead →
Databases
Database System Design: SQL vs NoSQL, Sharding, Replication & Indexing
19 min readRead →
Microservices & Distributed Systems
Kafka Interview Guide: Architecture, Consumers, Partitions & Exactly-Once Semantics
17 min readRead →
Backend Engineering
REST API Design Interview Guide: Authentication, Pagination, Versioning & Rate Limiting
15 min readRead →
Cloud & DevOps
Docker Interview Guide: Images, Containers, Networking & Production Debugging
15 min readRead →
Programming Languages
JavaScript & TypeScript Interview Guide: From Closures to the Event Loop
17 min readRead →
Backend Engineering
Node.js Backend Interview Guide: Event Loop, Streams, APIs & Scaling
17 min readRead →
Databases
Redis System Design Guide: Caching, Eviction, Persistence & Distributed Locks
17 min readRead →
Software Engineering
Concurrency Interview Guide: Threads, Locks, Race Conditions & Deadlocks
17 min readRead →
Software Engineering
Dynamic Programming Patterns: How to Recognize and Solve DP Problems
17 min readRead →