What to Expect in Java 11

The last few years have been tumultuous for the Java world, with a diverse range of features being added in quite a few releases.

There was a sentiment building up in the developer community that Java wasn’t developing fast enough. For the first 20 years, the Java platform and the Java Development Kit (JDK) evolved in large, irregular, and somewhat unpredictable steps. Every feature release was driven by one or more significant features. So the schedule of each release was delayed multiple times to accommodate the completion of those features.

This approach worked well to deliver big new features with a high level of quality. However, the smaller features and application programming interface (API) could be delivered only when big features were ready. This was acceptable a few years back, but not anymore. Nowadays, developers can choose from a variety of platforms that are evolving at a more rapid pace.

The last release under Sun Microsystems’ stewardship was Java 1.6 (a.k.a. Java 6) and it remained as the last major Java release for five years. Sun soon fell into trouble and was eventually acquired by Oracle.

Java 7 was the first major release under Oracle’s leadership and was followed by Java 8. The evolutionary change for the Java platform started with Java 9. Just as Java 8 was all about lambdas and their consequences (functional programming, streams, and default methods), Java 9 was mostly about modules.

Before seeing what new, exciting features are coming out in Java 11, let’s first take a look at the gradual introduction of new features since Java 9.

Features Introduced in Java 9

After several schedule delays, Java 9 was released on September 21, 2017. Most developers consider Java 9 to be mostly about modularity.

The Java 9 release and its features were a milestone in the Java ecosystem. Modules were a new way to build and deploy software. They helped developers create better architected software with a much smaller footprint. The key features introduced were Project Jigsaw, JShell, and several other feature improvements.

Project Jigsaw was the biggest addition in JDK 9 that brought modularity to the Java platform. A large codebase often leads to complicated, tangled “spaghetti code.” It is quite challenging to encapsulate code with no clear dependencies between various parts (Java Archive, or JAR files) of a system.

Project Jigsaw introduced modularity like OSGi, where an additional module descriptor can be used to express dependencies among modules. Project Jigsaw was a paradigm shift in the ways we envision and develop large-scale applications.

Twenty years of development on the Java platform has taken its toll. Many classes have gotten entangled and there has been no easy way to encapsulate private implementation classes in the JDK. This encouraged proliferation of external libraries depending on internal details, all the while hampering the evolution of the platform.

With Project Jigsaw, now Java 9 comes with around 90 distinct modules that group related packages. Only packages that have been explicitly exported from a module can be accessed from other modules. This makes encapsulation of internal implementation classes a reality.

Additionally, modules can specify dependencies on other modules. Just like JDK has been modularized, applications can also use the same techniques. Rather than using a brittle classpath (which has duplicate, missing, or inconsistent JARs), you can create your own module that encapsulates packages and specifies dependencies. This will go a long way in making better-structured and more reliable applications.

Java 9 also introduced JShell, the Interactive Java REPL, which is short for Java Shell and is also known as REPL (Read-Evaluate-Print Loop). It adds the capability to execute different Java constructs like class, interface, enum, object, and statements. JShell has a wide variety of uses, and the most common one is to perform quick tests on some code to see how it works. There is no need to first create a class, compile it, and run it. Just use JShell for quick tests.

Different feature improvements were introduced, like upgraded network communication and support of WebSockets with HTTP/2.0 support, Enhanced Process API to ease controlling and managing of operating system processes, and Stream API improvements to create declarative pipelines of transformations on collections.

Features Introduced in Java 10

Java 10 was released on March 20, 2018. As it had a short release cycle, only a handful of features were introduced. Since it is supposed to be a short-term release, public updates for JDK 10 are slated to end in six months. Many developers may not migrate to Java 10, as they would prefer to wait for Java 11.

Type inference was a demand from the developers for a long time, as a lot of statically typed languages are already supporting this feature.

With JEP 286, local variable type inference (JDK Enhancement Proposal), a new keyword, var, has been introduced, which shortens the declaration of a local variable. It indicates to the compiler to infer the type of the local variable from its initializer.

Prior to Java 10, we used to declare variables like this:

With Java 10, we can avoid explicit type declaration and write code like this:

The keyword var has made Java less verbose by removing the redundancy from the variable declaration. It would be possible to implicitly determine the type of variable from the context in which it is used.

With time-based release versioning, the format of the Java version number has been changed to improve the support for a time-based release model. The most notable aspect of the new release model is that the content of a release is subject to change.

At the beginning, only the release date is announced. However, if the development of this new feature takes longer than anticipated, it is removed from the release cadence and will not be included. Therefore, there is a need for a version number that depicts the passage of time, instead of the nature of the included changes.

Parallel full GC in G1 is an interesting feature that might get lost in the noise of big bang feature announcements. In fact, many developers may not even notice it.

G1 GC was introduced in Java 8 and it became the default garbage collector in Java 9. By design, it avoids full garbage collections, but they still happen.

G1 uses only a single threaded mark-sweep-compact algorithm to perform a full collection, which can result in performance issues.

Java 10 has fixed this issue by performing full GC by using multiple threads. The same number of threads are used for full collection as the number of threads being used for young and mixed collections. There would be a marked improvement in full GC performance of the G1 collector now.

Long-Term Release and Support Cycle

