Java 9 : The Advanced Java SE 9 Platform & Its Dynamic Features

Java 9 release is Expected on 21 September 2017 for general availability. Java Platform Group Chief architect Mark Reinhold delays java 9 citing due to additional time is taken to move through the JCP process is the main cause.

It delay involves the variety of setbacks & issues with its modularization so Java 9 programmer is making modular Java a feature in Java 9. Oracle had set 27 July as the already pushed back release date.

The release date was expected by developers while testing Java9. The early access & build to find issues that affected its release.

1. Project Jigsaw: Java 9 Module System

Java 9 introduces the most important feature modular system which provides capabilities as OSGi framework. It has a dependency concept that can take public API and keep implementation private. One of the main features is to provide modular JVM that can run on devices with less memory.

The JVM runs with those modules and APIs which are necessary for an application. It also offers JVM implementation APIs like com.sun.* is no longer accessible from application code.

 

The Primary Goals of Jigsaw Project

  • Make the Java SE Platform as well as JDK easily scalable down to all small computing devices.
  • To Enhance the security and maintainability of Java Platform Implementations
  • To Enable fast application performance and making easier for developers to make & maintain large libraries & applications for Java SE & Java EE platforms.

 

The modules are going to be described in a file called module-info.java which is to be located in the top of java code hierarchy:

module com.starhead.java9.modules.bike
{
requires com.starhead.java9.modules.engines;
exports com.starhead.java9.modules.bike.handling;
}

 

Our module bike requires module engine to run and exports a package for handling.

The java platform module system introduces the changes & extensions to the Java language, the Java virtual machine as well as in standard Java APIs. A javac compiler, hotspot virtual machine & run-time libraries will implement complete modules as a new kind of Java program component which will provide reliable configuration and high encapsulation of modules in all development phases.

 

The resolution process locates module by using different searching paths in the module system depending upon the phase and also by searching compiled modules such as :

  • The compilation module path specifies by the command-line option –module-source-path contains complete module definitions in source form during compile time only.
  •  An upgrade module path such as –upgrade-module-path contains compiled module definitions which are used replace upgraded modules during compile time and run time.
  • The system modules are the compiled modules offers compile time and run time services which include Java SE and JDK modules.
  • The application module path contains compiled module definitions of library and application modules of all phases.

Read full updates about Jigsaw Project Here

 

2. Java 9 New HTTP Client

 

A bigger replacement to the old HttpURLConnection is a new HTTP Client feature with new functionality to create and send a simple HTTP request. The new API is defined under the java.net.http package. It provides supports for HTTP/2 protocol and WebSocket handshake with offering best performance like Apache HttpClient,& Netty.

 

New HTTP Client prototype API includes :

Separate requests and responses such as Servlet and HTTP server API.

  • Response errorResponse error
  • Response headers received
  • Asynchronous notification events
  • Response error
  • Response body received
  1. Server push HTTP/2
  2. HTTPS using SSLEngine & Proxying
  3. Cookies and Authentication

 

A New HTTP Client Features:

  • The API and implementation will live under the JDK.incubtor namespace & offer notification for events such as errors, response & headers using an asynchronous mechanism like CompletableFuture.
  • A simple and concise API supports all HTTP protocol request to a server as well as the response from a server such as headers, body & status codes etc.
  • It supports HTTP/2 & server push which is the ability of the server to push resources to the client without an explicit request.The application-level semantics of HTTP/2 is similar to 1.1. Therefore, It offers new language features such as lambda expressions.
  • HTTP/1.1 performance depends upon the existing HttpURLConnection implementation & Apache HttpClient library when using a client API.

JDK 9 has defined separate classes for HTTP client, requests, and responses. The builder pattern helps to differentiate mutable entities from the immutable products. A synchronous blocking mode is defined for send and receives services, as well as an asynchronous mode, also define on java.util.concurrent.CompletableFuture.

 

3. Compiler Control & Java 9 Directives

 

Java9 proposes the best method to control JVM compilers which enable runtime manageable method depending compiler flags. A Context Dependent Control is a powerful compilation process for writing the test for small JVM compiler restarting entire JVM. It helps to create work around for bugs in JVM compilers too.

Java 9 controls JVM compilers that contain all set of options with values defined as compiler directives which have an instruction to compile. A directive & VM together decides which methods it applies to different modules. Many directives are active in runtime applied to a specific compilation. The Directives can be add and remove during run time also.

 

Directives :

Directives are a standardized & human readable file format which can be loaded as command line as well as diagnostic command. A directives file can have one or more defined directives which contain one design & method pattern with a number of option values. The compiler Broker applies the first directive whose pattern match to the compilation.

 

