Home  >  Article  >  Java  >  What are the major features and enhancements introduced in Java 9?

What are the major features and enhancements introduced in Java 9?

PHPz
PHPzforward
2023-08-31 19:05:021324browse

Java 9引入了哪些主要功能和增强?

Oracle has released Java 9 version with a rich set of new features and many new Enhanced features.

Here are some of the important features and enhancements introduced in Java 9.

  • Factory method of collections: Factory method is a special type of static method that can be used to create unmodifiable Collection instances, which means we can use these methods to create Lists, Collections and Maps.
  • Java Platform Module System (JPMS): Java modules are a mechanism for bundling Java applications and Java packages into Java modules. It specifies which Java packages contain visible to other Java modules.
  • Private methods in the interfaces: The interface is allowed to include private and private static methods, thereby improving Code reusability inside the interface.
  • Java 9 REPL (Jshell) : Jshell is a REPL (read evaluation print loop) tool, Can be run from the command line. We can launch Jshell from the console and start entering and executing Java code directly.
  • Improvements in resource management: Java introduced a try-with-resources feature in Java 7 that can be automatically closed after use resource.
  • Diamond operator for anonymous inner classes: Java 9 introduced a new feature that allows us to use diamond## inside anonymous classes #operator.
  • Improvements in CompletableFuture API: The Java 9 version improves CompletableFuture API and solves some problems that occurred in Java 8. They add support for some delays and timeouts, some utility methods and better subclassing.
  • Responsive streaming: The reactive streaming API is a publish-subscribe framework that can be very easily implemented using Java language Asynchronous, Scalable and Parallel applications.
  • Improvements in process API: The process API is responsible for controlling and managing operating system processes, and has been significantly improved in this regard. ProcessHandle The class can provide the native process ID, startup time, accumulated CPU time, parameters, commands, users, parent processes and child processes of the process.
  • Improvements of the Optional class: In Java 9, the Optional class has three main improvements: Optional.ifPresentOrElse(), Optional.or() and Optional.stream().
  • Improvements to the Stream API: The Stream API has been improved and new methods have been added to the Stream interface. Added takeWhile (), dropWhile (), ofNullable () and iterate () methods to perform operations on stream elements.
  • Multi-resolution image API: The multi-resolution image API can encapsulate a set of images with different height and width , which can be customized according to our Query them on request.
  • HTTP/2 Client: HTTP/2 is a new version of HTTP protocol , focusing on data between the server and the client How it is framed and transmitted. In Java 9, the HTTP Client module is bundled as an incubator module and supports HTTP/2 with Backwards Compatibility.
  • Enhanced @Deprecated annotation : The @Deprecated annotation can provide more information about deprecated API. It can also provide a tool to analyze an application's static usage of deprecated APIs.

The above is the detailed content of What are the major features and enhancements introduced in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete