Updated March 31, 2023
Introduction to Java 9 Features
One of the upgraded versions of java is java nine, which was released on the 27th of July 2019 consisting of many features like improved Javadoc, collections like List, Map, Set, Map.entry etc. using factory methods, Jshell which is an interactive java repl, stream API improvements, methods in interfaces that are private, multi-resolution image API, the java nine platform module system, improvements in process API, HTTP/2 client.
Java is a high-level programming language developed by sun microsystems and is a language that can be used for general purposes. Its design is such that the dependencies in implementation are very few because it is concurrent, based on class, object-oriented. Java is independent of the platform, and it follows the principle of write once run anywhere (WORA). There are several different versions of java, and with each version, there is development and improvement, and new features keep getting added to each of the new versions.
Features of Java 9
Some of the features of Java 9 is as follows:
1. Improved Javadoc
Complete java documentation is available for java version 9, and it is not necessary for us to search for documentation on google. The search rights are available in the API documentation of java. Java is compliant with HTML. There is java document information on every page related to JDK modules, interfaces and classes.
2. Factory method for collections such as List, Map, Set and map.entry
Whenever we want to create a collection in java consisting of elements, repetitive coding is necessary to create the instance of the collection while calling the add functions. There are several such factory methods in Java 9. Of() method is present in the list and set interfaces to create an empty or non-empty immutable list or objects of the set.
3. Jshell: The interactive Java REPL
A tool called Jshell is introduced by Oracle corporation. The abbreviation of Jshell is Java shell. It is also known as Read Evaluate Print Loop (REPL). This interactive read evaluates print loop is already a feature of many programming languages and now the feature of java 9 as well. Any of the java constructs like class, object, enum, interface etc., can be tested and executed. Jshell can be launched from the console, and the java code can be executed from there. The feature of jshell can be used to explore application programming interfaces and can be used to try out various features of the language.
4. Stream application programming interface improvements
Four new methods have been added to java.util.stream interface by the oracle corporation. All the newly implemented methods are default methods because the stream is an interface. The pipelines of transformations can be created on collections through a stream. Dropwhile, takewhile, ofnullable are the newly added methods to the stream interface. New overload is added to the iterate method by providing a predicate that indicates the stop of iteration.
5. Private methods in interfaces
Default and static methods are used in the implementation of methods in interfaces. Private methods cannot be created in interfaces. Oracle corporations have created new private methods to avoid code redundancy and can be re used more often. Private and private static methods can be created in Java 9 using the ‘private’ keyword.
Code:
public interface Car
{
private Long CarID()
{
// Method implementation goes here.
}
private static void display()
{
// Method implementation goes here.
}
}
6. Multi-resolution image application programming interface
A new multi-resolution image application programming interface is introduced by oracle corporation. The multi-resolution image is the important interface in the application programming interface. A multi-resolution image is available in java.awt.image package. A set of images with different heights and widths is encapsulated by a multi-resolution image and can be used to query our requirements.
7. The java 9 platform module system
The module system is the new feature in java 9.
The following features are introduced by oracle corporation as part of the jigsaw project:
- Modular JDK
- Modular Java Source Code
- Modular run time images
- Encapsulate java internal application programming interfaces
- Java platform module system
Monolithic jars were used to develop applications based on java before the release of Java version 9. There were a lot of limitations and drawbacks in the previous architecture. Module system in java version 9 can be used to overcome these drawbacks.
8. Improvements in-process application programming interface
There are improvements in the process application programming interface in java version 9. The controlling and managing of operating system processes can be easier by the newly added classes. The process application programming interfaces consists of two new interfaces. They are:
Code:
lang.processhandle
lang.processhandle.info
9. HTTP/2 client
HTTP calls can be performed using Java 9. There were several issues with the existing or legacy HTTP client application programming interface; it has been replaced by the HTTP URL Connection application programming interface. Java.net http package introduces a new HTTP client application programming interface. Both HTTP/1.1 and HTTP/2 protocols are supported. Synchronous and asynchronous modes are also supported. Websocket application programming interface is used to support asynchronous mode.
Code:
HttpClient cle = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create("http://www.java.com"))
.header("agent", "Java1")
.GET()
.build()
HttpResponse res=client.send(req,HttpResponse.BodyHandler.asString());
The other features of Java version 9 Include
- Garbage collector (GC) improvements
- Stack walking application programming interface
- Filtering the incoming serialization data
- Applet Application programming interface deprecation
- String concatenation indify
- Enhanced method handles
- Java platform logging application programming interface and service
- Compact strings
- Parser application programming interface for Nashorn
- Javadoc search.
Conclusion
In this tutorial, we understand the concept of the java 9 version’s several features through definition like Improved Javadoc, Factory method for collections such as List, Map, Set and map.entry, JShell: the interactive Java REPL, Stream API Improvements, Private methods in Interfaces, Multi-Resolution Image API, The Java(9) Platform module system, Improvements in Process API, HTTP/2 Client, Garbage collector (GC) improvements, Stack walking application programming interface, Filtering the incoming serialization data, Applet Application programming interface deprecation, Applet Application programming interface deprecation, String concatenation indify, Enhanced method handles, Java platform logging application programming interface and service, Compact strings, Parser application programming interface for Nashorn, Javadoc search.
Recommended Articles
This is a guide to Java 9 Features. Here we discuss Introduction to Java 9 Features, Some features with explanation and the other features. You can also go through our other related articles to learn more –