noscript

Java9 Features – Complete Guide

Java 9 introduced several new features and enhancements to the Java programming language and platform. Here are some of the key features of Java 9:

Java 9 was a significant upgrade from Java 8 that brought us numerous features for developers.

Java 9 was released on Sep 21, 2017.

In this article, we will discuss the features.

Java 9 Features:

  1. Improved Javadoc

The Java 9 update has brought with it updated Java documentation, so we don’t have to use Google to find the correct documentation. The new Javadoc provides search capabilities directly within the API documentation. Furthermore, the Javadoc output conforms to HTML5 standards. Every Javadoc page has information about the JDK module that the class or interface originates from.

  1. Factory methods for collection(List, Map, Set, Tree)

It’s common to want to create a collection (such as a List or Set) in your Java program and populate it with some elements. Repetitive coding occurs when you initialize the collection and then make multiple ‘add’ calls. In Java 9, there have been several additions to the collection factory methods. The ‘of()’ methods available in List and Set interfaces enable the creation of an Immutable List or Set object that is either empty or non-empty, as shown below:

Ex: List immutable list = List.of();

  1. JShell

A new tool named ‘shell’, which stands for Java Shell and is also known as REPL (Read Evaluate Print Loop), has been introduced by Oracle Corp. Java is the latest language to adopt an interactive Read-Eval-Print-Loop, which is already included in many other languages. Executing and testing Java Constructs, such as classes, interfaces, enums, objects, statements, and more, is very easy with this tool.

Starting typing and executing Java code directly is possible with the launch of the shell from the console.

  1. Stream API

Java SE 9 adds four useful new methods to the Oracle Corp. java. util. Stream interface. Stream is an interface, so all newly implemented methods are standard methods. This allows you to create a declarative transformation pipeline for your collection. Four new methods have been added to the stream interface: drop while, take while, and ofNullable. The iterate method gets a new overload, so you can specify a predicate when you need to stop the iteration.

  1. Private Methods in Interfaces

Java 8 allows you to provide method implementations for interfaces using standard methods and static methods. However, you cannot create private methods within an interface. Private methods introduced in Oracle Corp. Java SE 9 interfaces to avoid redundant code and increase reusability. Starting with Java SE 9, you can also write private and private static methods within interfaces using the “private” keyword.

Ex.

public interface Card{               private Long createCardID(){                    // Method implementation goes here.              }               private static void displayCardDetails(){                    // Method implementation goes here.              }       }

  1. Multi-Resolution API

Java SE 9 introduced Oracle Corp.’s new multiresolution image API. The key interface of this API is MultiResolutionImage. This is available in the java.awt.image package. MultiResolutionImage encapsulates a set of images with different heights and widths and allows you to query them according to your needs.

  1. Improvement in Process API

Java SE 9 includes several improvements to the Process API. Several new classes and methods have been added to make it easier to control and manage operating system processes.

Two new interfaces in the Process API:

java. lang.ProcessHandle

java.lang.ProcessHandle.Info

8 HTTP/2 client

Java 9 introduces a new way to make HTTP calls. There are many issues with existing or legacy HTTP client APIs (for example, the HTTP client API supports the HTTP/1.1 protocol instead of HTTP/2 and WebSockets, works only in blocking mode, and has many performance issues. I have a problem). .), replace this HttpURLConnection API with a new HTTP client. They plan to introduce a new HTTP 2 client API under the java.net.http package. Supports both HTTP/1.1 and HTTP/2 protocols. Supports both synchronous (blocking mode) and asynchronous mode. Supports asynchronous mode using WebSocket API.

Ex.

HttpClient client = HttpClient.newHttpClient();        HttpRequest req =       HttpRequest.newBuilder(URI.create(“https://www.google.com”))
.header(“User-Agent”, “Java”)
.GET()
.build();       HttpResponse resp = client.send(req,        HttpResponse.BodyHandler.asString());

Also, Read This Blog- Java Control Statement

For more information & classes Call: 2048553004
Registration Link: Click Here!

Author: Ambarish Durani

JAVA Trainer

IT Education Centre Placement & Training Institute

© Copyright 2023 | IT Education Centre.