Directives Example

 
// Start if array of directives
{ // Start of directive block
// Excactly one match with one or several patterns
// The array is not required with a single pattern
match: ["java*.*", "oracle*.*"], 
// A directives block that only apply to a single compiler
c1: { 
PrintAssembly:true, 
},
// Another compiler block
c2: {
// force inline patters prepended with +, prevent with -
inline: ["+vm*.*","-*.*" ] 
},
// Options outside compiler block apply to all compilers
BreakAtExecute: true // enable break in compiled code 
BreakAtCompile: true // enable break in compiler
},
{ // start of another directives block
// match ant method whose class end with 'Concurrent'
match: ["*Concurrent.*"], 
c2: {
Exclude:true, 
} 
 }

 

Directives patterns :

Directive Method patterns are used in the match & inline option such as Class.method(signature). Class includes package names define by a / Class and method wildcarded with leading defaults to *.

 

Directives parser:

The directives parser helps in parsing the directives file and add information in VM internal format. When the error directives file is specified on the command line then VM will print an error and exit. In the same way when error directives file is added through diagnostic command then it will be ignored & proper warning will be printed. The parser validates all options are valid or not.

 

Compiler Broker:

The compilerBroker supports directives stack which contains complete applied directives. Hence, the bottom directive is set to be default set & never be removed. It is a usability feature, When a new file loaded with additional directives then it will be added in reverse order with the first directive in the top of the stack.

 

4. Java 9 Process API Updates

Java 9 has improved the API to control and manage operating-system processes. Hence, Java SE 9 provides support for native operating-system processes. It offers a basic API to setup the environment for starting the process.

The java.lang.Process:

It is a class which provides process id & information of the process with arguments, commands, start time, CPU time as well as the user name.

The java.lang.ProcessHandle:

It is a class which provides each process information of the operating system which includes process id, arguments, command, start time, etc. ProcessHandles helps to destroy processes and monitor the live process.

ProcessHandle.onExit:

Process Handle is the asynchronous mechanisms of CompletableFuture that helps to schedule the action performed when the process exits.

5. JShell: The Java 9 Shell Interpreter

It provides an interactive shell with JShell API provide JShell’s evaluation functionality to evaluate declarations, statements, as well as expressions of the Java programming with an API. It also helps the other applications to leverage this functionality too.

The JShell state involves code and execution state in order to facilitate rapid investigation and coding, statements and expressions. JShell define as a command line tool which offers features such as editing codes, tab completion, automatic adding semi colon so as to configure predefined definitions.

Functionality JShell:

The code fragments input to the API is known as “snippets”. The Jshell supports & use JShell API to identify whether the input is complete or not using the semicolon in this case the tool will append the semicolon. Hence, Jshell has the complete set of commands such as query, saving & restoring work as well as configuration.

Jshell Wrapping:

In Java9 programming language, all variables, special methods, statements, & expressions must be nested by constructing the class. While implementing, JShell tool compiles a variable, method, statement, and expression snippet as Java code & an artificial context is required such as :

  • Variables, Methods, and Classes: static members of a synthetic class.
  • Expressions and Statements: As expressions and statements within a synthetic static method within a synthetic class.

Snippet Dependencies:

The Jshell code state is necessary to keep update as well as consistent because, when a snippet evaluated, then any changes made to snippets are immediately evolved. When a snippet declared successfully then declaration will be three kinds: Added, Modified, or Replaced.

  • A snippet is Added when the first declared with the key.
  • Snippet is Replaced when its key matches to the previous snippet with different signatures.
  • A snippet is Modified when its key matches to the previous snippet with same signatures.

6. Java SE 9: New Doclet API

The New Doclet API known as Javadoc API which provides an excellent mechanism for clients so as to inspect & recheck the source code of programs and libraries as well as Javadoc comments embedded in the source. Java Doclets invoked by Javadoc too. This API helps to write program information to files. The compilation define by the abstract Doclet class with the start method:

public static boolean start(RootDoc root)

The RootDoc instance indicates the root of the program. It replaces the Doclet API with standard new doc API to improve Java SE and JDK APIs. Doclet API defines under JDK.javadoc.doclet, as well as the new standard doclet refers to the API under JDK.javadoc.doclet.StandardDoclet.

Doclet API Features:

  • It maintains the outdated APIs by eliminating the use of custom language API too.
  • Eliminates support for analyzing documentation comments by Compiler Tree API, com.sun.source.doctree introduces in JDK 8.
  • It replaces the use of “template class” com.sun.javadoc.Doclet with a new interface type.
  • The new Doclet API declared in JDK.javadoc.doclet package. It uses Language Model API & the Compiler Tree API.