Java 10 has just been released, but we are now eagerly awaiting the release of Java 11 later this year. With Oracle aiming for a faster release cycle, there are more features and abilities coming our way fast. Java 11 will be a long-term support release, unlike JDK 10, and will be a reference implementation of Java Platform, Standard Edition (Java SE) 11.

Along with the new release train, Oracle has also changed their support model. In the new scheme of things, there is a difference between short-term and long-term releases. Releases like Java 9 and 10, which are short-term releases, will receive public updates until the next feature release is available. This implies that support for Java 9 ended in March 2018 and support for Java 10 will end after September 2018.

Java 11 has a unique distinction of being the first long-term release, and it will be supported for a more extended period. Java 11 will receive premier-level support from Oracle until September 2023 and extended support until 2026.

What’s New in Java 11?

Java 11 will potentially come out with a few key features. Java 11 may also lose some capabilities through the removal of CORBA (do people still use it?), Java EE modules (recently renamed Jakarta EE), and JavaFX.

CORBA was a popular way to create distributed applications more than two decades back, but I think it’s being used only in legacy applications now. Java EE and JavaFX don’t quite fit in the JDK stack anymore and there are other third-party libraries providing these capabilities now. Let’s consider these aspects in detail.

New Features Planned for Java 11

At this point, Java 11 is set to introduce the following features:

  • JEP 318: Epsilon: An Arbitrarily Low-Overhead Garbage Collector—Epsilon is billed as a “no-ops” collector, which promises to handle memory allocation without implementing any actual memory reclamation mechanisms. As stated in the proposal, the goal is to “provide a completely passive GC implementation with a bounded allocation limit and the lowest latency overhead possible, at the expense of memory footprint and memory throughput.” Specific use cases for Epsilon include performance testing, memory pressure testing, and virtual machine (VM) interface testing. It would also be useful for extremely short-lived jobs, last-drop latency improvements, or last-drop throughput improvements.
  • JEP 323: Local-Variable Syntax for Lambda Parameters—Local variable type inference was introduced in Java 10 as a measure to reduce verbosity associated with writing Java code. Java 11 takes it one step ahead by allowing var to be utilized for declaring the formal parameters of implicitly typed lambda expressions.

Currently, you need to specify parameters for a lambda expression as follows:

From Java 11 onward, you can simplify it by writing it in the following manner:

While it leads to uniformity of syntax, it also makes it possible to apply modifiers to local variables             and lambda formats without lack of brevity. There is no need for redundant syntax constructs, as               they can be deduced from the context.

  • JEP 309: Dynamic Class-File Constants—The Java class-file format will be extended to support a new constant-pool form, CONSTANT_Dynamic. This will reduce the cost and disruption of creating new forms of materializable class-file constants. Currently, linking an invokedynamic callsite delegates linkage to a bootstrap method. It is a JVM instruction that allows the compiler to generate code, which calls methods with a looser specification than was previously possible. It provides the ability to make a dynamic call that the JVM not only recognizes, but also optimizes in the same way it optimizes plain old static-typed calls. Now, loading a CONSTANT_Dynamic will delegate creation to a bootstrap method. The new constant-pool form will offer language designers and compiler implementers broader options for expressivity and performance.

Faster JDK Release and Shorter Support Cycles

With Oracle aiming for a faster release cycle, there are more features and abilities coming our way with a high velocity. Oracle announced last year that there would be two JDK releases in 2018, and JDK 10 has already been released. This is a welcome change from an era of slow release cycles with a good amount of features getting introduced in a major release every few years.

We can now expect a smaller feature release every six months. This has many benefits including faster innovation of the Java platform. The risk in updating your version of Java gets reduced. The smaller feature set makes the adoption easier for developers.

The faster release cycles have made Java an agile and nimble language. It has become a dynamic language that is responding to market forces and concerns of the developer community.

What Won’t Make the Cut in Java 11?

Although Java 11 will likely come with some new features, it will still be leaner than Java 10, primarily because a few legacy features are going to be dropped.

JEP 320: Remove the Java EE and CORBA Modules aims to remove Java EE and CORBA modules from the Java SE platform and the JDK. In fact, these modules were already deprecated in Java 9 with the declared intent to remove them in a future release.

With Java SE 6 getting released in December 2006, a full Web services stack was included. This consisted of four technologies:

  • JAX-WS—Java API for XML Web Services
  • JAXB—Java Architecture for XML Binding
  • JAF—JavaBeans Activation Framework
  • Common Annotations for Java

Since that time, the Java EE versions have evolved, making it difficult for Java SE to include irrelevant technologies and cumbersome maintenance across the two Java editions. There are third-party sites providing standalone versions of Java EE technologies, so Oracle no longer feels obligated to include them in Java SE or in the JDK.

In regard to the removal of CORBA, this technology is from the 1990s and hardly anyone develops applications using it these days. Since the cost of CORBA maintenance far outweighs the benefits, Oracle feels there is no point in Java SE or the JDK to include it.

Get Ready for Java 11

As a Java developer, you now have an option to update your Java version every six months, or you may prefer a long-term release every few years.

Oracle also recommends everyone migrate to their Java SE Advanced product. It will offer at least five years of support for every long-term release. In my opinion, if you are still on an earlier version like Java 8 or Java 9, you can wait a bit longer and then migrate directly to Java 11.

Java 11 will help developers in creating better software with its exciting new features, like the low-overhead Garbage Collector, using lambda expressions with less verbosity, and broader options for language designers and compiler implementers. The future looks exciting for the Java world.