Java 19: What is in it, and should you take notice?

What does it mean to have a non Long-Term-Support Java version, what is in Java 19 and why should we care? In this blog we will look at each of these questions.

05-10-2022
Bcorp Logo


To log or to log

Oracle released Java 19 on the 20th of September 2022. This version of Java is a non Long-Term-Support version, which means that it is only supported for six months – until Java 20 is released in March 20223. Even that version will only have a six-month self-life as it is another non Long-Term-Support version. You will have to wait for Java version 21 in September 2023 for the next Long Term Support (or LTS) version.

Great, but this may raise several questions what does it mean to have a non Long-Term-Support Java version, what is in Java 19 and why should we care about Java 19? In the remainder of this blog we will look at each of these questions.

    Long Term Support Versions

    In a previous blog we discussed in more detail the support strategy introduced by Oracle back in 2018. At that time Oracle indicated that it would release short term support versions and long-term support versions. The Long-term versions would be Java 8 (2014), Java 11 (2018), Java 17 (2021) and (in the future) 21. These versions would have support lasting years rather than months. The exact length of support depends on the version with Java 8 being supported until December 2039 and Java 11 only until September 2026. For more information on which Java versions are LTYS and the duration of this support see the Java SE Support Roadmap.

    Java 19: What is in it, and should you take notice?


    The non Long Term Support versions (or non-LTS) versions are intended to allow new features to be introduced into the language at a quicker rate and for previews (proposed new features which are still subject to change) to be made available publicly for feedback and to allow developers to try potential new concepts out for themselves.

    This means a non-LTS version of Java can be used to explore new and proposed changes to the language but should not be used by commercial organisations as the basis of their production applications or systems. This is partly because the support only lasts six months and partly because the preview features are subject to change. In effect a non-LTS version should be treated as a taster for the future LTS version; for Java 19 this means it is a taster for Java 21.

    Java 19: What is in it, and should you take notice?

      What is in Java 19?

      So, what does the Java 19 release comprise? The main features are:

      From this you can see that the majority of the elements in the release represent previews of new syntax or implementation details. The above provide links to the JEP (Java Enhancement Proposal documents) that describe in more detail the preview or change.

      Record Patterns is an extension to the Pattern Matching for instanceof formate introduced in Java 16. In this syntax it was possible to write:

      <b>public record </b>Coordinate(<b>int </b>x, <b>int </b>y) {}
      
      
      
      <b>public void </b>print(Object object) {
      
        <b>if </b>(object <b>instanceof </b>Coordinate position) {
      
          System.<b><i>out</i></b>.println(<b>"object coordinates are: x = " </b>+ position.x()
      
            + <b>", y = " </b>+ position.y());
      
        }
      
      }

      We could then use a new Coordinate record instance with the print method:

      Coordinate coord = <b>new </b>Coordinate(10, 15);
      
      <i>print</i>(coord);

      This has been refined so that we can extract the values of x and y directly, for example:

      <b>public void </b>print2(Object object) {
      
        <b>if </b>(object <b>instanceof </b>Coordinate(<b>int </b>x, <b>int </b>y)) {
      
          System.<b><i>out</i></b>.println(<b>"object is a coordinates are: x = " </b>+ x + <b>", y = " </b>+ y);
      
        }
      
      }

      Linux/RISC-V Port this is a port to support the open source Linux/RISC-V instruction set architecture.

      Foreign Function & Memory API is a replacement for the old Java Native Interface (or JNI). This newer API is designed to be easier to work with, less error prone and faster than JNI.

      Java 19: What is in it, and should you take notice?


      Virtual Threads preview relates to work carried out in Project Loom. As it is now part of Java 19 it is easier to explore virtual Threads. A Virtual Thread is a lot like a normal thread to the developer, however instead of mapping directly onto ab operating system thread, they are executed by a pool of carrier threads. This makes it possible to support a higher number of virtual threads using less operating system threads. This feature is likely to be of significant benefit to backend / service developers.

      Vector API relates to a new API for mathematical vector oriented computations (and has nothing to do with the Vector container class).

      Pattern Matching for Switch relate to pattern matching for the switch statement which has been under incubator or preview for some time (since Java 17 in fact). The latest version changes the syntax for the guard pattern so that a when key word can be used to represent the condition under which a case should be applied, for example:

      public class App {
      
        public static void main(String[] args) {
      
          String obj = "Hello World!";
      
          switch (obj) {
      
            case String s when s.length() > 3 -> System.out.println(s.toUpperCase());
      
            case String s -> System.out.println(s.toLowerCase());
      
          }
      
        }
      
      }

      Structured Concurrency provides an API for developing tasks and subtasks that can be executed in parallel and managed at the task and subtask level.

      A notable change that you won ;t find listed above relates to the standard our and standard error streams. The change in because from Java 19 the operating system’s defayult encoding will be used for printing to the System.out and System.err streams. This means that on Windows you might find that your output suddenly contains extra question marks instead of control characters. To fix this so that the output streams use the previous UTF-8 you can start your application using the VM options:

      -Dstdout.encoding=utf8 -Dstderr.encoding=utf8Why should you care about Java 19?
      

      Why should you care about Java 19?

      Given that above we have said that a commercial organisation should not rely on Java 19 for their production systems, why should you be interested in it? The short answer is that it introduces you to the new features introduced in Java 19 (and indeed Java 18 does something similar). The content of Java 20 is yet to be defined but the combination of what’s in Java 18, Java 19 and Java 20 will likely from the core changes between Java 17 (LTS) and Java 21 (LTS) support versions. Therefore, being aware of the languages changes that will be available ibn Java 21 for the next decade or so is a useful thing.

      Companies can then decide which LTS version of Java to use and what language features they are happy for their developers to work with.


      Would you like to know more?

      If you found this article interesting you might be interested in our Java Training Courses.

        Share this post on:

        We would love to hear from you

        Get in touch

        or call us on 020 3137 3920

        Get in touch