Java 14 new features
You can follow the latest updates in Java here: https://marmo.dev/java-versions-features
All the new features of every Java version: https://marmo.dev/java-versions-features
- Java 14 Enhancements official page: https://openjdk.java.net/projects/jdk/14/
Developer / language new features
These features are interesting for your daily basis activity.
Pattern matching for instanceof (Preview)
https://openjdk.java.net/jeps/305
Here you can find an extended explanation. The pattern matching should be implemented initially for
instanceof
, switch
could follow in future releases.
Java 11 example:
if (obj instanceof String) {
String s = (String) obj;
System.out.println(s);
}
In this code we can see a 'pattern':
-> test: obj instanceof String
-> conversion: (String) obj;
-> assignment: String s = (String) obj;
-> usage: System.out.println(s);
Another issue is the repetition of String
, it's used 3 times in this small example.
The pattern 'test -> conversion -> assignement -> usage' is a common pattern used by the developer.
With Java 14 we can simplify our code:
if (obj instanceof String obj) {
System.out.println(s);
}
If obj
is an instance of String
this is assigned to the String
object obj
.
You can find this feature already implemented in C#, Scala, Haskell
Records (Preview)
You can find a post with many details here: https://marmo.dev/java-records
Helpful NullPointerException
https://openjdk.java.net/jeps/358
Switch Expression
https://openjdk.java.net/jeps/361
Text Blocks (Second preview)
https://openjdk.java.net/jeps/368
Garbage collector
If you want to know more about Garbage colletors in the JDK you can see my presentation here: https://marmo.dev/garbage-collectors-intro
Z is coming to MacOS
https://openjdk.java.net/jeps/364. Z is already present as 'preview' feature for Linux 64-bit, now it is ported to MacOS and in future to Windows.
Z is the new powerful Garbage Collector developed by Oracle. This GC target Heaps until 1TB with pauses (stop-the-world) of max 10ms. Here you can find the details:
ZGC Wiki.
CMS (Concurrent Mark Sweep) removed
CMS is now removed from the sources, it was already deprecated in Java 9.
CMS has been replaced G1, if you didn't migrate yet it's really time to do it.
G1, Parallel and Shenandoah are currently your best alternatives.
Deprecate the ParallelScavenge + SerialOld GC Combination
https://openjdk.java.net/jeps/366
There is a lot going on in the GCs for Java. This combination has been replaced by Parallel GC and is not used frequently, for this reason will be deprecated.
Other improvements
- G1 performances: NUMA-Aware Memory Allocation for G1
Tools
Packaging (Incubator)
https://openjdk.java.net/jeps/343
JDK Flight Recorder: JFR Event Streaming
https://openjdk.java.net/jeps/349