9 Best Java 9 Features explained - Java 9 Tutorials

Submitted by techyboy on Mon, 01/15/2018 - 12:29
coffee cup java 9 symbol

No doubt, Java is the most popular programming language in the present computer world. Oracle is going to stop updates to Java 8 or Java SE 8 after september 2018. It is essential to experiment with Java 9 or Java SE 9. As a java developer, you need to distinguish Java 9 from Java 8, Java 7 and so on. Java 9 release date is already over. So, we prepare you to know the best Java 9 features and its uses.

Java 9 Features

Java 9 has many new features that may change the way you write and test your Java Code. New Java 9 features are from categories like Tools, Security, Core Libraries, Deployment, JVM, Nashorn and all.

1. JShell

JShell  or Java Shell is a tool to learn java programming skills with prototyping and syntax. This is just like a command prompt console with jshell> waiting for user interaction. You can write a complete java program instead of a snippet. JShell compiles the program, runs it and shows messages for easy understanding. JShell is a Read-Evaluate-Print Loop (REPL) which evaluates statements or program as they are entered and shows the results.

Start JShell

> jshell

Stop JShell

jshell> /exit

 

2. Factory Methods for Collections

One of the best useful feature of this Java 9 Features post, is the provision of Factory Methods to create and initialise collection objects. Map, List and Set immutable objects can be created in a single line of code.

Examples

List stringList = List.of("a", "b", "c");

Set<String> stringSet = Set.of("a", "b", "c");

Map stringMap = Map.of("a", 1, "b", 2, "c", 3);

 

3. Java Platform Module System

A module is a collection of Code and Data. Java Platform Module System is an important part of Java 9 features. Java Standard Edition Development Kit (JDK) is intern divided into a number of small modules which can be added at compile time without any hassle. Loading and combining only required modules reduce memory footprint and processing power. It is almost equivalent to Java Compact Profiles introduced by Java 8. Provide your custom module paths to Java, Javac and JLink command line  tools to use them.

Java Platform Module System introduced a slight variant of JAR file called Modular Jar File with module-info.class file at its root directory. One more addition is JMOD packaging format to pack Native Files and Configuration Files. Even JDK and JRE work on this modules system. By default, only a few useful modules are enabled in the JDK. User can add more modules if required.

 

4. Multi Release JAR Files

Multi Release JAR (MRJAR) contains additional directories with classes and resources specific to a particular Java Version. Use JAR tools with --release option.

MRJAR Multi Release JAR file structure

 

5. Removal of Support for Underscore ( _ ) for Java 9 Identifiers

One of the best Java 9 Features is the removal of support for Underscore Symbol as part of an identifier. Identifier is simply a variable name, method name, class name, interface name or a package name. If you have older code, replace all underscores with some character or empty literal to successfully compile your java program.

 

6. Java 9 Try With Resource Statement

One of the Java 9 features that simplify your exception handling code is Java 9 Try With Resource i.e try ( resource ). If you have final variables which are already declared and initialized, you can directly use those resources with in parentheses. Earlier versions of Java like Java 8 and Java 7 insist us to declare the variables with in try parentheses it self. 

In Java 7 and Java 8, you write:

try( Resource resource1 = new Resource(); Resource resource2 = new Resource() )

{

....

}

 

java 9 try with resource

 

7. Multi Resolution Images and Support for TIFF Image IO

Image display has been given more priority when introducing new Java 9 Features by Oracle. In an Android App, developer defines multiple images with the same name but different DPI (Dots Per Inch) so that higher DPI displays pick a better image for display. Java 9 adopted the same functionality. Multiple Images can be combined into a single collection of images. User can provide DPI of the Device ( Desktop Monitor or Laptop Monitor usually ) to retrieve the suitable resolution image.

Also, java 9 Image IO includes support for TIFF image operations like reading and writing. HiDPI graphics support for Windows and Linux systems has been added to automatically scale AWT (Abstract Window Toolkit) components for better visibility on big screens.

 

8. Unicode 8.0 Support

Unicode is the reason why all smart phones display text of most of the languages and popular Emojis. Unicode evolves, adds new symbols and languages for world wide usage. Java 8 supported up to Unicode 6.2. Java 9 has added advantage of new 10555 characters, 29 scripts and 42 blocks with the support of Unicode 8.0. Thanks to Oracle for introducing this Unicode 8.0 support as part of new Java 9 Features. 

java 9 unicode 8.0 new symbols

 

9. Java 9 Process API

Java 9 Process API lets you retrieve information about the running Operating System Processes. You can iterate through all processes, get info like Process ID, usage statistics and log the output. Unless you implement SecurityManager, sensitive information and requests will not be available to this Process API.

There are plenty of new features introduces in Java 9 like Nashorn ECMA support, Compact String, UTF-8 Configuration Files, Web Deployment options and all. We have chosen only the above as the 9 Best Java 9 Features as part of our first Java 9 Tutorial. We will come back with more Java Tutorials in coming months.

 

Java 8 Download

Latest version of Java 8 available for download is Java 8u151 / Java 8u152.

Java 9 Download

Latest version of Java 9 or JDK 9 available for download is Java 9.0.1.

 

You can also read

1. How to a Create Bootable Pendrive with command prompt

2. How to get BSNL Call Details Online / Offline

3. How to use BSNL Prepaid Selfcare Portal  - BSNLSZPREPAID

4. How to Unlock Bootloader of Redmi Note 3 Easily

 

Add new comment

Related Content