2. JDK 26 Preview Notes
JDK 26 is the latest feature release of Java. This book uses JDK 25 LTS as the main baseline, so JDK 26-only features belong in a clearly marked preview section.
Use preview features deliberately. They require explicit compiler and launcher flags, and their syntax or API can still change before finalization.
javac --release 26 --enable-preview Example.java
java --enable-preview Example
2.1. Primitive patterns
JDK 26 previews primitive types in patterns, instanceof, and switch.
This makes pattern matching more uniform across reference and primitive values.
It can also check whether a value fits exactly into a narrower primitive type
before binding it.
String statusMessage(int status) {
return switch (status) {
case 0 -> "okay";
case 1 -> "warning";
case 2 -> "error";
case int code when code > 2 -> "unknown status: " + code;
};
}
void printIfByte(int value) {
if (value instanceof byte b) {
IO.println("fits in a byte: " + b);
} else {
IO.println("too large for byte");
}
}
Because this is preview syntax, do not use it in the core examples. The standard
JDK 25 way to write the same beginner-friendly code is still a normal
default branch.
2.2. HTTP/3
JDK 26 adds HTTP/3 support to the HTTP Client API. Most beginner code still
starts with HttpClient, HttpRequest, and HttpResponse; the new
protocol support mainly matters when an application talks to HTTP/3 servers.
2.3. Structured concurrency
Structured concurrency is preview in JDK 26. It is important for the future of Java concurrency, but this book should teach stable virtual threads first. Preview structured-concurrency examples can be added later when the API is final.
2.4. Migration notes
When moving code from JDK 25 to JDK 26, watch for these areas:
Preview code must be rechecked against the exact JDK 26 syntax.
HTTP Client behavior changed in a few edge cases.
The Applet API was removed.
Deep reflection that mutates
finalfields now emits warnings to prepare for future restrictions.