More than 10 JEPs in the new version of Java š¤Æ
Java 22 was released on March 19th, but this you already know, right? But, are you aware that this new release contains over 10 JEPs?
I wonāt go into all of them, since some are finalized features from previous versions or in their second preview phase. I want to talk only about 3 of them, JEP 423, 447 and 461. However, if you want to go deep into each one of them, this is the list:
- 423:Region Pinning for G1
- 447:Statements before super(ā¦) (Preview)
- 454:Foreign Function & Memory API
- 456:Unnamed Variables & Patterns
- 457:Class-File API (Preview)
- 458:Launch Multi-File Source-Code Programs
- 459:String Templates (Second Preview)
- 460:Vector API (Seventh Incubator)
- 461:Stream Gatherers (Preview)
- 462:Structured Concurrency (Second Preview)
- 463:Implicitly Declared Classes and Instance Main Methods (Second Preview)
- 464:Scoped Values (Second Preview)
JEP 423: Region Pinning for G1
G1 has been the default GC since Java 9 by the JEP 248, and since then, we have had many other GCs, ZGC, Shenandoah, and others, however, the G1 has kept improving, as we can see with this new feature.
This new feature will help the G1 to reduce the latency by implementing region pinning.
The goals for this new feature are:
- No stalling of threads due to JNI critical regions.
- No additional latency to start a garbage collection due to JNI critical regions.
- No regressions in GC pause times when no JNI critical regions are active.
- Minimal regressions in GC pause times when JNI critical regions are active.
JEP 461: Stream Gatherers (Preview)
The Stream API now includes a new feature that allows custom intermediate operations to be supported.
The goals of the Stream Gatherers are:
- Make stream pipelines more flexible and expressive.
- Insofar as possible, allow custom intermediate operations to manipulate streams of infinite size.
Now we have a new method called gather() that receives a new Functional Interface called Gatherer
Example:
public List getMaxSumOfConsecutiveElements(List values, Integer windowSize) {
return values
.stream()
.gather(Gatherers.windowSliding(windowSize))
.max(getMax())
.orElse(null);
}
JEP 447: Statements before super(ā¦) (Preview)
Have you ever tried to add something before the super? Well, until now, this doesnāt work, but with Java 22, you can do that.
These are the goals of this new feature:
- Give developers greater freedom to express the behavior of constructors, enabling the more natural placement of logic that currently must be factored into auxiliary static methods, auxiliary intermediate constructors, or constructor arguments.
- Preserve the existing guarantee that constructors run in top-down order during class instantiation, ensuring that code in a subclass constructor cannot interfere with superclass instantiation.
- Do not require any changes to the Java Virtual Machine. This Java language feature relies only on the current ability of the JVM to verify and execute code that appears before explicit constructor invocations within constructors.
Example:
public PositiveBigInteger(long value) {
if (value <= 0)
throw new IllegalArgumentException("non-positive value");
super(value);
}
It is not possible to add all kinds of things before the super, there are some rules, and remember, with great power comes great responsibility.
Conclusion
These are only some new features added in the new version of Java, and this shows how Java has kept improving and enhancing the developersā activities.
Knowing these new features is essential to achieve better performance and productivity.
Java 23 is being developed and already has an associated JEP. If you want to keep updated, subscribe to the newsletter, itās free š
Subscribe
PS: If you want to access the code shared here, it is available for free here: https://github.com/ThiagoBfim/java-news