TL;DR
Java 25 is the new LTS after Java 21 (Sept 16, 2025): compact source files, scoped values, smaller heap. What changed, what the move costs, and who should wait.
Java 25 became generally available on September 16, 2025, and it is the long-term support release that succeeds Java 21. It ships 18 JDK Enhancement Proposals (JEPs), twelve of them final. Oracle's published roadmap lists premier support through September 2030, and Java 26 and 27 are short-term releases, so Java 25 is the upgrade target for every team still on an LTS line. If you are on Java 21, this is a maintenance-window upgrade. If you are on Java 17 or older, it is a two-LTS jump that lands you records, sealed classes, pattern matching, virtual threads, and everything below in one move.
The short version: the language gets smaller and less ceremonial, the concurrency model gets a finalized replacement for ThreadLocal, and the runtime gets a smaller heap for free. Nothing in Java 25 forces a rewrite. The work is in the jump from your current version, not in the new features themselves. What follows is what is final, what is still preview, what the move from Java 21 actually gains you, and the decision written down so your team can argue with it.
What is final in Java 25
Seven features crossed the line to final in this release, and they split cleanly into language, libraries, and runtime.
Compact source files and instance main methods (JEP 512)
The ceremony around a small Java program is gone. A file with no class declaration and an instance main method is now a complete program:
// Hello.java — run it with: java Hello.java
void main() {
IO.println("Hello, Java 25");
}The new java.lang.IO class supplies print(), println(), and readln() without an import. This matters most for scripts, teaching, and the first file of a prototype. It changes nothing about how a production service is structured — do not rewrite your services as compact source files. The feature exists so that the smallest Java program is one file, not so that large programs lose their structure.
Flexible constructor bodies (JEP 513)
A constructor can now run code before super() or this(). The rule that the superclass call must be the first statement is relaxed, which finally lets you validate arguments before the parent constructor runs:
public class Order {
private final String id;
public Order(String id) {
if (id == null || id.isBlank()) {
throw new IllegalArgumentException("id is required");
}
super();
this.id = id;
}
}Before Java 25, the same validation had to live in a static helper called from the super(...) argument list, or in a factory method — both patterns that hid intent. The practical effect is small per class and large across a codebase: constructors can now fail fast with a readable message instead of letting an invalid value reach a superclass that throws something cryptic. The compiler still enforces the real invariants — you cannot read this or access instance fields before super() returns — so this is strictly more expressive, not less safe.
Module import declarations (JEP 511)
One statement now imports everything a module exports:
import module java.base;
void main() {
var names = List.of("ada", "grace");
IO.println(names);
}import module java.base replaces a dozen individual imports in a file that leans on the standard library. It is a readability feature, not a modularity feature: it does not change what your code can access, only how much import boilerplate sits at the top of the file. In a codebase that already uses explicit imports, the honest advice is to leave existing files alone and use module imports in new files where they genuinely cut noise.
Scoped values (JEP 506)
Scoped values are the finalized replacement for ThreadLocal when the data is immutable context — a request id, a tenant, the authenticated user — passed down a call chain and across threads:
private static final ScopedValue<String> TENANT = ScopedValue.newInstance();
void handleRequest(String tenantId) {
ScopedValue.where(TENANT, tenantId).run(() -> {
// Any method called from here, on this thread or a child
// virtual thread, can read TENANT.get()
processOrder();
});
}The difference from ThreadLocal is the guarantee: a scoped value is bound for a delimited scope, it is immutable while bound, and it cannot leak into a thread-pool thread that later serves a different request. That leak is exactly the bug ThreadLocal produces in server code — a value set for one request read by the next. Scoped values are designed to pair with virtual threads, where a thread per task makes ThreadLocal misuse both more likely and harder to spot. If your code passes context through method parameters today, keep doing that — scoped values are for context that would otherwise be threaded through every signature in the chain. If your code uses ThreadLocal for request context, Java 25 is the release to migrate it.
Key Derivation Function API (JEP 510)
Java 25 standardizes key derivation: PBKDF2, scrypt, Argon2, and HKDF behind one API instead of provider-specific incantations. If you hash passwords or derive encryption keys, this is the API to use for new code. It does not change the security advice — use Argon2id for password hashing, keep parameters current, never roll your own KDF — it just removes the excuse for reaching for a third-party library or a hand-rolled derivation.
The runtime: compact object headers and generational Shenandoah
Two performance features are final, and both are opt-in flags rather than behavior changes:
-XX:+UseCompactObjectHeaders and measure; the gain depends on how much of your heap is object headers versus payload.Ahead-of-time compilation also gets more ergonomic in this release (JEPs 514 and 515: AOT method profiling and command-line ergonomics), which shortens warm-up for services that restart often. Treat all three as measured wins: turn the flag on in staging, compare heap and startup numbers, and only then promote them.
The Java 21 to 25 jump: what you actually gain
Most teams upgrading to Java 25 are coming from Java 21, and the features that change daily coding arrived in the LTS releases between them — they are just new to you. Three are worth knowing by name.
Records and sealed classes
Records (final since Java 16) and sealed classes (final since Java 17, JEP 409) are the data-modelling pair. A record is a class that is its data, with equals, hashCode, and toString generated:
public record CardPayment(String cardLast4, Money amount) implements Payment { }A sealed interface says exactly which types may implement it, so the compiler can check that a switch over it is exhaustive:
public sealed interface Payment permits CardPayment, BankTransfer {
Money amount();
}Together they replace the two patterns Java code used for years: mutable DTOs with hand-written boilerplate, and open hierarchies where adding a case silently broke every switch. If your codebase still has Lombok @Data classes carrying payment or event payloads, records are the migration — less generated magic, and the shape is visible in the source.
Pattern matching for switch (final in Java 21)
Pattern matching for switch (JEP 441) turns a type test and a cast into one expression, and record patterns destructure in the same step:
String label = switch (payment) {
case CardPayment(var last4, var amount) -> "Card •••• " + last4;
case BankTransfer(var iban, var amount) -> "Transfer " + iban;
};The compiler verifies exhaustiveness against a sealed type, so adding a third payment method becomes a compile error at every switch instead of a runtime surprise. This is the feature that makes sealed classes pay off: the two were designed together.
Virtual threads (final in Java 21)
Virtual threads (JEP 444) are the concurrency change that matters most for server code. A virtual thread is cheap — thousands per process instead of hundreds — so the thread-per-request model works again without a pool sized by guesswork:
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (String url : urls) {
executor.submit(() -> fetch(url));
}
} // waits for all tasks, then closesThe code looks like the platform-thread code it replaces, and that is the point: blocking calls on a virtual thread do not block a carrier thread, so a service that spends its time waiting on databases and HTTP calls scales by writing straightforward blocking code. Our Spring Boot 4.2 guide covers how the framework wires this in — Boot 4.x needs Java 17 at minimum, and virtual threads are its recommended concurrency model for I/O-bound services.
The honest limit: virtual threads fix throughput for I/O-bound work. They do not make CPU-bound work faster, they do not fix a slow query, and they do not help if your bottleneck is a connection pool sized for platform threads — raise the pool or the threads will queue at the database instead of in your code. The companion pattern, structured concurrency, is still in preview (see below), so for now the try-with-resources executor above is the sanctioned shape.
What is still preview — do not build on it yet
Four features are in preview and one is in an incubator module. They are in the release so you can try them; they are not a stable foundation for production code.
instanceof and switch match on primitive types. Useful, and likely to finalize in a later release — but preview means the syntax can still change.final fields. Promising for configuration-heavy services; not yet something to depend on.The rule for previews is simple: a --enable-preview flag in a demo or a spike is fine; a preview feature in a service you will still be running in two years is a liability. The same applies to the one removal in this release: the 32-bit x86 port is gone (JEP 503), which affects almost nobody in 2026 but is worth a grep if you still ship 32-bit builds.
Upgrade paths, compared
| Your situation | Move | Effort | What you get first |
|---|---|---|---|
| Java 22–24 (short-term) | Move to 25 now | A version bump and a test run | A supported runtime — your line is already end-of-life |
| Java 21 LTS | Move on the next maintenance window | A version bump, a test run, then adopt features | Scoped values, compact source files, smaller heap |
| Java 17 LTS | Jump straight to 25 | Plan it as a sprint: APIs removed since 17, tooling versions | Records, sealed classes, virtual threads, all of 25 |
| Java 11 or 8 | Jump straight to 25 | A migration project, not a bump: modules, removed APIs, build plugins | Everything above, plus a supported line |
Two mechanical notes apply to every row. First, the compiler now writes class files with major version 69, so build tools, linters, and bytecode libraries must be current enough to read it — upgrade Maven, Gradle, and your static-analysis plugins in the same change. Second, run the full test suite on the new runtime before adopting any new language feature; the upgrade and the adoption are two separate changes and should be verified separately. Our creational patterns guide shows the Spring Boot side of the same discipline: framework features are adopted deliberately, not because a version number changed.
Recommendation
Move to Java 25 as your next LTS, on the timetable your current version dictates: now if you are on a short-term release, on the next maintenance window if you are on Java 21, as a planned sprint if you are on Java 17 or older. Adopt scoped values for request context and records plus sealed classes for new domain types as you touch code; leave the preview features alone until they finalize.
Architecture Decision
>
Decision: Standardize on Java 25 as the team's LTS runtime; adopt scoped values for request context and records/sealed classes for new domain types; do not adopt preview features.
>
Context: The team runs Java 21 in production with Spring Boot services, passes request context through method parameters or ThreadLocal, and models domain payloads as mutable classes. The next LTS is available with support through September 2030.
>
Options considered: (a) Move to Java 25 now and adopt the finalized features as code is touched. (b) Stay on Java 21 until its support window narrows. (c) Move to Java 25 and immediately adopt preview features (structured concurrency, stable values) for new services.
>
Why this one: Option (a) buys a supported line, a smaller heap, and a ThreadLocal replacement with no rewrite and no preview risk. Option (b) saves a version bump now and pays it later with interest, when the jump is two LTS versions instead of one. Option (c) bets production services on APIs that are explicitly allowed to change.
>
What it costs you: A version bump and a full test run; build-tool upgrades for class file version 69; a small learning cost for scoped values and record patterns; the discipline to leave preview features alone while they look attractive.
>
When to reverse it: If a library you depend on cannot run on Java 25, or if a measured regression appears in staging (heap, startup, or throughput), hold that service on Java 21 and revisit at the next patch release. The reversal trigger is a measured failure, not discomfort with the new syntax.
When NOT to upgrade yet
Do not move a service to Java 25 this week if it depends on a library that has not published a Java 25-compatible release — check the library's own compatibility statement first, and hold that service on Java 21 while the vendor catches up. Do not upgrade in the same change as a framework migration or a major refactor; the runtime move is one change, and it deserves its own verification. And do not adopt preview features because they solve a problem you have today — structured concurrency is the tempting one, and the sanctioned answer until it finalizes is the virtual-thread executor shown above. The LTS exists precisely so you do not have to chase every release; Java 25 is the release to land on, and landing on it calmly is the whole point.
For the bigger picture on how this runtime fits the framework on top of it, our modular monolith guide covers the architecture decision that most teams should settle before they argue about versions.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.