Java 10 Features

Yash Walke
7 min readNov 1, 2021

--

Java 10 is the fastest release of a java version in its 23-year history. Java has been criticized for its slow growth and evolution, but Java 10 just shattered that concept. Java 10 is a release with many futuristic changes, the scope, and impact of which may not be obvious but are far-fetching.

In this article, we will discuss the various features added in the Java10 release. Before that, let’s go over some changes introduced to the java release model.

Starting in 2017, Oracle & the Java community announced its shift to a new 6-month cadence for Java. It moved to a Long Term Support (LTS) model for Oracle Java SE products.

LTS version of the products will offer premier and sustained support from Oracle and it will be targeted every 3 years.

Each Java release is modeled after one or two major features, these features drive the release. Any obstacle postpones the release and is late to market. Project Jigsaw was a major feature of Java 9, it pushed out the release dates a couple of times and the release was delayed by more than 1.5 years. 6 months cadence release will follow a release train. Release train will have a schedule every 6 months. Features that make the cut get boarded on the train; else they wait for the next scheduled train.

In order to be more developer-friendly, Oracle & Java community now promotes the OpenJDK binaries as primary JDK going forward. This is a big relief from earlier days, where the JDK binaries were propriety and licensed by Oracle, which had various restrictions around redistribution. Oracle will, however, keep producing their JDK, but only for long-term support releases. This is a move towards being more cloud & container friendly, as the open JDK binaries can be distributed as part of a container.

Open JDK binaries will be released every 6 months, while Oracle JDK binaries will be released every 3 years (LTS version).

Which JDK binaries will be adopted?

Large organizations take time to move between the versions; they cling on to the version until they can. Industry adoption for Java 6 was more than Java 7 and then Industry is gradually moving to Java 8. In my opinion, the LTS version will be the most favored one by the enterprises. However, whether it would be the LTS version of Oracle JDK or the Open JDK is yet to know, partly because there’s a lot going on in the cloud space.

Let’s take a sneak peek at the features available in Java 10.

  1. With the adoption of the time-based release cycle, Oracle changed the version-string scheme of the Java SE Platform and the JDK, and related versioning information, for present and future time-based release models.

The new pattern of the Version number is:

$FEATURE.$INTERIM.$UPDATE.$PATCH

$FEATURE: counter will be incremented every 6 months and will be based on feature release versions, e.g: JDK 10, JDK 11.

$INTERIM: counter will be incremented for non-feature releases that contain compatible bug fixes and enhancements but no incompatible changes. Usually, this will be zero, as there will be no interim release in a six-month period. This kept for a future revision to the release model.

$UPDATE: counter will be incremented for compatible update releases that fix security issues, regressions, and bugs in newer features. This is updated one month after the feature release and every 3 months thereafter. The April 2018 release is JDK 10.0.1, the July release is JDK 10.0.2, and so forth

$PATCH: counter will be incremented for an emergency release to fix a critical issue.
New APIs have been added to get these counter values programmatically. Let’s take a look;

Version version = Runtime.version();
version.feature();
version.interim();
version.update();
version.patch();

Now, let us take a look at the Java launcher which returns the version information:

$ java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

2.

The version number format is “10” as there’s no other counter which is other than zero. The date of release is added. 18.3 can be read as the Year 2018 & 3rd Month, build 10+46 is the 46th build for version 10. For a hypothetical build 93 of JDK 10.0.1, the build will be 10.0.1+93.

  • Limited only to Local Variable with initializer
  • Indexes of enhanced for loop or indexes
  • Local declared in for loop
var numbers = List.of(1, 2, 3, 4, 5); for (var number : numbers) { System.out.println(number);
} for (var i = 0; i < numbers.size(); i++) { System.out.println(numbers.get(i));
}

3.

This feature enables the Java-based JIT compiler, Graal, to be used as an experimental JIT compiler on the Linux/x64 platform. This is by far the most futuristic inclusion in the Java 10 feature list.

Graal was introduced in Java 9. It’s an alternative to the JIT compiler which we have been used to. It’s a plugin to the JVM, which means that the JIT compiler is not tied to JVM and it can be dynamically plugged in and replaced with any other plugin which JVMCI compliant (Java-Level JVM Compiler Interface). It also brings Ahead of Time (AOT) compilation in the java world. It also supports polyglot language interpretation.

“A Java-based Just in Time Compiler written in Java to convert the java bytecode to machine code.” Is it confusing? If JVM is written in Java, then don’t you need a JVM to run the JVM? The JVM can be compiled AOT and then the JIT compiler can be used within JVM for enhancing performance through live code optimization.

Graal is a complete rewrite of the JIT compiler in Java from scratch. The previous JIT compiler was written in c++. It’s considered one for the final stage of evolution for any programming language.

You can switch to Graal with the following JVM parameters:

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

