Week 9 Day 1 — Java Versions for Spring Boot
Goal
Today I want a version story I can say in an interview without guessing patch numbers.
Main questions:
- Which Java does Spring Boot 3 and 4 need?
- What is an LTS, and which ones matter?
- Which language features arrived where?
- What do I actually say when they ask “what Java version do you use?”
- What JVM bits are enough at this level?
1. Boot’s floor, not the ceiling
| Line | Java floor (typical) | What I run in 2026 |
|---|---|---|
| Spring Boot 3.x | 17 | 17 or 21 LTS; 21 if I want virtual threads |
| Spring Boot 3.2+ | 17 | Can set spring.threads.virtual.enabled on 21+ |
| Spring Boot 4.x | 17+ on the current line | Prefer the current LTS (21, then 25) |
I do not memorize every minor. I remember: Boot 3 made 17 the new 8. Jakarta EE 9+ (jakarta.*) came with that cut. I do not write javax.servlet in Boot 3/4.
Memory sentence:
Boot 3’s floor is Java 17. I target an LTS (21, then 25) and I can name what 21 added.
2. LTS vs feature releases
Oracle/OpenJDK ship a release every six months. LTS (17, 21, 25, …) is what production teams stay on for years. Feature releases (18–20, 22–24) are for trying APIs that may still be preview.
In interviews I name LTS. I mention a preview API (structured concurrency) only if I say it is preview.
Distributions: Eclipse Temurin, Amazon Corretto, BellSoft Liberica, Oracle JDK. For a Boot app I care that it is a current 21/25 TCK build, not the vendor logo.
3. Feature map I can recite
| Java | What I actually use in backend code |
|---|---|
| 8 | Lambdas, streams, Optional (Weeks 5–7). Still the mental baseline interviewers grew up on. |
| 11 | var (locals only), HTTP client, Predicate.not |
| 17 | Records, sealed classes, text blocks, pattern matching instanceof, switch expressions |
| 21 | Virtual threads, sequenced collections, pattern matching for switch, record patterns |
| 25 | Current LTS after 21 — I check release notes; I do not fake APIs |
Week 9 is 17 + 21. That is the Boot 3/4 conversation.
var is local-variable inference. I do not use it for fields or API types. var order = service.get(id) is fine when the right-hand side is obvious.
4. The spoken answer (60 seconds)
We run Java 21 LTS in production on Spring Boot 3. The framework floor is 17, which is why I still know records and sealed types from 17. I would not start a new Boot 3 service on 8 or 11. Virtual threads are a 21 feature; Boot can run Tomcat on them if we turn that on, with the connection-pool caveat. I read 25 as the next LTS when we plan the jump.
If the company is still on 17: I say 17 is supported and enough for records/sealed, and I know what we would gain on 21.
I do not say “I use whatever IntelliJ defaults to.”
5. JVM enough for this week
- G1 is the default GC on current LTS HotSpot for server heaps. I tune heap size and allocation rate before exotic flags.
- Stack vs heap: Week 1. I can still draw it.
- I do not claim to be a GC engineer. I say: heap dump, allocation flame graph, then flags.
Day 5 is virtual threads. GC details stay in the concurrency/JVM interview page.
6. Spring connection
- Compiler level in Maven/Gradle:
java.version=21(or 17). Do not compile 21 bytecode and run 17. jakarta.*packages on Boot 3/4.- Test on the same LTS as production. “It worked on 22 preview locally” is not a release.
7. Common traps
Trap 1: “Spring Boot 3 runs on Java 8.” It does not.
Trap 2: Using a non-LTS in production with no upgrade plan.
Trap 3: Compiling with 21, deploying to 17.
Trap 4: Listing every JEPs. Interviewers want 17 records and 21 virtual threads, not a changelog.
Trap 5: var on a public API type.
Practice Questions and Answers
Question 1
What Java version do you use with Spring Boot?
Answer:
Boot 3 requires 17. I prefer 21 LTS in production so I have virtual threads and the 21 library ecosystem. Boot 4 stays on that LTS line. I can work on 17; I would not start a new 3.x service below 17.
Question 2
Why did Boot 3 drop Java 8?
Answer:
Java 17 is the LTS that unlocked records, sealed types, and a supported baseline, and the framework moved to Jakarta EE 9+ (jakarta.*). Staying on 8 meant missing language and namespace changes the stack standardized on.
Question 3
LTS vs a six-month release?
Answer:
LTS is what we run for years (17, 21, 25). Six-month releases are for trying features, often still preview. Production defaults to LTS unless the team has a stated reason.
Question 4
Which features do I name for 17 vs 21?
Answer:
17: records, sealed classes, text blocks, instanceof pattern matching, switch expressions. 21: virtual threads, pattern matching in switch, record patterns, sequenced collections.
Question 5
Can I compile on 21 and run on 17?
Answer:
Not if the bytecode version is 21. --release 17 (or a 17 toolchain) is required to run on 17. Mixing versions is a class-file error at startup, not a warning.
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.
Say the LTS you run. Do not recite the whole changelog.