Top Java 9 Features That Will Change The Way You Build Software

30 Aug. 2017 Software Development

The upcoming version of Java is just around the corner. The core Java programmers at Oracle are currently working hard to rigorously test and fix bugs for the general availability of Java 9, tentatively scheduled for September 21, 2017.

Java Development Kit (JDK) 9 is expected to feature modularity, new capabilities, and performance tweaks. It will also come packed with a read-eval-print loop, smart compilation, and a memory-saving improvement.

All About New JDK 9 Features

Java 9: What’s New For Developers

Need Help!Talk to our Java experts for custom software development

So, while the Java committers chalk up the plans for Java 9’s official release, let’s take a look at some of the most intriguing JDK 9 features.

  • Modular System:
    Modularity is most anticipated among the new Java 9 features. A modular system includes capabilities similar to an OSGi framework system. It is a general concept of dependencies that enables writing and implementing a program or computing system as a number of modules instead of a single, monolithic design.

    Inspired by Project Jigsaw, the module system in Java 9 is aimed at making JDK scalable to smaller devices. It lets an application use only the required JDK modules instead of using an entire JDK framework. The modular system also encapsulates the public classes within a module so that a public class is not available easily until a module explicitly defines so. As a result, the internal Java API com.sun.* will no longer be available by default.

    In simple words, the modules will be described in a file called module-info.java which is located at the root of the module’s code file hierarchy:

    module me.aboullaite.java9.modules.car {
    requires me.aboullaite.java9.modules.engines;
    exports me.aboullaite.java9.modules.car.handling;
    }

    Your module car will require a module engine to run and export the package for handling. Go through Open JDK Project Jigsaw – Module system Guide for a detailed example.

  • JShell – the Interactive Java REPL:
    REPL is an acronym for Read-Evaluate-Print Loop. It is a command line tool (also known as jshell) that helps to quickly evaluate declarations, expressions, and statements of Java alongside an API. It is a convenient method of testing small code snippets which otherwise requires Java developers to create a new class using the main method. The jshell executable is located within the /bin folder:

    jdk-9\bin>jshell.exe
    | Welcome to JShell — Version 9
    | For an introduction type: /help intro
    jshell> “This is my long string. I want a part of it”.substring(8,19);
    $5 ==> “my long string”

    The interactive tool also comes with history and auto-completion. It includes functionalities such as saving to and loading from files, all or a number of written statements:

    jshell> /save c:\develop\JShell_hello_world.txt
    jshell> /open c:\develop\JShell_hello_world.txt
    Hello JShell!

    The execution of code snippets occurs upon file loading.

  • HTTP 2 Client:
    A new HTTP client is a long-awaited feature to replace the legacy HTTPURLConnection API. It supports HTTP 2.0 and web sockets and delivers performance that is comparable with the Apache HttpClient, Jetty, and Netty. However, the HTTP Client JEP will no longer be available in the java.net.http package. It will be moved to the Incubator module and available under jdk.incubator.http. You can start using the API with Java 9 as shown below.

    HttpClient client = HttpClient.newHttpClient();

    HttpRequest req =
    HttpRequest.newBuilder(URI.create(“https://www.rishabhsoft.com”))
    .header(“User-Agent”,”Java”)
    .GET()
    .build();

    HttpResponse resp = client.send(req, HttpResponse.BodyHandler.asString());

    Apart from creating an HTTPRequest and getting an asynchronous response, HttpClient also offers new APIs that work with HTTP 2.0 features like streams and server push.

  • Conclusion
    The official release will unleash a wide array of new features in Java 9. In addition, Oracle is offering an early availability for those looking to download and test the latest Java platform.

    Get a Free ConsultationGet in touch with us to build an application using Java 9
Follow Us
Subscribe to the Blog
Get a Free Consultation
Reach out to our team to get a free consultation for your next project Contact Us