June 12, 2026 • 3 min read
Java 25 Playground
A hands-on tour of Java 25: flexible constructors, scoped values, and primitive patterns.
TL;DR
Java 25 LTS ships flexible constructor bodies, scoped values, module import declarations, and primitive types in patterns. Here's what each does.
- java
- java25
- jep
Series
- Part 1 · Why I'm Deepening My Java Skills in 2026
- Part 2 · How Java Ships: JEPs, CSR, and the 6-Month Train
- Part 3 · Java 25 Playground
Java 25 (LTS) shipped a few new features. Each demo below is compiled to WasmGC via GraalVM Web Image and runs in your browser. Hit Run to see it execute.
Flexible Constructor Bodies (JEP 513)
Before Java 25, the first statement in a constructor had to be super() or
this(). You couldn’t validate parameters before delegating to the parent.
JEP 513 lifts that restriction:
ChildClass(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("Name cannot be empty or null");
}
super(name);
}
Scoped Values (JEP 506)
ScopedValue is an immutable, scope-bound alternative to ThreadLocal. You bind a value for the duration of a block.
Virtual threads can have millions of concurrent scoped values
without the memory overhead of ThreadLocal.
Primitive Types in Patterns (JEP 507, Third Preview)
Pattern matching (instanceof, switch) now works with primitive types.
Java 25 On-Ramp (JEP 511 + 512)
Module import declarations, implicitly declared classes, and instance main methods. Combined, you can write small programs without the usual boilerplate.
Try It Yourself
The full lab (Maven project + WASM build pipeline) is in the repo:
git clone https://github.com/samir1498/java-learning
cd java-learning/versions/labs/java25-playground # Maven project
cd java-learning/wasm-demos # WASM build (GraalVM Web Image)
Or just hit Run above.