Java 11 Cookbook
上QQ阅读APP看书,第一时间看更新

Getting ready

The Java 10 release (JDK 18.3) started a six-month release cycle—every March and every September—and a new release numbering system. It also introduced many new features, the most significant of which (for application developers) are the following:

  • Local variable type inference that allows the declaration of a variable using the reserved var type (see Chapter 15, The New Way of Coding with Java 10 and Java 11)  
  • Parallel full garbage collection for the G1 garbage collector, which improves worst-case latencies
  • A new method, Optional.orElseThrow(), that is now the preferred alternative to the existing get() method
  • New APIs for creating unmodifiable collections: The List.copyOf(), Set.copyOf(), and Map.copyOf() methods of the java.util package and new methods of the java.util.stream.Collectors class: toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() (see Chapter 5, Streams and Pipelines)  
  • A default set of root Certification Authorities, making OpenJDK builds more appealing to developers
  • A new Javadoc command-line option, --add-stylesheet, provides support for the use of multiple stylesheets in the generated documentation
  • Extending the existing class-data sharing feature to allow application classes to be placed in the shared archive that improves startup time and reduces the footprint (see the Using application class-data sharing recipe)

  • An experimental just-in-time compiler, Graal, can be used on the Linux/x64 platform
  • A clean garbage-collector (GC) interface that makes it simpler to add a new GC to HotSpot without perturbing the current code base and makes it easier to exclude a GC from a JDK build
  • Enabling HotSpot to allocate the object heap on an alternative memory device, such as an NVDIMM memory module, specified by the user
  • Thread-local handshakes, for executing a callback on threads without performing a global VM safepoint
  • Docker awareness: JVM will know whether it is running in a Docker container on a Linux system and can extract container-specific configuration information instead of querying the operating system
  • Three new JVM options, to give Docker container users greater control over the system memory

See the full list of Java 10's new features in the release notes: https://www.oracle.com/technetwork/java/javase/10-relnote-issues-4108729.html.

We will discuss the new features of JDK 18.9 in more detail in the next section.