Week 9 Review — Modern Java
Goal
This review checks whether I can say 17 vs 21, pick records vs classes, switch exhaustively on a sealed type, and refuse “virtual threads fix Hikari.”
Week 9 topics:
- Java versions and LTS for Boot 3/4
- Records in REST and config
- Sealed types and pattern matching
- Switch expressions and text blocks
- Virtual threads and pinning
1. Week 9 big picture
Boot 3 floor = Java 17 records, sealed, text blocks, switch expressions
I run LTS 21 (then 25) virtual threads, switch patterns, sequenced collections
CreateOrderRequest record → JSON body
PaymentResult sealed → exhaustive switch → HTTP status
Tomcat on virtual threads → still 10 Hikari connections
2. Core memory sentences
Boot 3’s floor is Java 17. I target an LTS (21, then 25).
17 is records and sealed. 21 is virtual threads and richer patterns.
Records for values and DTOs. Classes for entities and Spring beans.
sealednames every subtype.switchcan be exhaustive.
Seal results I own. Keep ports (repositories, gateways) open.
Arrow switch does not fall through. Expression switch must cover every case.
Text blocks are multiline strings, not templates.
Virtual threads make blocking cheap; they do not create extra database connections.
3. Speak these without notes
- “What Java version do you use?” (60 seconds)
- Why a JPA entity is not a record.
- Why
PaymentResultis sealed andPaymentGatewayis not. - Arrow switch vs fall-through.
- Virtual threads vs Hikari pool size.
4. Tiny code proofs
Proof A — exhaustive switch
Seal PaymentResult with three records. switch all three. Add a fourth permitted type and watch the compiler fail until you handle it.
Proof B — record copy
Record with a List component, no List.copyOf. Mutate the caller’s list; watch equals change. Fix with List.copyOf in the compact constructor.
Proof C — text block indent
Print a text block’s first character codes and confirm the common indent was stripped.
5. Common mix-ups from this week
| Mix-up | Clear line |
|---|---|
| Boot 3 on Java 8 | Floor is 17, jakarta.* |
Record @Entity | JPA needs a class |
Seal OrderRepository | Ports stay open |
default on sealed switch | Hides new cases |
| VTs replace Hikari sizing | They make exhaustion more visible |
6. Interview drill
- Java fundamentals: records vs JavaBeans vs Lombok
- Concurrency and JVM: virtual threads; process vs thread recap
- How to answer
7. The Java track is complete
I can enter the Spring book without a hidden language gap:
- Speak Week 1–9 memory sentences once.
- Drill the interview bank out loud.
- Start Book Week 1 Day 1 — What problem does Spring solve?
Keep the OrderService picture: interface, constructor injection, domain exceptions, DTO records, no mutable request fields, no parallel() inside @Transactional.
The curriculum is now fully written.