The Javadoc tool updates to recognize doclets written with the new Doclet API. The old doclet supports a 2nd plug-in API known as the Taglet API. Taglets provide support to define custom tags used in documentation comments.

7. Html 5 Java Doc Feature

It has enhanced the JavaDoc tool to generate HTML5 markup. It provides an option to standard doclet to request for HTML5 output. The HTML5 markup is semantic which separates the meaning from style and content. The pages generated by the standard doclet using HTML5 markup satisfy accessibility requirements such as:

  • A command-line support added to the standard doclet to request a specific output markup.
  • The structural HTML5 elements such as header, footer, nav, etc. improve the semantic value of generated HTML.
  • HTML5 markup implements the WAI-ARIA standard for accessibility with assigning the specific roles to elements in the HTML using the role attribute.
  • The -Xdoclint feature updated to check documentation comments for errors requested type of output markup.

 

8. C++ Unit-Test Framework

Java9 has encouraged the development of C++ unit tests for HotSpot. The Google Test framework is the C++ unit test framework with complete API which provides IDE integration with Eclipse IDE. It has the feature rich execution model & supports JUnit style test as well as integration with Hudson.

Unit-Test Framework Features

  • It Supports writing & executing unit tests for methods & classes with VM initialization.
  • It offers both positive and negative testing with test isolation as well as integration with the current infrastructure.
  • Provide IDE support that allows the framework to fast fixes the code too.
  • Allow the framework to evolve, including making fast fixes to the framework.
  • It supports test selection as well as test grouping & Allows tests of platform-dependent code.

9. Мulti-Resolution Image API With JWT

Java 9 offers best multi resolution image API interface such as java.awt.image.MultiResolutionImage that encapsulates images with different resolutions into a single object. We can collect resolution image variance in the image based on DPI metric & image transformations as well as can retrieve all variants in the image.

The java.awt.Graphics class take multi resolution image based on display DPI metric with the apply transformations too. The new Image API defined in the java.awt.image package encapsulates images with different resolutions into one complete image as its variants. It takes variants using image variant resolutions in the image so as to represent the logical image on DPI metric.

Have a look at MultiResolutionImage with 2 useful methods:

  1. getResolutionVariant() that returns Image
  2. getResolutionVariants() that returns a list of images

The class java.awt.image.BaseMultiResolutionImage provides implementation as :

BufferedImage[] resolutionVariants = .... 

MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants);

Image testRVImage = bmrImage.getResolutionVariant(16, 16); 

assertSame("Images should be the same", testRVImage, resolutionVariants[3]);

10. Unified JVM Logging With Tags & XLog

This Java 9 feature introduces an easy logging system for all development components of the JVM. Hence, it provides the platform to do the logging, The logging framework provides the complete set of tags in JVM identify by its name such as compiler as well as threads. The set of tags changed in the source code program too. Tag-set provides the feature in which log message added so as to classify the information logged. A tag-set consists of one or more tags.

Logging messages decorated with information such as the possible decorations:

  • time — Current time and date in the ISO-8601 format
  • uptime — Time since the start of the JVM in seconds and milliseconds
  • timemillis — The same value as generated by JVM
  • uptimemillis — Milliseconds time the JVM started
  • timenanos — The same value as generated
  • uptimenanos — Nanoseconds time the JVM started
  • PID — The process identifier
  • tid — The thread identifier
  • level — The level associated with the log message
  • tags — The tag-set associated with the log message

Xlog :

A new command-line option included in Java to control logging from all components of the JVM. The command line parameter -Xlog helps to turn on logging during startup.

Examples

Xlog:all

– log messages use ‘info’ level to stdout
– level ‘info’ and output ‘stdout’ is the default if nothing provided
– the default output of all messages at level ‘warning’ to ‘stderr’

Xlog:gc

– log messages tag with ‘gc’ tag use ‘info’ level to ‘stdout’
– default output all messages at level ‘warning’ to ‘stderr’ effect

Read: Spring Framework 5.0 & Its New Core Reactive Features

Hope you have liked this article, please feel free to provide any suggestions, comments or query. Also, don’t forget to subscribe us on Youtube. You can also find us on Twitter and Facebook.

web design company dehradun best web hostingfree wordpress themes

Leave a Reply

Feature rich hosting with premium support starting at just $3.95/monthGrab this deal

Triple your Traffic!

Grab your free copy of "40 Timeless Ideas to Attract More Visitors to Your Website" that reveals all the practices used to attract tons of visitors.