The new and highly anticipated version of one of the world's most popular programming languages is finally here, bringing with it a series of changes and improvements worth exploring. From performance enhancements to changes in the core structure of code syntax, Java 25 marks a turning point in how developers will use this long-established language, which has been a part of the computing world since 1995.
The following lines will discuss all the important features it offers, both at the platform and development levels, focusing primarily on the latter. But before delving into all the improvements this new version brings, it's worth remembering that Java has undergone a progressive and constant transformation in recent years. It has adapted its platform to offer more expressive, secure, and modern programming, with Java 25 being the most recent addition, although there are a number of important versions that have gradually transformed Java into the renowned language it is today.
The evolution of the language: from Java 17 to Java 25
To trace the evolution up to Java 25, one can start with Java 17, since this is the version considered the modern foundation of the language, where its changes stabilized what was introduced in previous versions, as well as laying the groundwork for the improvements seen in Java 21 and in this new Java 25.
The new starting point: Java 17
One of the language's major improvements was the formal addition of Sealed Classes , which allowed both these classes and existing interfaces to restrict which other classes or interfaces could extend or implement them. This effectively provided better control over inheritance in the code, improving security and hierarchical control. Another significant change to its syntax was the use of Pattern Matching for switch-type conditional structures. This enabled the direct use of patterns and conditionals, resulting in more concise, clean, and easier-to-understand code.
Regarding performance and platform improvements, this version finally introduced official support for macOS on ARM architectures, as well as a new rendering pipeline for the same operating system, which improved performance on compatible machines. In addition, improvements were made to the Random Generators, adding a new API with the RandomGenerator interface, enhancing the ability to swap between algorithms and supporting stream-based operations, among other things.
Also, as is common, some improvements were made to the security and cleanliness of the code with things like deserialization filters, responsible for improving security when deserializing objects (reconstructing an object to its previous state), or the strong encapsulation of internals (which are the internal classes of the JDK itself), improving security and maintainability by only allowing access to those Java APIs that are public.
All of this marked the beginning of the cleaning and modernization of the language, focusing on security, consistency, and performance.
Improving on what's already been established: Java 21
Continuing with the improvements during the evolution of the Java language, we must mention Record Patterns, a system that allowed for the direct extraction of components without the need for complex code. Another significant addition to its syntax was the extension of Pattern Matching (which already existed in Java 17) to switch statements, thus allowing, with less code, the comparison of not only constant values, but also types, specific object fields, validations, and sealed classes. Also noteworthy are Unnamed Patterns and Variables , which represent a new type of unnamed variable and pattern, preventing the compiler from issuing an error message if they are not used, thereby reducing code complexity. Similar to Unnamed Patterns, Unnamed Classes were added, and the main method was simplified. This feature is one of several designed to create a smoother learning curve for the language and provide an easy entry point for new developers, specifically by establishing a simplified class creation process.
In terms of performance, another improvement related to simplifying and facilitating the language is worth highlighting. Scoped Values were introduced, used to share immutable data between threads in a more controlled manner and with a specific scope, thus creating an alternative to ThreadLocal. Improvements were also added to collection handling with Sequenced Collectors , allowing the use of new methods to access the logical order (first position, last, etc.) in a unified way and without the need for manual indexes or iterators. But without a doubt, the most noteworthy feature in this section is Virtual Threads: probably the most important addition in Java 21. They solve the main problem of using threads in Java, as they were costly because each one was tied to an operating system thread. Thanks to this improvement, threads are managed by the JVM (Java Virtual Machine), making them lighter, cheaper, and more scalable than in previous versions.
Further changes were made to security and the environment. Features such as the Key Encapsulation Mechanism (KEY), a standard API for key encapsulation mechanisms, were added, improving the security of key exchange. Preparations were also made to disable dynamic agent loading (which involves components used to modify or monitor application behavior). Because dynamic agents are dangerous and difficult to control, Java 21 warned against their use, paving the way for a future where their use will be permanently prohibited.
This version also made significant changes regarding interoperability and efficiency, creating Foreign Function & Memory, an improvement in Java's evolutionary line around Pattern Matching, providing an API for Java to interact with native code (from other languages such as C) and with memory outside the heap; the Vector API, which would allow directly extracting components from a record within a pattern without needing to name the entire record, improving the code by making it more precise and thus helping in the creation of generic code; or the Generational ZGC, which introduces a new API to be able to handle .class files (at runtime) natively and safely.
This summarizes the main features of Java 21 which, closing the cycle started by Java 17, eliminated historical limitations of the language, introduced new concurrency paradigms with virtual threads and simplified the code without sacrificing robustness.
A simpler, more powerful, and more modern Java
And now, building on the foundation laid in Java 17 and incorporating all the improvements, additions, and optimizations made in subsequent versions, we have Java 25. This version doesn't aim to reinvent the language, but rather to refine it. Its goal is to consolidate the efficiency of the various APIs and improve the experience for both new developers and to prepare the ground for what lies ahead: cloud environments and AI.
The following will list the most important improvements (both those released in this version and those that are previews, features not yet confirmed as permanent) with regard to programming, accompanied by small practical examples:
Primitive Type in Patterns (Preview):
There's another improvement to Pattern Matching, specifically regarding primitive types (such as int, double, boolean, etc.). It will now allow for cleaner switch statements and checks without manual conversions, improving the readability of conditional logic.
Checking in Java 21, less readable and simple
New way in Java 25 with improved Pattern Matching
Module Import Declarations:
Continuing with the simplifications, Java will now allow importing entire modules, without the need for multiple import statements.
Import method in Java 21, more tedious and lengthy
Figure 1: New way in Java 25 that reduces space by allowing the import of entire modules
Compact Source Files & Instance Main Methods:
Another simplification will allow for the creation of more compact source files by defining main methods directly in instances. This will be especially useful in education, where short scripts are more common.
Basic main method in Java 21 with the most important syntax to keep in mind
New, more compact method in Java 25
Flexible Constructor Bodies:
Previously Java did not allow code to be executed before calling super() or this(), but after this change it will be allowed, helping with flexibility and pre-configuration.
Need in Java 21 to call super() in advance
New Java 25 syntax more permissive with order
Structured Concurrency (Preview):
Extending the important initial work created with Java 21's Virtual Threads, it will now be possible to handle groups of concurrent tasks with a single logical unit, including error handling and cancellation.
How concurrency was handled in Java 21, in a more manual way
In Java 25 we can group subtasks into scopes to control their entire lifecycle
Scoped Values:
Another addition that will improve thread usage is a replacement for ThreadLocal, which will help share values between different threads safely and in a controlled manner, preventing memory leaks. In short, it's Java's way of adapting context usage to the modern concurrency model that came with virtual threads, for which Java wasn't yet fully prepared.
Example of its use in Java 21
In Java 25 we can group subtasks into scopes to control their entire lifecycle
Java 25 makes management easier and also more secure
Furthermore, there is no longer any need to worry about the problems associated with using thread poolers together.
with ThreadLocal, since from now on it can also be replaced by Scoped Values in these
cases, ensuring the use of data in a temporary, clean and secure manner:
Using Scoped Values instead of ThreadLocal in a Thread Pool operation
Vector API:
This addition will improve the vector API for parallel CPU-level operations, optimizing its calculations (mathematical, graphics, AI…), which will help high-performance applications or numerical analysis.
Normal loop in Java 21 without computational optimization
Using the new API in Java 25 to perform addition in parallel and with native SIMD instructions
Key Derivation Function API:
This new standard API is introduced, which will be responsible for deriving cryptographic keys securely, thus allowing them to be managed without the need for external libraries.
Use of external APIs for key derivation functions
Use of the new, more secure, direct, and explicit Java 25 standard API
Compact Object Headers:
The size of object headers in memory will be reduced from 12/16 to 8 bytes, improving efficiency and being especially noticeable in applications with millions of instances, where we can see a reduction of approximately 30% in CPU usage.
Ahead-of-Time Optimizations:
It will be easier to create ahead-of-time caches, caches generated at compile time or pre-run that save time when running Java applications. This optimization will allow for faster startup, which can be especially important in microservices or environments where time is a priority.
These are, in broad strokes, the new features that the recent Java 25 presents for developers, where you can clearly see how they have based their progress on simplicity, cleanliness and ease of use for both new learners of the language and its most veteran defenders.
Java 25 is not just another version. It's confirmation that the language has adapted without betraying its essence. After almost three decades, it remains a vibrant, reliable, and constantly evolving platform.
Rubén Gadea
Software Technician
ALTIA