Future of the Java programming language: Three major projects on the horizon

Three of the major projects in the pipeline that will help determine the future of Java.

The best programming languages to learn in 2019: Top coding skills that pay you the most These are the languages that are in the highest demand and offer the highest salaries.

The pace of change in Java has never been faster, with new releases of the language now being pushed out every six months.

Helping shape some of these changes are collaborative projects focused on improving performance and adding new features.

The aim of these projects is quite ambitious, as Trisha Gee, developer advocate for JetBrains, referred to when she told the QCon London 2019 conference: "There's loads of cool stuff coming in Java down the line."

These are three of the major projects in the pipeline that will help determine the future of Java.

Project Loom

An attempt to improve how Java handles concurrency, a reference to the computer's ability to switch between executing different sets of instructions.

Ron Pressler, technical lead for Project Loom at Oracle, told the QCon 2019 conference in London that Java developers who want to write software to handle concurrent tasks are faced with two imperfect options: to write "simple synchronous blocking code" that can't scale to handle large numbers of concurrent tasks or use complex asynchronous code that will scale but is difficult to write and debug.

SEE: Hiring kit: Python developer (Tech Pro Research)

To find a way around this issue, Project Loom introduces a new way to split tasks into threads, the name given to the smallest possible units of execution when a computer is running instructions. Loom introduces new lightweight user threads called fibers.

"With fibers, if we can indeed make them much more lightweight than the threads provided by the kernel, we solve the problem. You can have as many of these user mode lightweight threads as you like and blocking becomes essentially free," he told the conference.

Using these new fibers would be made possible by augmenting the Java Virtual Machine (JVM) to support delimited continuations, which would allow the sets of instructions being executed to be paused and resumed. The task of pausing and resuming these continuations would be handled by Java's ForkJoinPool scheduler in asynchronous mode.

According to the documentation, fibers would use a very similar API to Java's existing Thread class, so the learning curve for existing Java developers should be manageable.

Project Amber

The goal of Project Amber is to accelerate the pace at which useful new features are added to the language by supporting the development of "smaller, productivity-oriented Java language features".

This approach is a good fit for the faster pace at which new versions of Java are being released since Java 9.

At present, the following JDK Enhancement Proposals (JEPs) are listed as being in progress and falling under Project Amber.

Raw String Literals

Raw string literals would make it simpler for developers to format text appropriately without the complexity of having to add escape characters.

For example, not having to use the \n escape character to represent a newline, so in the following string.

Hello

World

would allow it to be written as:

`Hello

World`

rather than:

"Hello\nWorld\n"

The documentation for the proposal suggests the change could make it simpler to input various text strings, from file paths to SQL statements.

As you can see, raw string literals would be enclosed in backticks.

Java Compiler Intrinsics for JDK APIs

This proposal would allow developers to optimize the performance of important stretches of code they call regularly.

Specifically it would let developer instruct the compiler to optimize the performance specific Java Developer Kit (JDK) methods by designating them as candidates for compile-time intrinsification.

The proposal documents give String::format and Objects::hash as examples of methods that are candidates for compile-time intrinsification, due to their critical importance in Java. Such methods could annotated with @IntrinsicCandidate to instruct the compiler to treat them as such, while JDK's implementation of the javac compiler would be modified to create a mechanism for handling the intrinsification process.

Pattern Matching

Pattern Matching would make it simpler to use Java's instanceof operator to check whether an object is an instance of a specific class and then extract components of that object for further processing.

It would allow syntax for operations like below to be shortened from:

if (obj instanceof Integer) {

int intValue = ((Integer) obj).intValue();

// use intValue

}

to:

if (x instanceof Integer i) {

// can use i here, of type Integer

}

Switch Expressions

Switch expressions, already available in preview as part of Java 12, allow developers to use simpler syntax when using switch statements to specify different responses based on the input.

For example, rather than using the following syntax for each case within the switch statement:

switch (port) {

case 20:

type = PortType.FTP;

break;

}

each case could instead be expressed in the following, more concise manner:

Switch (port) {

case 20 -> PortType.FTP;

}

Project Valhalla

Project Valhalla is focused on supporting the development of "advanced" JVM and language features.

There are just a couple of candidate proposals listed as falling under Valhalla at present.

Value Types

A proposal aimed at allowing the JVM to handle a new type called Value Types.

These new immutable types would combine the memory efficiency of primitives like int but, similar to classes, would be able to hold an aggregate of primitives.

The proposal document states the goal as being to "provide JVM infrastructure for working with immutable and reference-free objects, in support of efficient by-value computation with non-primitive types".

Generic Specialization

This proposal extends the types that can be used with generics to also include primitives and the upcoming value types.

Also see