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
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”) ));
12. JAVA 9 - OTHER IMPROVEMENTS
▸ Collection improvement
▸ Compact String
▸ Multi Release JAR
▸ JVM based logging
▸ Try With Resource Improvement
▸ CompletableFuture API
▸ Stream API improvement