JAVA 9
ALİCAN AKKUS
JAVA 9
TIMELINE
1.0
1996
1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
1997 1998 2000 2002 2004 2006 2011 2014
1.9
2017
‣ * MODULES

* JSHELL / JLINK

* G1GC

* REACTIVE API
‣ * PROCESS API
‣ * HTTP 2 CLIENT

* OTHERS..
JAVA 9
MODULE SYSTEM
▸ Problems;

(1) : JDK is too big.

* 4240 classes in Java 8

* 4024 classes in Java 7

* 3793 classes in Java 6

(2) : As User can access Internal APIs too, Security is also big issue.

(3) : Its a bit tough to support Less Coupling between components.

▸ Solutions;

Each Module contains only a set of related code and data to support Single Responsibility (Functionality) Principle (SRP).
1. The Moduler JDK

* Java 9 Module System has 73 modules in JDK
2. Modular Source Code
3. Encapsulate Most Internal APIs
4. Java Platform Module System(JPMS)
5. jlink: The Java Linker
JAVA 9 - MODULE SYSTEM
JAVA 9 - MODULE SYSTEM
module com.caysever.java9 {
requires java.logging;
requires jdk.incubator.httpclient;
exports com.caysever.java9.http2client;
}
Module module = moduleInfo.getClass().getModule();
Optional.ofNullable(module).ifPresent(m -> System.out.println(module.getName()));
Optional.ofNullable(module.getDescriptor().requires()).ifPresent(requires ->
Stream.ofNullable(requires).forEach(rs -> rs.forEach(r ->
System.out.println(r.name()))));
com.caysever.java9
java.logging
java.base
jdk.incubator.httpclient
JAVA 9 - JSHELL
▸ JShell introduces a REPL (Read-Eval-Print-Loop) environment in Java.
▸ JShell gives you a prompt (and interactive session history) so that you can type and execute Java
commands.
▸ JShell makes it really easy to write, execute and test fragments of code. So you can perform quick tasks,
test and mockup code.
JAVA 9 - JLINK
▸ Jlink is Java’s new command line tool which allows you to link sets of modules (and their transitive
dependencies) to create a run-time image.
▸ jlink --module-path <modulepath> --add-modules <modules> --limit-modules <modules> --output
<path>
▸ This command creates a run-time image which only has the modules that our application needs.
JAVA 9 - GARBAGE COLLECTOR
▸ With Java 9, the default garbage collector (GC) is being changed from the ParallelGC to the G1GC.
▸ The “Garbage-first” garbage collector, aka G1, is a concurrent multi-threaded GC. It mostly works
alongside the application threads (much like the concurrent mark sweep GC) and is designed to offer
shorter, more predictable pause times – while still achieving high throughput.
▸ G1 also tracks various metrics for each region, and calculates how long it will take to collect them – give it
a target for pause times, and it will attempt to collect as much garbage as it can within the given
constraints.
▸ You can test the G1GC yourself using the VM flag –XX:+UseG1GC.
JAVA 9 - REACTIVE STREAM
▸ Publisher

* Produces items for subscribers to consume. The only method is subscribe(Subscriber) whose purpose
should be obvious.
▸ Subscriber

* Subscribes to publisher(usually only one) to receive items (via method onNext(T)), 

error messages (onError(Throwable)), 

or a signal that no more items are to be expected (onComplete()). 

Before any of those things happen, though, the publisher calls onSubscribe(Subscription)
▸ Subscription

* The connection between a single publisher and a single subscriber. The subscriber will use it to request
more items (request(long)) or to sever the connection (cancel()).
JAVA 9 - PROCESS API
▸ Java SE 9 is coming with some improvements in Process API. They have added couple new classes and
methods to ease the controlling and managing of OS processes.
▸ Sample;

* ProcessHandle.current().pid(); 

* ProcessHandle.allProcesses()

.map(p -> p.info().command())

.filter(Optional::isPresent)

.collect(Collectors.toList())

.forEach(System.out::println);

* new ProcessBuilder().command("sleep", "3").start().onExit().thenAccept(System.out::println);

* ProcessBuilder.startPipeline(List.of(new ProcessBuilder(“ls”), new ProcessBuilder(“sort”,”-u”) ));
JAVA 9 - HTTP 2.0
▸ Still in incubation
▸ Provides support for HTTP 2.0
▸ Sync & Async request
▸ HttpClient, HttpRequest, HttpResponse
HttpClient httpClient = HttpClient.newHttpClient(); 

HttpRequest httpRequest = HttpRequest.newBuilder().uri(“alicanakkus.github.io”).GET().build(); 

HttpResponse<String> httpResponse = httpClient.send(httpRequest, BodyHandler.asString()); 

System.out.println(httpResponse.body());
SYNC
ASYNC httpClient.sendAsync(httpRequest, BodyHandler.asString());
JAVA 9 - OTHER IMPROVEMENTS
▸ Collection improvement
▸ Compact String
▸ Multi Release JAR
▸ JVM based logging
▸ Try With Resource Improvement
▸ CompletableFuture API
▸ Stream API improvement
JAVA 9
▸ http://openjdk.java.net/jeps/0
▸ https://www.journaldev.com/13121/java-9-features-with-examples
▸ www.baeldung.com
▸ www.blog.idrsolutions.com
THANKS :)
https://github.com/AlicanAkkus/java9

