What are the main features and enhancements introduced in Java 9?
Oracle has released Java 9 version with a rich set of new features and brings a lot of new enhancements.
Below are a few important features and enhancements introduced in Java 9.
- Factory Methods for Collections: Factory methods are special kinds of static methods that can be used to create unmodifiable instances of collections, which means we can use these methods to create a list, set, and map.
- Java Platform Module System (JPMS): A Java Module is a mechanism to bundle java applications and java packages into a Java module. It specifies which of the java packages that contain visible to other java modules by using this module.
- Private methods in Interfaces: Private methods are allowed to include private and private static in an interface, so improves the code re-usability inside an interface.
- Java 9 REPL (Jshell): Jshell is a REPL (Read Evaluate Print Loop) tool and runs from the command line. We can launch Jshell from the console and directly start typing and executing the java code.
- Try With Resources Improvement: Java introduced a try-with-resources feature in Java 7 that helps to close resources automatically after being used.
- Diamond Operator for Anonymous Inner Class: Java 9 has introduced a new feature that allows us to use a diamond operator with anonymous classes.
- Completable Future API Improvements: Java 9 version improved CompletableFuture API to solve some problems raised in Java 8. They have added to support some delays and timeouts, some utility methods and better sub-classing.
- Reactive Streams: Reactive Stream API is a publish-subscribe framework to implement asynchronous, scalable and parallel applications very easily using java language.
- Process API Improvements: Process API has the responsibility to control and manage operating system processes that improve considerably. ProcessHandle class can provide the process’s native process ID, start time, accumulated CPU time, arguments, command, user, parent process and descendants.
- Optional Class Improvements: In Java 9, there are three main improvements of Optional class: Optional.ifPresentOrElse(), Optional.or() and Optional.stream().
- Stream API Improvements: Stream API has improved and new methods added to the Stream interface. The takeWhile (), dropWhile (), ofNullable () and iterate () methods added to perform operations on stream elements.
- Мulti-Resolution Image API: Multi-Resolution Image API can encapsulate a set of images with different height and widths that can allow us to query them with our requirements.
- HTTP/2 Client: HTTP/2 is the new version of the HTTP protocol and focuses on how data have framed and transported between server and client. In Java 9, the HTTP Client module is bundled as an incubator module and supports HTTP/2 with backward compatibility.
- Enhanced @Deprecated annotation: @Deprecated annotation can provide more information about deprecated API. It can also provide a tool to analyze the application’s static usage of deprecated APIs.
Published on 11-Feb-2020 08:00:28