Zum Hauptinhalt springen

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:

  1. Java versions and LTS for Boot 3/4
  2. Records in REST and config
  3. Sealed types and pattern matching
  4. Switch expressions and text blocks
  5. 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.

sealed names every subtype. switch can 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

  1. “What Java version do you use?” (60 seconds)
  2. Why a JPA entity is not a record.
  3. Why PaymentResult is sealed and PaymentGateway is not.
  4. Arrow switch vs fall-through.
  5. 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-upClear line
Boot 3 on Java 8Floor is 17, jakarta.*
Record @EntityJPA needs a class
Seal OrderRepositoryPorts stay open
default on sealed switchHides new cases
VTs replace Hikari sizingThey make exhaustion more visible

6. Interview drill


7. The Java track is complete

I can enter the Spring book without a hidden language gap:

  1. Speak Week 1–9 memory sentences once.
  2. Drill the interview bank out loud.
  3. 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.