The Future of Java: Most Awaited Features

19/03/2021 · 5 min read

Java’s latest development kit will arrive in less than a month, reaching version 16, but thanks to Oracle’s not-so-recently introduced release cadence, version 17 is also on the horizon.

This is especially interesting since Java 17 will be the next LTS (long-term support) version of Java, thus retiring Java 11 from its position.

For the past few years, Oracle has seemed committed to closing the backlog that Java has been collecting since version 8 – mostly due to backward compatibility guarantees. The clearest example of this is the reconsidered version update cadence, which is why a new JDK arrives every six months.

Of course, frequent updates alone would still be worth almost next to nothing, especially if Oracle were unable to fill them with real content. However, these packages also include many add-ons that developers have been missing for a long time.

These innovations fall under four major projects (Amber, Panama, Loom and Valhalla) which are to be completed during the course of next few years, with the promise of ensuring that Java would regain its modern image.

Project Panama

Panama promises nothing less than to enrich and primarily improve the connection between the JVM (Java Virtual Machine) and native code or, as they put it: “We are improving and enriching the connections between the Java Virtual Machine and well-defined but “foreign” (non-Java) APIs, including many interfaces commonly used by C programmers”.

An early version of Project Panama has already been included in Java since 2018, however, this is only recommended for testing purposes. A newer version is likely to arrive at the end of 2021, with the promise of near-full functionality.

Project Loom

Loom is perhaps the most anticipated project of the four. Java has long been criticized for not making it easier for programmers to use thread management and solve concurrent tasks. As they put it, Project Loom is intended to explore, incubate and deliver Java VM features and APIs built on top of them for the purpose of supporting easy-to-use, high-throughput lightweight concurrency and new programming models on the Java platform.

Project Loom is also available as an early-access build, but we will only get a final and usable version in JDK 17.

Projet Valhalla

Valhalla’s most interesting innovation is certainly value types to be introduced alongside primitives and plain objects. In terms of everyday coding, there will be no noticeable difference between value types and normal objects, however, in the background, value types will not behave as objects, but rather as primitives. They will be much more efficient to use than plain objects. According to the Valhalla team, the project will allow you to “code like a class, use it like an int”.

What makes the value type different from an object is that the value type does not have an object header or an identity so of course there is no reference to it. And there is no inheritance between value types, so polymorphism will also fall out of the picture. All of this is necessary because, unlike objects, values are not stored in the heap but in the variable - so the compiler will know the type immediately, as it does for an int, so it will know right away how to process it.

Using ValueType will look like this:

final __ByValue class Point {
    public final int x;
    public final int y;

    public Point( int x, int y ) {
        this.x = x;
        this.y = y;
    }

    public boolean equals( Point other ) {
        return this.x == other.x && this.y == other.y;
    }

    private Point() {
        this.x = 0;
        this.y = 0;
    }

    public static Point of( int x, int y ) {
        Point v = __MakeDefault Point();
        v = __WithField( v.x , x );
        v = __WithField( v.y, y );
        return v;
    }  
}

Placing __ByValue in front of the class declaration will let you use the new type, and then you will have to use the expression __WithField for instantiation instead of the word new keyword.

Project Amber

Amber sticks out of the line a bit, as it is not built around a well-grasped goal, but involves several minor innovations. Among them, there are already things that are available with full functionality, such as switch expression available in Preview mode since JDK 12 or Text Blocks available since JDK 13.

The most important innovation is Pattern Matching, which was first included in JDK 14 as a Preview and will be fully implemented in the near feature. This may not seem like a big step forward at first, but in fact, it already greatly improves the readability of the code as it eliminates the obligatory casting after the use of instanceof.

So this:

    if (obj instanceof String) {
        String s = (String) obj;
        // use s
    }

in the future would be reduced to:

    if (obj instanceof String s) {
        // can use s here
    } else {
        // can't use s here
    }

The clear goal of these four projects is to make Java a modern language again. We are not saying that this alone will be enough, but the intention is clear. And to make things better, these intention is followed by deeds. This post does not intend to deal with every little detail separately, and even presents the four projects only from a remote perspective. The details will be deepened in separate entries.

Do you have a question?

1117 Budapest Budafoki út 97.
+36 1 353 9790
info@ashszoftverhaz.hu
Please see the map for the entrance on Prielle Kornélia Street.