Java 25: the new LTS, explained for everyone
Java 25 is the new long-term support release. Here is what it actually changes, with code you can run, explained so a junior developer or a student can follow along.
TL;DR: Java 25 is the new long-term support release, and a careful one: no single headline, but a set of small improvements made permanent, including compact source files, scoped values, a key derivation API, compact object headers, and one-step ahead-of-time compilation.
Who this is for: Java 21 developers planning their next upgrade, and students starting a new project. What you will learn: Compact source files, module imports, flexible constructor bodies, scoped values, the KDF API, compact object headers, AOT compilation, and the features still in preview.
Java 25 is the new long-term support release, out September 16, 2025. It is the version I would pick for a new project today. This post shows what it actually changes, with code you can run. If you are a junior developer or a student, this is written for you.
1. Words to know#
If you are new to Java 25, this box is the whole vocabulary of the article. Come back to it whenever a word looks unfamiliar.
- LTS: Long-Term Support. A version that gets years of security fixes, instead of six months.
- JEP: JDK Enhancement Proposal. The numbered document that describes one Java feature.
- Final: a feature that is permanent and safe to use in production.
- Preview: a feature you can run, but it can still change, so do not use it in production.
- Incubator: a feature even earlier than preview, still experimental and likely to change.
- Compact source file: a Java file with no class declaration, for small programs. Save it and run it directly.
- Module import: one line,
import module java.base;, that imports every package a module exports. - Scoped value: an immutable value bound for one block of code, cleaned up automatically when the scope ends, and inherited by child threads.
- ThreadLocal: the older way to pass data along with a thread. It is mutable, you must clean it up yourself, and child threads do not see it.
- KDF: key derivation function. A standard way to turn a shared secret into an encryption key.
- Object header: the metadata stored before an object's fields. Java 25 can compress it from 12 bytes to 8.
- AOT: ahead-of-time compilation. Doing some of the JVM's warm-up work in advance and saving it in a cache, so the next start is faster.
- Flight Recorder: a low overhead profiler built into the JDK that records what your program was doing.
- Structured concurrency: a group of subtasks run inside a scope that waits for all of them and cancels the rest if one fails.
- Stable value: a holder you set exactly once, on first use, and then it behaves like a constant the JVM can optimize.
2. What "LTS" means, and why it matters#
Java ships a new version every six months, but most get only six months of support. Every two years, one version is marked Long-Term Support (LTS) and gets years of security fixes. Java 25 is the current LTS, with Premier Support until September 2030. The previous LTS was Java 21 (September 2023); the next will be Java 29 (September 2027). Java 26 and 27 are short-term releases. Teams that run production systems pick an LTS and stay on it.
A feature is final when it is permanent and safe to use. A preview feature is runnable but can still change, so do not use it in production. An incubator feature is even earlier. I label every preview and incubator feature below.
3. The big picture#
Java 25 has no single headline feature like records (Java 16) or virtual threads (Java 21). It is the release where several features previewed during Java 21 to 24 finally become permanent. If you are coming from Java 21, you are not learning a new language. You are picking up small improvements that make everyday code shorter, safer, and cheaper to run.
4. Compact source files and instance main methods (JEP 512)#
The most visible change. It answers the beginner's question: why do I need all that ceremony just to print one line?
Before (Java 21):
The old way: a class, a public static main, and an args array to print one line.
public class Hello {
public static void main(String[] args) { // key line: the ceremony a beginner has to learn first
System.out.println("Hello, Java 25");
}
}
After (Java 25):
The same program in Java 25: no class, no public static, no args.
void main() { // key line: the whole program starts here
IO.println("Hello, Java 25");
}
That is the whole program. Save it as Hello.java and run java Hello.java. A compact source file has no class declaration, and it implicitly imports java.base, so no import statements. An instance main method needs no public static and no String[] argument. And the new java.lang.IO class gives you println, print, and readln.
Reading input with the new IO class: one line to ask, one line to answer.
void main() {
String name = IO.readln("Your name: "); // key line: read a line straight from the console
IO.println("Hello, " + name);
IO.println("Welcome to Java 25.");
}
Use it for small programs, examples, scripts, tests, and teaching. A real application still needs classes, packages, and structure. The old form still works.
5. Module import declarations (JEP 511)#
Before, you imported each type by name. Now you can import a whole module in one line.
Before (Java 21):
The old way: one import line per type.
import java.util.List; // key line: a separate import for every type
import java.util.Map;
import java.nio.file.Path;
After (Java 25):
The same imports as one line: import the whole module.
import module java.base; // key line: one line imports the whole module
public class ModuleImportDemo {
public static void main(String[] args) {
List<String> names = List.of("Asha", "Ben", "Cleo");
Map<String, Integer> scores = Map.of("Asha", 90, "Ben", 85);
IO.println(names);
IO.println(scores);
}
}
import module java.base; imports every package the module exports, so List, Map, and IO are all available. Use it for small programs and scripts, especially with compact source files. If two modules export the same type name, add a single-type import for the one you want.
6. Flexible constructor bodies (JEP 513)#
Before, a constructor had to call super(...) first, before any of your own code. You could not validate an argument before the object was built, so a bad argument left a half-built object.
Now you can run statements before super(...), as long as they do not use this. Validate first, then build.
Before (Java 21): the check runs after super(), so a bad argument creates a half-built object.
The old way: the check runs after super(), so a bad argument leaves a half-built object.
public User(String name, int age) {
super(); // key line: super runs first, so the check comes too late
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("name must not be blank");
}
this.name = name;
this.age = age;
}
After (Java 25): the check runs first, and a bad input fails immediately.
The same constructor with the check first: a bad input fails before anything is built.
public class User {
private final String name;
private final int age;
public User(String name, int age) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException(
"name must not be blank");
}
if (age < 0) {
throw new IllegalArgumentException(
"age must not be negative");
}
super(); // key line: super runs only after the checks pass
this.name = name;
this.age = age;
}
}
You can also compute a value before super(), for example Math.max(0, x). You still cannot use this before super(), except to assign a field.
7. Scoped values (JEP 506)#
The most important feature for server code. It is the second half of Project Loom. Virtual threads made it cheap to have a thread per request. Scoped values make it safe to pass data along with that request.
Before (Java 21): ThreadLocal works, but you must remember to clean it up or the value leaks into the next request, it is mutable, and a child thread does not see the parent's value.
After (Java 25): a scoped value is immutable, cleaned up automatically when the scope ends, and inherited by child threads.
A scoped value bound for one block of code, then gone when the scope ends.
public class ScopedDemo {
private static final ScopedValue<String> USER =
ScopedValue.newInstance();
public static void main(String[] args) {
ScopedValue.where(USER, "asha").run(() -> { // key line: bind the value, run the code, unbind it after
greet();
});
IO.println("Outside: " + USER.orElse("nobody"));
}
static void greet() {
IO.println("Hello, " + USER.get());
}
}
ScopedValue.where(USER, "asha") binds the value, .run(...) runs code with it in place, and outside the scope the binding is gone. A virtual thread started inside the scope sees the same value, with nothing passed to it.
A virtual thread started inside the scope sees the same value, with nothing passed to it.
ScopedValue.where(USER, "asha").run(() -> {
Thread child = Thread.ofVirtual().start(
() -> IO.println("Child sees: " + USER.get())); // key line: the child reads the value without it being passed in
try {
child.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
Use it for request context with virtual threads: the current user, a correlation ID, a tenant ID, a deadline. If you were reaching for ThreadLocal, use a scoped value instead. It is immutable by design. Use orElse when the value might not be bound, because get() throws if nothing is bound.
8. Key derivation function API (JEP 510)#
Before, there was no standard KDF API in the JDK. For HKDF, the standard used by TLS 1.3, there was no public API at all. You used a third-party library or wrote the HMAC chaining by hand.
Now there is a standard API, javax.crypto.KDF, supporting HKDF with SHA-256, SHA-384, and SHA-512.
Deriving an AES key from a shared secret with the standard HKDF API.
import javax.crypto.KDF;
import javax.crypto.SecretKey;
import javax.crypto.spec.HKDFParameterSpec;
import java.util.HexFormat;
public class KdfDemo {
public static void main(String[] args) throws Exception {
byte[] secret = HexFormat.of().parseHex(
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
byte[] salt = HexFormat.of().parseHex(
"000102030405060708090a0b0c");
byte[] info = HexFormat.of().parseHex(
"f0f1f2f3f4f5f6f7f8f9");
KDF hkdf = KDF.getInstance("HKDF-SHA256");
HKDFParameterSpec params = HKDFParameterSpec.ofExtract()
.addIKM(secret)
.addSalt(salt)
.thenExpand(info, 32);
SecretKey key = hkdf.deriveKey("AES", params); // key line: the shared secret becomes an AES key here
IO.println(HexFormat.of().formatHex(key.getEncoded()));
}
}
addIKM adds the shared secret, addSalt adds a random salt, thenExpand(info, 32) derives 32 bytes for an AES-256 key. Change the info label and you get a different key for a different purpose. Use it when turning a shared secret into an encryption key. Do not use HKDF for passwords; use PBKDF2 instead, which is designed to make guessing expensive.
9. Compact object headers (JEP 519)#
Every object has a header of metadata before its fields. Before, that header was 12 bytes on a 64-bit JVM (8 for the mark word, 4 for the class pointer). Java 25 can compress it to 8 bytes (4 and 4). It is opt-in, with a flag. No code changes.
Before: 12-byte header, no flag.
After: 8-byte header, run with the flag.
The same program, run with the flag that shrinks every object header to 8 bytes.
java -XX:+UseCompactObjectHeaders ManyObjects.java // key line: the flag that turns compact headers on
Saving 4 bytes per object means a million objects save about 4 megabytes, just from the header. Use it for applications that create many small objects, especially in-memory caches and containers where memory is limited. Measure before and after, because the benefit depends on how small your objects are.
10. Generational Shenandoah (JEP 521)#
Shenandoah is a garbage collector designed for low pause times. It now has a generational mode, production in Java 25. Most objects die young, so the collector gathers the young ones often and cheaply, and the old ones rarely.
Run with generational Shenandoah, and log the collections to see the young generation collected often.
java -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc GcDemo.java // key line: generational mode plus a GC log
With -Xlog:gc you will see the young generation collected often and the old generation rarely. Use it for services where low pause times matter and you have many short-lived objects. If you use G1, the default, you do not need to switch. Measure pause times and throughput on your own workload before changing collectors.
11. Ahead-of-time compilation, in one step (JEP 514 and JEP 515)#
When a Java program starts, the JVM loads classes and compiles hot methods just in time. That warm-up takes time. AOT does some of that work in advance and saves it in a cache, so the next start is faster.
Before, creating that cache took several steps and commands. Java 25 makes it one step.
Before (Java 21): several commands to record, train, and assemble the cache.
After (Java 25): one command to create the cache, one to run with it.
One command creates the ahead-of-time cache.
java -XX:AOTCacheOutput=app.aot App.java // key line: this run writes the cache file
One command runs with the cache, so startup skips the warm-up.
java -XX:AOTCache=app.aot App.java // key line: this run reads the cache file
Java 25 also stores method profiling data in the same cache, so the JVM spends less time warming up. No separate flag needed. Use it for containerized services that start often, serverless functions, and command-line tools. If your service runs for hours, warm-up is a small fraction of its life and AOT will not change much. Rebuild the cache when you change the code or upgrade the JDK.
12. Better flight recording (JEP 518 and JEP 520)#
Java Flight Recorder (JFR) profiles a running application with very low overhead. Java 25 improves it in two ways: cooperative sampling gives more accurate, cheaper CPU-time profiling, and method timing gives finer detail on how long methods take.
Start a 60 second flight recording, then summarize it.
java -XX:StartFlightRecording:filename=app.jfr,duration=60s,settings=profile App.java // key line: the recording flag, the rest is your normal launch
Summarize the recording from the command line.
jfr summary app.jfr // key line: a quick summary without opening Mission Control
Open app.jfr in JDK Mission Control for the full picture. Use it when you need to understand what a production service is actually doing, instead of guessing. A slow endpoint, a memory leak, a blocked thread. Start a recording, reproduce the problem, and read the data.
13. The removal: 32-bit x86 is gone (JEP 503)#
Java 25 removes the 32-bit x86 port. If you run on a 64-bit machine, which almost everyone does, nothing changes. If you still have a 32-bit x86 system, you cannot run Java 25 on it. Stay on an older version or move to 64-bit hardware.
14. Still preview, so do not build on these yet#
Four features are still in preview, and one is still an incubator. Learn them, try them, do not use them in production. Every example below needs --enable-preview.
14.1. Primitive types in patterns (JEP 507, third preview)#
Pattern matching used to work only on objects. Now it works on primitives like int too, in instanceof and switch.
Pattern matching on a primitive: an int in a switch, with a guard for positives.
// Run with: java --enable-preview Main.java
static String describe(int value) {
return switch (value) {
case 0 -> "zero";
case int i when i > 0 -> "positive " + i; // key line: the guard narrows the binding to positives
case int i -> "negative " + i;
};
}
void main() {
IO.println(describe(0)); // zero
IO.println(describe(7)); // positive 7
IO.println(describe(-3)); // negative -3
}
case int i binds any int to i, and when i > 0 narrows it to positives.
14.2. Structured concurrency (JEP 505, fifth preview)#
A group of related tasks is treated as a single unit. Start them together, wait for them all, and if one fails the rest are cancelled.
The final form in Java 25: fork two subtasks, join them, fail fast if either failed.
// Run with: java --enable-preview Main.java
import java.util.concurrent.StructuredTaskScope;
void main() throws Exception {
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
var hello = scope.fork(() -> "hello");
var world = scope.fork(() -> "world");
scope.join().throwIfFailed(); // key line: wait for both, or throw if either failed
IO.println(hello.get() + " " + world.get());
}
}
fork() starts a subtask, join() waits for them all, throwIfFailed() throws if any failed. Use it when you fan out to several services and need all of them before you can answer.
14.3. Stable values (JEP 502, preview)#
A stable value is a holder you set exactly once, on first use, and then it behaves like a constant the JVM can optimize. Like a final field you are allowed to fill in late.
A value set exactly once, on first use, then cached like a constant.
// Run with: java --enable-preview Main.java
static final StableValue<String> GREETING = StableValue.of();
void main() {
String first = GREETING.orElseSet(() -> "hello, loaded once"); // key line: the supplier runs once, on first use
IO.println(first);
String second = GREETING.orElseSet(() -> "this never runs");
IO.println(second);
}
orElseSet() runs the supplier once to set the value, then returns the cached value. It is thread safe. Use it for an expensive object you only want to create on first use, without writing double-checked locking by hand.
14.4. PEM encodings of cryptographic objects (JEP 470, preview)#
PEM is the text format for keys and certificates, the one with -----BEGIN PUBLIC KEY----- lines. Before, you stripped the header lines and called Base64 and KeyFactory yourself. Now there is a standard encoder and decoder.
Encode a public key to PEM text, then decode it back and check it matches.
// Run with: java --enable-preview Main.java
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
void main() throws Exception {
KeyPair pair = KeyPairGenerator.getInstance("Ed25519").generateKeyPair();
String pem = PEMEncoder.of().encodeToString(pair.getPublic()); // key line: the key becomes PEM text here
IO.println(pem);
PublicKey back = PEMDecoder.of().decode(pem, PublicKey.class);
IO.println("Same key: " + back.equals(pair.getPublic()));
}
Use it when reading or writing keys and certificates in PEM format.
14.5. Vector API (JEP 508, eleventh incubator)#
The Vector API uses the CPU's vector instructions directly. Instead of adding numbers one at a time, you add a whole chunk at once, which can speed up numeric work a lot. It is still an incubator, and it may still change.
Add two arrays a whole chunk at a time, using the CPU's vector instructions.
// Run with: java --enable-preview --add-modules jdk.incubator.vector Main.java
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.VectorSpecies;
static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_PREFERRED;
void main() {
int n = SPECIES.length();
float[] a = new float[n];
float[] b = new float[n];
float[] out = new float[n];
for (int i = 0; i < n; i++) {
a[i] = i + 1;
b[i] = (i + 1) * 10;
}
FloatVector va = FloatVector.fromArray(SPECIES, a, 0);
FloatVector vb = FloatVector.fromArray(SPECIES, b, 0);
va.add(vb).intoArray(out, 0); // key line: one add for the whole chunk, not one per number
IO.println(java.util.Arrays.toString(out));
}
SPECIES_PREFERRED picks the best vector size for your CPU. Note the extra flag: incubator code needs --add-modules jdk.incubator.vector as well as --enable-preview. Use it for numeric loops over large arrays, like image processing or math.
The rule is simple. Final means use it. Preview and incubator mean learn it, try it, and wait.
15. What Java 25 picks up from 22, 23, and 24#
Java 25 also includes everything that became final in Java 22, 23, and 24. If you upgrade from Java 21, you get all of it too: stream gatherers (JEP 485) for custom stream operations, the Class-File API (JEP 484) for reading and writing class files, the Foreign Function and Memory API (JEP 454) for calling native code without JNI, and unnamed variables and patterns (JEP 456). Virtual threads no longer pin inside synchronized blocks (JEP 491), and the Security Manager is permanently disabled (JEP 486).
16. Should you upgrade?#
If you are on Java 21, yes, plan the upgrade. Java 25 is the new LTS, supported until September 2030. Most code that runs on Java 21 runs on Java 25 unchanged.
Run your test suite on Java 25 in a branch, fix what breaks, then adopt the features that solve a problem you actually have: scoped values where you use ThreadLocal with virtual threads, compact object headers if you hold many small objects, the AOT cache if your containers start slowly. You do not have to adopt everything at once.
If you are on Java 17 or older, the jump is bigger. If you are starting a new project, use Java 25.
17. Conclusion#
Java 25 is not a dramatic release. It is a careful one. It takes the ideas previewed over the last two years and makes them permanent: a simpler way to write a small program, a safer way to pass data between threads, a standard way to derive a key, less memory per object, faster startup, better profiling. And it removes the things that no longer earn their keep.
That is what a good LTS looks like. It does not ask you to rewrite your code. It gives you better tools for the code you are already writing, and it promises to support them for years.
If you take one thing from this post, take this: learn scoped values. Virtual threads changed how we write concurrent code, and scoped values are the other half of that change.
Try the examples above. Run them. Change them. Break them. That is how you learn a release, and Java 25 rewards the effort.
18. The series#
- Java 8: the release that changed Java forever
- Java 11: the LTS that made teams leave Java 8
- Java 17: the LTS that locked the language down
- Java 21: the LTS that made threads cheap
- Java 25: the new LTS, explained for everyone (this post)

