Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java Interfaces

Java Data Structures

Java Collections Algorithms

Advanced Java

Java Miscellaneous

Java APIs & Frameworks

Java Class References

Java Useful Resources

Java 10 - New Features (APIs & Options)


Java 10 is a major release in Java release cadence and it was releasd on March 10, 2018. With Java 10, Oracle has changed the java release cadence to a new model, a 6 month release cadence and LTS model for Oracle Java SE products. LTS model stands for Long Term Support model.

From Java 10 onwards, Oracle releases a new version of Java after every 6 month where each version contains one or two major features. Oracle uses a release train concept. Each release train is scheduled for 6 months. Features which are developed within this timeline are shipped in the release otherwise the features are moved to next release train.

Oracle JDK vs OpenJDK

Most of the Oracle JDK binaries are propriety and licensed by Oracle and have multiple restrictions on redistribution. Whereas OpenJDK is more developer community friendly. From Java 10 onwards, Oracle has decided to promote OpenJDK as primary JDK to facility community based development of Java. Oracle will keep producing its own JDKs but it will release them after 3 years and term them as LTS version. So OpenJDK binaries will be released after every six month.

OpenJDK is cloud and container friendly as it can freely distributed as part of the container. So Oracle's move to promote OpenJDK makes java more friendly towards cloud or container development and deployment.

Java 9 and Java 10 are non-LTS release. Java 11 release is a LTS release.

Java 10 New Features

Following are the major new features which are introduced in Java 10.

Java 10 enhanced 70+ APIs with new methods and options and removed deprecated APIs and options. We'll see these changes in next chapters.

Java 10 - New APIs & Options

JDK 10 release has added 70+ new APIs and Options to Java library. Following are some of the important enhancements introduced.

Optional.orElseThrow() Method

A new method orElseThrow() is available in java.util.Optional class which is now a preferred alternative for get() method.

APIs to create Unmodifiable Collections

A new method copyOf() is available in List, Set and Map interfaces which can create new collection instances from existing one. Collector class has new methods toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() to get elements of a stream into an unmodifiable collection.

Disable JRE Last Usage Tracking

A new flag is introduced jdk.disableLastUsageTracking which disables JRE last usage tracking for a running VM.

Hashed Password

The plain text passwords available in the jmxremote.password file are now being over-written with their SHA3-512 hash by the JMX agent.

javadoc Support for Multiple Stylesheets

A new option is available to javadoc command as --add-stylesheet. This option supports use of multiple stylesheets in generated documentation.

javadoc Support for Overridding methods

A new option is available to javadoc command as --overridden-methods=value. As many classes override inherited methods but do not change the specification. The --overridden-methods=value option allows to group these methods with other inherited methods, instead of documenting them again separately.

javadoc Support for Summary

A new inline tag, {@summary ...}, is available to specify the text to be used as the summary of the API description. By default, the summary of an API description is inferred from the first sentence.

Example

Following Program shows the use of some of the new APIs in JAVA 10.

import java.util.List;
import java.util.stream.Collectors;

public class Tester {
   public static void main(String[] args) {
      var ids = List.of(1, 2, 3, 4, 5); 
      try {
         // get an unmodifiable list
         List<Integer> copyOfIds = List.copyOf(ids);
         copyOfIds.add(6);	
      } catch(UnsupportedOperationException e){
         System.out.println("Collection is not modifiable.");
      }
      try{
         // get an unmodifiable list
         List<Integer> evenNumbers = ids.stream()
            .filter(i -> i % 2 == 0)
            .collect(Collectors.toUnmodifiableList());;
         evenNumbers.add(6);	
      }catch(UnsupportedOperationException e){
         System.out.println("Collection is not modifiable.");
      }
   }
}

Output

It will print the following output.

Collection is not modifiable.
Collection is not modifiable.

Useful Links

Advertisements