4.

This feature helps in improving the startup footprint, extends the existing Class-Data Sharing (“CDS”) feature to allow application classes to be placed in the shared archive.

JVM while starting performs some preliminary steps, one of which is loading classes in memory. If there are several jars having multiple classes, then the lag in the first request is clearly visible. This becomes an issue with serverless architecture, where the boot time is critical. In order to bring down application startup time, Application class-data sharing can be used. The idea is to reduce footprint by sharing common class metadata across different Java processes. This can be achieved by the following 3 steps:

Determining the classes to archive: Use the java launcher to create a list of files to archive, this can be achieved by the following parameters:

java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=hello.lst -cp hello.jar HelloWorld

Creating the AppCDS archive: Use java launcher to create the archive of the list of files to be used for Application CDS, this can be achieved by the following parameters:

$java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=hello.lst -XX:SharedArchiveFile=hello.jsa -cp hello.jar

Using the AppCDS archive: Use a Java launcher with the following parameters to use Application CDS.

java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa -cp hello.jar HelloWorld

5.

A G1 garbage collector was made default in JDK 9. G1 Garbage collector avoids any full garbage collection, but when concurrent threads for collection cannot revive the memory fast enough user's experience is impacted.

This change improves the G1 worst-case latency by making the full GC parallel. The mark-sweep-compact algorithm from the G1 collector is parallelized as part of this change and will be triggered when concurrent threads for collection can’t revive the memory fast enough.

6.

This JEP is a futuristic change. It improves the code isolation of different garbage collectors by introducing a common Garbage Collector Interface.

This change provides better modularity to the Internal GC Code. It will help in the future for adding a new GC without changing the existing codebase, also help in removing or housekeeping the previous GC.

This JEP is a futuristic change. It improves the code isolation of different garbage collectors by introducing a common Garbage Collector Interface.

This change provides better modularity to the Internal GC Code. It will help in the future for adding a new GC without changing the existing codebase, also help in removing or housekeeping the previous GC.

7.

This feature enhances java.util.Locale and related APIs to implement additional Unicode extensions of BCP 47 language tags. As of Java SE 9, the supported BCP 47 U language-tag extensions are “ca” and “nu”. This JEP will add support for the following additional extensions:

♦cu (currency type)
♦fw (first day of the week)
♦rg (region override)
♦tz (time zone)
In order to support these additional extensions, changes are made to various APIs to provide information based on U or additional extensions.

java.text.DateFormat::get*Instance
java.text.DateFormatSymbols::getInstance
java.text.DecimalFormatSymbols::getInstance
java.text.NumberFormat::get*Instance
java.time.format.DateTimeFormatter::localizedBy
java.time.format.DateTimeFormatterBuilder::getLocalizedDateTimePattern
java.time.format.DecimalStyle::of
java.time.temporal.WeekFields::of
java.util.Calendar::{getFirstDayOfWeek,getMinimalDaysInWeek}
java.util.Currency::getInstance
java.util.Locale::getDisplayName
java.util.spi.LocaleNameProvider

8.

In order to promote OpenJDK and make it more appealing to community users, this feature provides a default set of root Certification Authority (CA) certificates in the JDK. This will also mean that both Oracle & Open JDK binaries will be functionally the same.

Critical security components such as TLS will work by default in OpenJDK builds going forward.

9.

This is an internal JVM feature to improve performance.

A handshake operation is a callback that is executed for each JavaThread while that thread is in a savepoint state. The callback is executed either by the thread itself or by the VM thread while keeping the thread in a blocked state.

This feature provides a way to execute a callback on threads without performing a global VM safepoint. Make it both possible and cheap to stop individual threads and not just all threads or none.

  • List, Map & Set Interfaces are added with a static copyOf(Collection) method. Its returns an unmodifiable List, Map, or Set containing the entries provided. For a list, if the given List is subsequently modified, the returned List will not reflect such modifications.
  • Optional & its primitive variations get a method orElseThrow(). This is exactly same as get(), however, the java doc states that it is a preferred alternative than get().
  • Collectors class gets various methods for collecting unmodifiable collections (Set, List, Map).
List<String> actors = new ArrayList<>();
actors.add("Jack Nicholson");
actors.add("Marlon Brando");
System.out.println(actors); List<String> copyOfActors = List.copyOf(actors);
System.out.println(copyOfActors); actors.add("Robert De Niro");
System.out.println(actors);
System.out.println(copyOfActors); String str = "";
Optional<String> name = Optional.ofNullable(str);

name.orElseThrow();


List<String> collect = actors.stream().collect(Collectors.toUnmodifiableList());

In this article, we went through the different new feature addition of Java 10. If you think anything important got missed here, please let us know through comments.

--

--

Yash Walke

I'm a tech guy, who engaged with codes. Loves to spread knowledge.👨‍💻.