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

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.
Step-by-Step Study Plan
Follow this sequential roadmap designed to take you from core foundations to advanced architecture and mock interviews.
Language Internals & Collections Mastery
Hash collisions, equals/hashCode contract, String pool immutability, Generics type erasure, and Java 8-21 stream features.
- •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.
- •Always implement both equals() and hashCode() when creating custom Map keys.
- •Know the difference between fail-fast (ArrayList) and fail-safe (CopyOnWriteArrayList) iterators.
Thread Safety, Memory Model & Garbage Collection
ReentrantLock, Semaphore, CountDownLatch, CompletableFuture, JMM happens-before guarantees, Metaspace, and GC tuning.
- •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.
- •Avoid using raw synchronized blocks; master java.util.concurrent (ExecutorService, ThreadPoolExecutor).
- •Know common JVM flags: -Xms, -Xmx, -XX:+UseG1GC, -XX:+UseZGC.
Dependency Injection, AOP, JPA & Microservices
Spring Bean lifecycle, @Transactional rollback gotchas, N+1 query problem in Hibernate, and Spring Cloud / Kafka integration.
- •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.
- •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.
1. Core Java & Collection Internals (The Must-Knows)
Interviewers frequently probe your understanding of Java collections down to pointer operations and bucket allocation.
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.
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.
Strings are immutable for security, thread safety, and memory caching in the String Pool located in the Heap.
// 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();
};
}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.
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.
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.
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.
- 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).
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.
Combines @Configuration, @EnableAutoConfiguration (scans META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports), and @ComponentScan.
Default scope is Singleton. Lifecycle: Instantiate -> Populate Properties -> BeanNameAware / BeanFactoryAware -> BeanPostProcessor (BeforeInit) -> @PostConstruct -> InitializingBean -> BeanPostProcessor (AfterInit: Proxy wraps bean) -> Ready -> @PreDestroy.
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.
@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
}
}Top Must-Know Interview Questions & Model Answers
Q1: How do Java 21 Virtual Threads (Project Loom) differ from Reactive Programming (WebFlux)?
- •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.
Q2: Explain the contract between equals() and hashCode() and what happens if violated in a HashSet.
- •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.
Q3: What are the different Isolation Levels in Database Transactions and what anomalies do they prevent?
- •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).
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.