
Java 25 was released today as the latest Long Term Support (LTS) version of the language, meaning it will be supported by Oracle for at least eight more years.
Oracle releases a new LTS version of Java every two years, and the previous LTS release was Java 21, back in 2023. “If you look back from 21 to 25, and all the things that have come in 22, 23, and 24, then I believe 25 definitely could be one of the first versions where people are looking at it and going ‘I can’t not get to 25, I can’t stay back,’” said Chad Arimura, VP of Java Developer Relations at Oracle.
New language features
This release introduces several stable language features, including module import declarations, compact source files and instance main methods, and flexible constructor bodies.
Module import declarations allow developers to import all of the packages exported by a module, without that module needing to contain importing code. This functionality will make it easier for developers to reuse libraries, and also helps newer Java developers use third-party libraries and Java classes without needing to learn where they exist in a package hierarchy.
Compact source files and instance main methods allow students to write smaller programs without first needing to learn about language features designed for large codebases. “This has been previewed three or four times, and it’s going as a final feature now,” said Arimura. “It’s all about making the language more concise for new learners and students and people who want to write scripts in Java.”
Flexible constructor bodies allow input validations and safe computations to be done without invoking a constructor. According to Oracle, this change will enable constructors to be expressed more naturally, and also allows fields to be initialized before becoming visible to other code in the class.
This release also includes the third preview of primitive types in Patterns, instanceof, and switch, which aims to make Java more uniform and expressive. No changes have been made since the second preview in JDK 24. “There was kind of this gap where you couldn’t use primitives and switch expressions to switch across, and now you can and it’s much cleaner,” said Arimura. “You can do some pretty cool stuff, like safe type casting and checking to see whether you can take primitives and cast them into other types of primitives without any lossiness to the value.”
Library features
Scoped values is now stable, allowing immutable data to be shared within and across threads. This improves ease-of-use, comprehensibility, performance, and robustness, particularly for applications that are using AI platforms, web frames, and microservices.
Structured concurrency is now in its fifth preview, and it treats groups of related tasks in different threads as a single unit of work, which helps reduce risks that come out of cancellation and shutdown.
There is also a preview of an API for stable values, or objects that hold immutable data. Stable values are treated as constants by the JVM, so they allow for the same performance optimizations as declaring a field final and offer more flexibility over when they are initialized.
Finally, this release will see the tenth incubator of the vector API, which expresses vector computations that compile at runtime as optimal vector instructions on supported CPU architectures.
Miscellaneous updates
Java 25 also features several updates across security libraries, performance, and monitoring.
For security, there is a new API for key derivation functions and a preview of a new API for encoding objects.
Performance updates include compact object headers, ahead-of-time command-line ergonomics, and ahead-of-time method profiling. “You can profile your application, create a cache, fire up your application, and not have to preload and do all the JIT and everything. It actually preloads bytecode right in and that makes it faster to get your application up and running,” Arimura explained.
Several improvements were also made to the JDK Flight Recorder (JFR), such as more accurate CPU-time profiling information, cooperative sampling of thread stacks, and functions for method timing and tracing.