Java 9

  • 1.
  • 2.
    JAVA 9 TIMELINE 1.0 1996 1.1 1.21.3 1.4 1.5 1.6 1.7 1.8 1997 1998 2000 2002 2004 2006 2011 2014 1.9 2017 ‣ * MODULES
 * JSHELL / JLINK
 * G1GC
 * REACTIVE API ‣ * PROCESS API ‣ * HTTP 2 CLIENT
 * OTHERS..
  • 3.
    JAVA 9 MODULE SYSTEM ▸Problems;
 (1) : JDK is too big.
 * 4240 classes in Java 8
 * 4024 classes in Java 7
 * 3793 classes in Java 6
 (2) : As User can access Internal APIs too, Security is also big issue.
 (3) : Its a bit tough to support Less Coupling between components.
 ▸ Solutions;
 Each Module contains only a set of related code and data to support Single Responsibility (Functionality) Principle (SRP). 1. The Moduler JDK
 * Java 9 Module System has 73 modules in JDK 2. Modular Source Code 3. Encapsulate Most Internal APIs 4. Java Platform Module System(JPMS) 5. jlink: The Java Linker
  • 4.
    JAVA 9 -MODULE SYSTEM
  • 5.
    JAVA 9 -MODULE SYSTEM module com.caysever.java9 { requires java.logging; requires jdk.incubator.httpclient; exports com.caysever.java9.http2client; } Module module = moduleInfo.getClass().getModule(); Optional.ofNullable(module).ifPresent(m -> System.out.println(module.getName())); Optional.ofNullable(module.getDescriptor().requires()).ifPresent(requires -> Stream.ofNullable(requires).forEach(rs -> rs.forEach(r -> System.out.println(r.name())))); com.caysever.java9 java.logging java.base jdk.incubator.httpclient
  • 6.
    JAVA 9 -JSHELL ▸ JShell introduces a REPL (Read-Eval-Print-Loop) environment in Java. ▸ JShell gives you a prompt (and interactive session history) so that you can type and execute Java commands. ▸ JShell makes it really easy to write, execute and test fragments of code. So you can perform quick tasks, test and mockup code.
  • 7.
    JAVA 9 -JLINK ▸ Jlink is Java’s new command line tool which allows you to link sets of modules (and their transitive dependencies) to create a run-time image. ▸ jlink --module-path <modulepath> --add-modules <modules> --limit-modules <modules> --output <path> ▸ This command creates a run-time image which only has the modules that our application needs.
  • 8.
    JAVA 9 -GARBAGE COLLECTOR ▸ With Java 9, the default garbage collector (GC) is being changed from the ParallelGC to the G1GC. ▸ The “Garbage-first” garbage collector, aka G1, is a concurrent multi-threaded GC. It mostly works alongside the application threads (much like the concurrent mark sweep GC) and is designed to offer shorter, more predictable pause times – while still achieving high throughput. ▸ G1 also tracks various metrics for each region, and calculates how long it will take to collect them – give it a target for pause times, and it will attempt to collect as much garbage as it can within the given constraints. ▸ You can test the G1GC yourself using the VM flag –XX:+UseG1GC.
  • 9.
    JAVA 9 -REACTIVE STREAM ▸ Publisher
 * Produces items for subscribers to consume. The only method is subscribe(Subscriber) whose purpose should be obvious. ▸ Subscriber
 * Subscribes to publisher(usually only one) to receive items (via method onNext(T)), 
 error messages (onError(Throwable)), 
 or a signal that no more items are to be expected (onComplete()). 
 Before any of those things happen, though, the publisher calls onSubscribe(Subscription) ▸ Subscription
 * The connection between a single publisher and a single subscriber. The subscriber will use it to request more items (request(long)) or to sever the connection (cancel()).
  • 10.
    JAVA 9 -PROCESS API ▸ Java SE 9 is coming with some improvements in Process API. They have added couple new classes and methods to ease the controlling and managing of OS processes. ▸ Sample;
 * ProcessHandle.current().pid(); 
 * ProcessHandle.allProcesses()
 .map(p -> p.info().command())
 .filter(Optional::isPresent)
 .collect(Collectors.toList())
 .forEach(System.out::println);
 * new ProcessBuilder().command("sleep", "3").start().onExit().thenAccept(System.out::println);
 * ProcessBuilder.startPipeline(List.of(new ProcessBuilder(“ls”), new ProcessBuilder(“sort”,”-u”) ));
  • 11.
    JAVA 9 -HTTP 2.0 ▸ Still in incubation ▸ Provides support for HTTP 2.0 ▸ Sync & Async request ▸ HttpClient, HttpRequest, HttpResponse HttpClient httpClient = HttpClient.newHttpClient(); 
 HttpRequest httpRequest = HttpRequest.newBuilder().uri(“alicanakkus.github.io”).GET().build(); 
 HttpResponse<String> httpResponse = httpClient.send(httpRequest, BodyHandler.asString()); 
 System.out.println(httpResponse.body()); SYNC ASYNC httpClient.sendAsync(httpRequest, BodyHandler.asString());
  • 12.
    JAVA 9 -OTHER IMPROVEMENTS ▸ Collection improvement ▸ Compact String ▸ Multi Release JAR ▸ JVM based logging ▸ Try With Resource Improvement ▸ CompletableFuture API ▸ Stream API improvement
  • 13.
    JAVA 9 ▸ http://openjdk.java.net/jeps/0 ▸https://www.journaldev.com/13121/java-9-features-with-examples ▸ www.baeldung.com ▸ www.blog.idrsolutions.com THANKS :) https://github.com/AlicanAkkus/java9