Java 15

Updated:

To know what's included in this release: https://marmo.dev/java/15

How to test the preview features: [https://marmo.dev/java-test-preview-features](How to test preview features)

In 2 minutes

Java 15 is not a Long Term Support version and will be supported until 16th March 2021 (estimated date). There are a lot of preview features and some cleanup.

The main impact for the developers is the introduction of Text Blocs.

For DevOps it's very important the introduction of 2 new Garbage Collectors: Shenandoah and Z.
If you have big applications in the cloud that require a lot of RAM and processing, the new GCs are worth a try that could save you money.

Features that could change your daily work!

Text Blocks (Production)

Text blocks were initially planned for Java 12 but this feature generated a lot of debates inside the Java Community and it's introduction has been postponed.
After being in preview in JDK 13 and 14 it's the Prime Time for Text Blocks.
It's now an official feature of Java.

A nice ;) post here, with examples: Text Blocks examples

Official JEP 378
Oracle's Programmer's Guide to Text Blocks

In few words Text blocks support multi-line string through a new delimiter """.

Here an example:

String java14 = "I like this Blog.\nIt show me some examples\nin Java and Angular!"; 
 
String java15 = """ 
        I like this Blog. 
        It show me some examples 
        in Java and Angular!"""; 
 
java14.equals(java15) // => true 

In its current state this feature is pretty limited compared to string literals offered by other languages.

ZGC: A Scalable Low-Latency Garbage Collector (Production)

The new shiny Garbage Collector of Oracle goes in production. You can give it a try using -XX:+UseZGC.

Big competitor in this space is Shenandoah developed by RedHat.

The default garbage collector is still G1 (since Java 9).

If you want to learn more about Garbage Collectors you can find a 10 minutes intro here: marmo.dev GC

Official JEP 377

Shenandoah: A Low-Pause-Time Garbage Collector (Production)

The new super powerful GC developed by RedHat. You can give it a try using -XX:+UseShenandoahGC.

You can find on InfoQ an interesting interview with Shenandoah's RedHat Team: Shenandoah in JDK 11 - Interview with Red Hat's Team

For your info: if you want to use Shenandoah in production without waiting for Java 15, you can already it from JDK 8 if you are using a RedHat distribution (RH Linux, OpenShift).

If you want to learn more about Garbage Collectors you can find a 10 minutes intro here: marmo.dev GC

Features that will impact your development but are not ready yet!

Sealed classes (Preview)

Quick intro and example:
https://marmo.dev/java-sealed-classes.

Official JEP 360

The documentation of Oracle is pretty good, you can find it here:
Java SE Language Updates - Sealed classes

For a deep dive you can read this document of Brian Goetz:
Data Classes and Sealed Types for Java

Pattern Matching for instanceof (Second Preview)

Official JEP 375

For a deep dive you can read this document of Brian Goetz:
Pattern Matching for Java

Oracle [documentation and examples] (https://docs.oracle.com/en/java/javase/15/language/pattern-matching-instanceof-operator.html)

Records (Second Preview)

Excellent ;-) quick intro: Java Records

Official JEP 384

From the official JEP:

Enhance the Java programming language with records, which are classes that act as transparent carriers for immutable data. Records can be thought of as nominal tuples.

Oracle documentation

Changes that probably won't impact your work

Install Java 15 using SDKMAN!

To quickly install Java releases and switch between them I use SDKMAN!, you can see more details here: https://marmo.dev/java-angular-setup.

We are going to install AdoptOpenJDK, this JDK is free and supported by the community (RedHat).

For Java 15 you can execute the following command:

sdk install java 15.0.1.hs-adpt 

Here the video of the installation:


Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).