Hello everyone,
In the world of Java development, we have become accustomed to rapid change. Almost two decades have passed since the legendary article saying goodbye to Java 8, and the platform has continued to evolve. The monolithic release cycle is history. Instead, we get new features every six months that make our work more efficient, safer and more expressive.
Today we’ll dive deeper and take a look at what’s new with Java 24 and Java 25. While Java 24 paved the way with a host of improvements and preview features, Java 25 marks a significant milestone, bringing us some of the most anticipated features as final releases.
See also: Beyond Java 8 (Java 8 - 23)
Java 24: The Trailblazer
Java 24 was not a Long-Term Support (LTS) release, but it laid important foundations for the future. It was packed with preview features and improvements to the JVM that often go unnoticed in the background but increase performance and stability.
A highlight that was finalized in Java 24 is the Stream Gatherers (JEP 461). Previously, intermediate operations in Java streams such as map, filter or sorted were limited to a fixed list. With Gatherers we can now define our own intermediate steps.
Imagine you want to group elements into solid blocks or run a sliding window function without having to implement it on foot. With Stream Gatherers this is now possible out of the box.
var numbers = Stream.of(1, 2, 3, 4, 5, 6, 7);
var windows = numbers.gather(Gatherers.windowFixed(3))
.collect(Collectors.toList());
// Ergebnis: [[1, 2, 3], [4, 5, 6]]
In addition to this innovation, ongoing projects such as Structured Concurrency and Virtual Threads were also further advanced. This shows that Java is continually moving towards modern, concurrent programming.
Java 25: The big steps forward
But the real star of this article is Java 25. This release not only brings further improvements, but also the finalization of features that the community has been waiting for a long time.
1. Scoped Values (JEP 506)
This is a game-changer for concurrent programming. Scoped Values offer a high-performance and secure alternative to ThreadLocal. They allow immutable data to be shared across a chain of method calls without having to pass it as arguments.
The biggest advantage: Unlike ThreadLocal which can cause memory leaks, Scoped Values are clean and efficient. They are particularly powerful in combination with Virtual Threads (Project Loom), as they pass on the context per request (or task) cleanly and efficiently.
// Definition des Scoped Value
private static final ScopedValue<String> USER_ID = ScopedValue.newInstance();
// Wert binden und Methode ausfuehren
ScopedValue.where(USER_ID, "user-123")
.run(() -> processRequest());
public void processRequest() {
// Zugriff auf den Wert
System.out.println("Processing request for user: " + USER_ID.get());
}
2. Quick start with Ahead-of-Time Method Profiling (JEP 515)
The startup time and warm-up phase of Java applications has always been an issue. A quick start is crucial, especially in cloud-native and microservice architectures. Ahead-of-Time Method Profiling solves this problem by saving the JVM’s “learning behavior”.
After a training run, the JVM creates a profile of the most frequently executed methods. The next time it starts, the Just-In-Time (JIT) compiler uses this profile to immediately compile the code optimally. The result: The application reaches peak performance much faster, without the typical warm-up time.
3. Java for everyone: Compact Source Files (JEP 512)
Another big step is making it easier for Java beginners to get started. With Compact Source Files it is no longer necessary to declare a class or a public static void main(String[] args) method to write a simple “Hello World”.
// Vorher
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
// Neu in Java 25
System.out.println("Hello, World!");
This makes Java much more attractive as a first learning language and enables experienced developers to quickly write small scripts.
Java 24 and 25 in comparison: an overview
Here is a table that summarizes the key new features of Java 24 and Java 25.
| Feature (JEP) | Java 24 (Status) | Java 25 (Status) | What it does |
|---|---|---|---|
| Stream Gatherers (461) | Finalized | Finalized | Allows you to create your own intermediate operations in stream pipelines, e.g. B. for grouping elements in windows. |
| Structured Concurrency (499) | 4. Preview | 5. Preview | Simplifies error handling and canceling logically related tasks in different threads. |
| Scoped Values (506) | 4. Preview | Finalized | Offers a secure and performant alternative to ThreadLocal, ideal for virtual threads. |
| Flexible Constructor Bodies (492) | 3. Preview | 4. Preview | Allows statements before the super() or this() call in the constructor for more flexibility and security. |
| Compact Source Files (512) | 3. Preview | Finalized | Makes Java more beginner-friendly by eliminating the need for boilerplate code for simple programs. |
| Ahead-of-Time Profiling (515) | Experimental | Finalized | Improves JVM startup time and warm-up by saving and reusing execution profiles. |
| Primitive Types in Patterns (507) | 2. Preview | 3. Preview | Extends pattern matching to support primitive types, making code more compact and readable. |
Conclusion: Evolution continues
Java 24 and Java 25 show that the platform does not stand still. It has transformed from a sedate, monolithic giant into an agile, fast-moving ecosystem. The new features like ‘Stream Gatherers’, ‘Scoped Values’ and the simplified ‘Hello World’ are not just nice additions. They are strategic moves that make the language more relevant and competitive, both for developers and modern architectures.
Java’s journey is far from over. The work on Virtual Threads and Structured Concurrency continues, and we can’t wait to see what innovations the coming releases bring us. It’s the perfect time to dive into the new versions and benefit from the improvements.
![[EN] Java von 24 Bis 25](/images/Java24-25_BlogHeader.png)