SlideShare a Scribd company logo
www.luxoft.com
From Java 9 to Java 12.
Brief Overview
Petro Gordiievych
www.luxoft.com 2
www.luxoft.com 3
www.luxoft.com 4
Java 9
www.luxoft.com
Java 9
• Modular system – Jigsaw Project
• A new HTTP Client
• Process API
• Small language modifications
• Jshell Command Line Tool
• JCMD Sub-Commands
• Multi-Resolution Image API
• Variable Handles
• Publish-Subscribe Framework
• Unified JVM Logging
• New APIs
www.luxoft.com
Java 9 :: Java Platform Module System (JPMS)
• Module—a uniquely named, reusable group of related packages, as well as resources (such as
images and XML files) and a module descriptor specifying
• the module’s name
• the module’s dependencies (that is, other modules this module depends on)
• the packages it explicitly makes available to other modules (all other packages in the module
are implicitly unavailable to other modules)
• the services it offers
• the services it consumes
• to what other modules it allows reflection
www.luxoft.com
Java 9 :: Modules Types
• System Modules – These are the modules listed when we run the list-modules command above.
They include the Java SE and JDK modules.
• Application Modules – These modules are what we usually want to build when we decide to use
Modules. They are named and defined in the compiled module-info.class file included in the
assembled JAR.
• Automatic Modules – We can include unofficial modules by adding existing JAR files to the module
path. The name of the module will be derived from the name of the JAR. Automatic modules will
have full read access to every other module loaded by the path.
• Unnamed Module – When a class or JAR is loaded onto the classpath, but not the module path, it's
automatically added to the unnamed module. It's a catch-all module to maintain backward
compatibility with previously-written Java code.
www.luxoft.com
Java 9 :: Module declaration
• module com.luxoft.logeeknight {
exports com.luxoft.logeeknight.slides;
requires com.luxoft.pgordiievych;
requires public com.luxoft.calendar;
requires guava;
}
• jlink – allows create custom runtime image
www.luxoft.com
Java 9 :: New HTTP Client
HttpURLConnection -> HttpClient
(jdk.incubator.http.HttpClient)
It supports both HTTP/2 protocol and WebSocket handshake, with performance that should be
comparable with the Apache HttpClient, Netty and Jetty.
HttpRequest request2 = HttpRequest.newBuilder()
.uri(new URI("https://postman-echo.com/get"))
.header("key1", "value1")
.header("key2", "value2")
.GET()
.build();
www.luxoft.com
Java 9 :: Process API
• java.lang.ProcessHandle
• ProcessHandle self = ProcessHandle.current();
• long PID = self.getPid();
• ProcessHandle.Info procInfo = self.info();
• Optional<String[]> args = procInfo.arguments();
• Optional<String> cmd = procInfo.commandLine();
• Optional<Instant> startTime = procInfo.startInstant();
• Optional<Duration> cpuUsage = procInfo.totalCpuDuration();
• Destroying processes:
childProc = ProcessHandle.current().children();
childProc.forEach(procHandle -> {
assertTrue("Could not kill process " + procHandle.getPid(), procHandle.destroy());
});
www.luxoft.com
Java 9 :: Jshell Command Line tool
• Read-Eval-Print Loop (REPL)
www.luxoft.com
Java 9 :: Unified JVM Logging
• java -Xlog:gc=debug:file=gc.txt:none ...
• jcmd 9615 VM.log output=gc_logs what=gc
• -Xlog:help will output possible options and examples.
• Messages forwarding: java -Xlog:all=debug:file=application.log -version
• Messages decorators: java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version
www.luxoft.com
Java 9 :: Unified JVM Logging
• java -Xlog:gc=debug:file=gc.txt –version
13
www.luxoft.com
Java 9 :: Unified JVM Logging
• java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version
14
www.luxoft.com
Java 9 :: Publish-Subscribe Framework
These interfaces correspond to the reactive-streams specification. They apply in both concurrent and
distributed asynchronous settings: All (seven) methods are defined in void "one-way" message style.
• static interface Flow.Processor<T,R> - A component that acts as both a Subscriber and Publisher.
• static interface Flow.Publisher<T> - A producer of items (and related control messages) received by
Subscribers.
• static interface Flow.Subscriber<T> - A receiver of messages.
• static interface Flow.Subscription - Message control linking a Flow.Publisher and Flow.Subscriber.
www.luxoft.com
Java 9 :: Publish-Subscribe Framework
@FunctionalInterface
public static interface Flow.Publisher<T> {
public void subscribe(Flow.Subscriber<? super T> subscriber);
}
public static interface Flow.Subscriber<T> {
public void onSubscribe(Flow.Subscription subscription);
public void onNext(T item) ;
public void onError(Throwable throwable) ;
public void onComplete() ;
}
public static interface Flow.Subscription {
public void request(long n);
public void cancel() ;
}
public static interface Flow.Processor<T,R> extends Flow.Subscriber<T>, Flow.Publisher<R> {
}
www.luxoft.com
Java 9 :: New APIs
• java.util.Set.of()
• Set<String> strKeySet = Set.of("key1", "key2", "key3");
• java.util.Optional.stream()
• List<String> filteredList = listOfOptionals.stream()
.flatMap(Optional::stream)
.collect(Collectors.toList());
www.luxoft.com 18
Java 10
www.luxoft.com
Java 10
• Local-Variable Type Inference
• Unmodifiable Collections
• Optional *.orElseThrow()
• Performance Improvements
• Container Awareness
• Root Certificates
• Deprecation and Removals
• Time-Based Release Versioning
www.luxoft.com
Java 10 :: Local-Variable Type Inference
• Java 9: String message = “Hi there!”;
• Java 10: var message = “Hi there!”;
• Compiller infers the type of message from the type of initializer present on the right-hand
side
• var dict = new HashMap<String, String>();
• Illegal to use in cases:
• var x;
• var emptyList = null;
• public var x = “test”;
• var p = (String x) -> s.length() < 5;
• var arr = {”x”, “y”, “z”};
www.luxoft.com
Java 10 :: Unmodifiable Collections
• java.util.List:<E> List<E> copyOf(Collection<? extends E> coll)
• java.util.Set:<E> Set<E> copyOf(Collection<? extends E> coll)
• java.util.Map:<K,V> Map<K,V> copyOf(Map<? extends K, ? extends V> coll)
• UnsupportedOperationException throws
www.luxoft.com
Java 10 :: Time-Based Release Versioning
• Each major release of the Java platform will occur every 6 months (March and September)
• Update releases will occur every quarter (January, April, July, October)
• Long Term Release (LTS) – updates for releases will be available for at least three years
• Version format: $FEATURE.$INTERIM.$UPDATE.$PATCH
www.luxoft.com 23
Java 11
www.luxoft.com
Java 11
• Local-Variable Syntax for Lambda Parameters
• Launch Single-File Source Code Programs (JEP)
• HTTP Client
• Remove The Java EE and CORBA Module
• Dynamic Class-File Constants
• The Epsilon GC
• Flight Recorder
www.luxoft.com
Java 11 :: Local-Variable Syntax for Lambda Parameters
list.stream() .map((var s) -> s.toLowerCase()) .collect(Collectors.toList());
Why? If could be simple:
list.stream() .map(s -> s.toLowerCase()) .collect(Collectors.toList());
But:
list.stream() .map((@Notnull var s) -> s.toLowerCase()) .collect(Collectors.toList());
www.luxoft.com
Java 11 :: Launch Single-File Source Code Programs
(JEP)
java HelloWorld.java
java -classpath /home/foo/java Hello.java Luxoft
Is equal to:
javac -classpath /home/foo/java Hello.java
java -classpath /home/foo/java Hello Luxoft
www.luxoft.com
Java 11 :: Dynamic Class-File Constants
• *.class format extension described support CONSTANT_Dynamic (condy)
• Using bootstrap method to define values
• java.lang.invoke.ConstantBootstraps
www.luxoft.com 28
Java 12
www.luxoft.com
Java 12
• Switch Case
• Streams API
• Other
www.luxoft.com
Java 12 :: Switch Case
T result = switch (arg) {
case L1 -> e1;
case L2 -> e2;
default -> e3;
};
int j = switch (day) {
case MONDAY -> 0;
case TUESDAY -> 1;
default -> {
int k = day.toString().length();
int result = f(k);
break result;
}
};
www.luxoft.com
Java 12 :: Streams API has new Collector
public static <T,​R1,​R2,​R> Collector<T,​?,​R> teeing​(Collector<? super T,​?,​R1> downstream1, Collector<?
super T,​?,​R2> downstream2, BiFunction<? super R1,​? super R2,​R> merger)
var result = Stream.of("Devoxx", "Voxxed Days", "Code One", "Basel One", "Angular Connect")
.collect(
Collectors.teeing(
Collectors.filtering(n -> n.contains("xx"),
Collectors.toList()),
Collectors.filtering(n -> n.endsWith("One"), Collectors.toList()),
(List<String> list1, List<String> list2) -> List.of(list1, list2)
)
); System.out.println(result);
// -> [[Devoxx, Voxxed Days], [Code One, Basel One]]
www.luxoft.com
Java 12 :: Other
• InputStream skipNBytes(long n)
• java.lang.constant
• java.lang.Character
• java.lang.Class – arrayType()
• java.lang.String (indent(), transform())
www.luxoft.com 33www.luxoft.com
References
• https://www.oracle.com/corporate/features/understanding-java-9-modules.html
• https://www.baeldung.com/java-9-http-client
• https://docs.oracle.com/javase/9/docs/api/jdk/incubator/http/HttpClient.html
• https://openjdk.java.net/jeps/325
• https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/stream/Collectors.html
• https://dzone.com/articles/a-new-jdk12-stream-api-collection-collectorsteeing
• https://www.baeldung.com/new-java-9
• https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html
• https://openjdk.java.net/jeps/110
• https://openjdk.java.net/projects/jigsaw/
www.luxoft.com
Thank you!

More Related Content

What's hot (20)

PDF
Introduction to Retrofit and RxJava
Fabio Collini
 
PDF
JDK 11
Ilya Lapitan
 
PDF
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
PDF
What is new in java 8 concurrency
kshanth2101
 
PPTX
Java ain't scary - introducing Java to PL/SQL Developers
Lucas Jellema
 
PDF
Reaching the lambda heaven
Víctor Leonel Orozco López
 
ODP
JUDCON India 2014 Java EE 7 talk
Vijay Nair
 
PPTX
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
PPTX
Java 9 Module System Introduction
Dan Stine
 
PPTX
Java 9
Joanna Sokołowicz
 
PDF
Apache Flink Stream Processing
Suneel Marthi
 
PDF
Apache Aries Overview
Ian Robinson
 
TXT
Changes
tony
 
PPTX
Shipping your logs to elk from mule app/cloudhub part 2
Alex Fernandez
 
PPTX
SLF4J+Logback
Guo Albert
 
ODP
Http programming in play
Knoldus Inc.
 
PDF
Play Framework
Harinath Krishnamoorthy
 
PPTX
Kafka Connect
Oleg Kuznetsov
 
PDF
WebTalk - Implementing Web Services with a dedicated Java daemon
Geert Van Pamel
 
PDF
Short intro to scala and the play framework
Felipe
 
Introduction to Retrofit and RxJava
Fabio Collini
 
JDK 11
Ilya Lapitan
 
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
What is new in java 8 concurrency
kshanth2101
 
Java ain't scary - introducing Java to PL/SQL Developers
Lucas Jellema
 
Reaching the lambda heaven
Víctor Leonel Orozco López
 
JUDCON India 2014 Java EE 7 talk
Vijay Nair
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Java 9 Module System Introduction
Dan Stine
 
Apache Flink Stream Processing
Suneel Marthi
 
Apache Aries Overview
Ian Robinson
 
Changes
tony
 
Shipping your logs to elk from mule app/cloudhub part 2
Alex Fernandez
 
SLF4J+Logback
Guo Albert
 
Http programming in play
Knoldus Inc.
 
Play Framework
Harinath Krishnamoorthy
 
Kafka Connect
Oleg Kuznetsov
 
WebTalk - Implementing Web Services with a dedicated Java daemon
Geert Van Pamel
 
Short intro to scala and the play framework
Felipe
 

Similar to Petro Gordiievych "From Java 9 to Java 12" (20)

PPTX
Liferay (DXP) 7 Tech Meetup for Developers
Azilen Technologies Pvt. Ltd.
 
PPTX
New Features in JDK 8
Martin Toshev
 
PPTX
New features in jdk8 iti
Ahmed mar3y
 
PPT
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
PPTX
Reactive for the Impatient - Mary Grygleski
PolyglotMeetups
 
PPTX
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
StreamNative
 
PPTX
Clojure Fundamentals Course For Beginners
Paddy Lock
 
PDF
Java one2013
Aleksei Kornev
 
PDF
Building Scalable Stateless Applications with RxJava
Rick Warren
 
PPTX
Advance Java Topics (J2EE)
slire
 
PDF
FFM / Panama: A case study with OpenSSL and Tomcat
Jean-Frederic Clere
 
PDF
Java 8 Overview
Nicola Pedot
 
PDF
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
Getting value from IoT, Integration and Data Analytics
 
PPT
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
PPTX
Lambdas and Laughs
Jim Bethancourt
 
PDF
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Apex
 
PDF
What to expect from Java 9
Ivan Krylov
 
PPTX
Java 9 sneak peek
Martin Toshev
 
PDF
Java Web Services [4/5]: Java API for XML Web Services
IMC Institute
 
PPT
Shopzilla On Concurrency
Rodney Barlow
 
Liferay (DXP) 7 Tech Meetup for Developers
Azilen Technologies Pvt. Ltd.
 
New Features in JDK 8
Martin Toshev
 
New features in jdk8 iti
Ahmed mar3y
 
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
Reactive for the Impatient - Mary Grygleski
PolyglotMeetups
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
StreamNative
 
Clojure Fundamentals Course For Beginners
Paddy Lock
 
Java one2013
Aleksei Kornev
 
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Advance Java Topics (J2EE)
slire
 
FFM / Panama: A case study with OpenSSL and Tomcat
Jean-Frederic Clere
 
Java 8 Overview
Nicola Pedot
 
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
Getting value from IoT, Integration and Data Analytics
 
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Lambdas and Laughs
Jim Bethancourt
 
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Apex
 
What to expect from Java 9
Ivan Krylov
 
Java 9 sneak peek
Martin Toshev
 
Java Web Services [4/5]: Java API for XML Web Services
IMC Institute
 
Shopzilla On Concurrency
Rodney Barlow
 
Ad

More from LogeekNightUkraine (20)

PPTX
Face recognition with c++
LogeekNightUkraine
 
PPTX
C++20 features
LogeekNightUkraine
 
PPTX
Autonomous driving on your developer pc. technologies, approaches, future
LogeekNightUkraine
 
PDF
Orkhan Gasimov "High Performance System Design"
LogeekNightUkraine
 
PPTX
Vitalii Korzh "Managed Workflows or How to Master Data"
LogeekNightUkraine
 
PDF
Yevhen Tatarynov "From POC to High-Performance .NET applications"
LogeekNightUkraine
 
PDF
Oleksii Kuchuk "Reading gauge values with open cv imgproc"
LogeekNightUkraine
 
PDF
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
LogeekNightUkraine
 
PDF
Pavlo Zhdanov "Mastering solid and base principles for software design"
LogeekNightUkraine
 
PDF
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
LogeekNightUkraine
 
PDF
Iurii Antykhovych "Java and performance tools and toys"
LogeekNightUkraine
 
PDF
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
LogeekNightUkraine
 
PPTX
Aleksandr Kutsan "Managing Dependencies in C++"
LogeekNightUkraine
 
PDF
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
LogeekNightUkraine
 
PDF
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"
LogeekNightUkraine
 
PPTX
Michal Kordas "Docker: Good, Bad or Both"
LogeekNightUkraine
 
PPTX
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
LogeekNightUkraine
 
PPTX
Shestakov Illia "The Sandbox Theory"
LogeekNightUkraine
 
PPTX
Dmytro Kochergin “Autotest with CYPRESS”
LogeekNightUkraine
 
PPTX
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
LogeekNightUkraine
 
Face recognition with c++
LogeekNightUkraine
 
C++20 features
LogeekNightUkraine
 
Autonomous driving on your developer pc. technologies, approaches, future
LogeekNightUkraine
 
Orkhan Gasimov "High Performance System Design"
LogeekNightUkraine
 
Vitalii Korzh "Managed Workflows or How to Master Data"
LogeekNightUkraine
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
LogeekNightUkraine
 
Oleksii Kuchuk "Reading gauge values with open cv imgproc"
LogeekNightUkraine
 
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
LogeekNightUkraine
 
Pavlo Zhdanov "Mastering solid and base principles for software design"
LogeekNightUkraine
 
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
LogeekNightUkraine
 
Iurii Antykhovych "Java and performance tools and toys"
LogeekNightUkraine
 
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
LogeekNightUkraine
 
Aleksandr Kutsan "Managing Dependencies in C++"
LogeekNightUkraine
 
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
LogeekNightUkraine
 
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"
LogeekNightUkraine
 
Michal Kordas "Docker: Good, Bad or Both"
LogeekNightUkraine
 
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
LogeekNightUkraine
 
Shestakov Illia "The Sandbox Theory"
LogeekNightUkraine
 
Dmytro Kochergin “Autotest with CYPRESS”
LogeekNightUkraine
 
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
LogeekNightUkraine
 
Ad

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Digital Circuits, important subject in CS
contactparinay1
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 

Petro Gordiievych "From Java 9 to Java 12"

  • 1. www.luxoft.com From Java 9 to Java 12. Brief Overview Petro Gordiievych
  • 5. www.luxoft.com Java 9 • Modular system – Jigsaw Project • A new HTTP Client • Process API • Small language modifications • Jshell Command Line Tool • JCMD Sub-Commands • Multi-Resolution Image API • Variable Handles • Publish-Subscribe Framework • Unified JVM Logging • New APIs
  • 6. www.luxoft.com Java 9 :: Java Platform Module System (JPMS) • Module—a uniquely named, reusable group of related packages, as well as resources (such as images and XML files) and a module descriptor specifying • the module’s name • the module’s dependencies (that is, other modules this module depends on) • the packages it explicitly makes available to other modules (all other packages in the module are implicitly unavailable to other modules) • the services it offers • the services it consumes • to what other modules it allows reflection
  • 7. www.luxoft.com Java 9 :: Modules Types • System Modules – These are the modules listed when we run the list-modules command above. They include the Java SE and JDK modules. • Application Modules – These modules are what we usually want to build when we decide to use Modules. They are named and defined in the compiled module-info.class file included in the assembled JAR. • Automatic Modules – We can include unofficial modules by adding existing JAR files to the module path. The name of the module will be derived from the name of the JAR. Automatic modules will have full read access to every other module loaded by the path. • Unnamed Module – When a class or JAR is loaded onto the classpath, but not the module path, it's automatically added to the unnamed module. It's a catch-all module to maintain backward compatibility with previously-written Java code.
  • 8. www.luxoft.com Java 9 :: Module declaration • module com.luxoft.logeeknight { exports com.luxoft.logeeknight.slides; requires com.luxoft.pgordiievych; requires public com.luxoft.calendar; requires guava; } • jlink – allows create custom runtime image
  • 9. www.luxoft.com Java 9 :: New HTTP Client HttpURLConnection -> HttpClient (jdk.incubator.http.HttpClient) It supports both HTTP/2 protocol and WebSocket handshake, with performance that should be comparable with the Apache HttpClient, Netty and Jetty. HttpRequest request2 = HttpRequest.newBuilder() .uri(new URI("https://postman-echo.com/get")) .header("key1", "value1") .header("key2", "value2") .GET() .build();
  • 10. www.luxoft.com Java 9 :: Process API • java.lang.ProcessHandle • ProcessHandle self = ProcessHandle.current(); • long PID = self.getPid(); • ProcessHandle.Info procInfo = self.info(); • Optional<String[]> args = procInfo.arguments(); • Optional<String> cmd = procInfo.commandLine(); • Optional<Instant> startTime = procInfo.startInstant(); • Optional<Duration> cpuUsage = procInfo.totalCpuDuration(); • Destroying processes: childProc = ProcessHandle.current().children(); childProc.forEach(procHandle -> { assertTrue("Could not kill process " + procHandle.getPid(), procHandle.destroy()); });
  • 11. www.luxoft.com Java 9 :: Jshell Command Line tool • Read-Eval-Print Loop (REPL)
  • 12. www.luxoft.com Java 9 :: Unified JVM Logging • java -Xlog:gc=debug:file=gc.txt:none ... • jcmd 9615 VM.log output=gc_logs what=gc • -Xlog:help will output possible options and examples. • Messages forwarding: java -Xlog:all=debug:file=application.log -version • Messages decorators: java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version
  • 13. www.luxoft.com Java 9 :: Unified JVM Logging • java -Xlog:gc=debug:file=gc.txt –version 13
  • 14. www.luxoft.com Java 9 :: Unified JVM Logging • java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version 14
  • 15. www.luxoft.com Java 9 :: Publish-Subscribe Framework These interfaces correspond to the reactive-streams specification. They apply in both concurrent and distributed asynchronous settings: All (seven) methods are defined in void "one-way" message style. • static interface Flow.Processor<T,R> - A component that acts as both a Subscriber and Publisher. • static interface Flow.Publisher<T> - A producer of items (and related control messages) received by Subscribers. • static interface Flow.Subscriber<T> - A receiver of messages. • static interface Flow.Subscription - Message control linking a Flow.Publisher and Flow.Subscriber.
  • 16. www.luxoft.com Java 9 :: Publish-Subscribe Framework @FunctionalInterface public static interface Flow.Publisher<T> { public void subscribe(Flow.Subscriber<? super T> subscriber); } public static interface Flow.Subscriber<T> { public void onSubscribe(Flow.Subscription subscription); public void onNext(T item) ; public void onError(Throwable throwable) ; public void onComplete() ; } public static interface Flow.Subscription { public void request(long n); public void cancel() ; } public static interface Flow.Processor<T,R> extends Flow.Subscriber<T>, Flow.Publisher<R> { }
  • 17. www.luxoft.com Java 9 :: New APIs • java.util.Set.of() • Set<String> strKeySet = Set.of("key1", "key2", "key3"); • java.util.Optional.stream() • List<String> filteredList = listOfOptionals.stream() .flatMap(Optional::stream) .collect(Collectors.toList());
  • 19. www.luxoft.com Java 10 • Local-Variable Type Inference • Unmodifiable Collections • Optional *.orElseThrow() • Performance Improvements • Container Awareness • Root Certificates • Deprecation and Removals • Time-Based Release Versioning
  • 20. www.luxoft.com Java 10 :: Local-Variable Type Inference • Java 9: String message = “Hi there!”; • Java 10: var message = “Hi there!”; • Compiller infers the type of message from the type of initializer present on the right-hand side • var dict = new HashMap<String, String>(); • Illegal to use in cases: • var x; • var emptyList = null; • public var x = “test”; • var p = (String x) -> s.length() < 5; • var arr = {”x”, “y”, “z”};
  • 21. www.luxoft.com Java 10 :: Unmodifiable Collections • java.util.List:<E> List<E> copyOf(Collection<? extends E> coll) • java.util.Set:<E> Set<E> copyOf(Collection<? extends E> coll) • java.util.Map:<K,V> Map<K,V> copyOf(Map<? extends K, ? extends V> coll) • UnsupportedOperationException throws
  • 22. www.luxoft.com Java 10 :: Time-Based Release Versioning • Each major release of the Java platform will occur every 6 months (March and September) • Update releases will occur every quarter (January, April, July, October) • Long Term Release (LTS) – updates for releases will be available for at least three years • Version format: $FEATURE.$INTERIM.$UPDATE.$PATCH
  • 24. www.luxoft.com Java 11 • Local-Variable Syntax for Lambda Parameters • Launch Single-File Source Code Programs (JEP) • HTTP Client • Remove The Java EE and CORBA Module • Dynamic Class-File Constants • The Epsilon GC • Flight Recorder
  • 25. www.luxoft.com Java 11 :: Local-Variable Syntax for Lambda Parameters list.stream() .map((var s) -> s.toLowerCase()) .collect(Collectors.toList()); Why? If could be simple: list.stream() .map(s -> s.toLowerCase()) .collect(Collectors.toList()); But: list.stream() .map((@Notnull var s) -> s.toLowerCase()) .collect(Collectors.toList());
  • 26. www.luxoft.com Java 11 :: Launch Single-File Source Code Programs (JEP) java HelloWorld.java java -classpath /home/foo/java Hello.java Luxoft Is equal to: javac -classpath /home/foo/java Hello.java java -classpath /home/foo/java Hello Luxoft
  • 27. www.luxoft.com Java 11 :: Dynamic Class-File Constants • *.class format extension described support CONSTANT_Dynamic (condy) • Using bootstrap method to define values • java.lang.invoke.ConstantBootstraps
  • 29. www.luxoft.com Java 12 • Switch Case • Streams API • Other
  • 30. www.luxoft.com Java 12 :: Switch Case T result = switch (arg) { case L1 -> e1; case L2 -> e2; default -> e3; }; int j = switch (day) { case MONDAY -> 0; case TUESDAY -> 1; default -> { int k = day.toString().length(); int result = f(k); break result; } };
  • 31. www.luxoft.com Java 12 :: Streams API has new Collector public static <T,​R1,​R2,​R> Collector<T,​?,​R> teeing​(Collector<? super T,​?,​R1> downstream1, Collector<? super T,​?,​R2> downstream2, BiFunction<? super R1,​? super R2,​R> merger) var result = Stream.of("Devoxx", "Voxxed Days", "Code One", "Basel One", "Angular Connect") .collect( Collectors.teeing( Collectors.filtering(n -> n.contains("xx"), Collectors.toList()), Collectors.filtering(n -> n.endsWith("One"), Collectors.toList()), (List<String> list1, List<String> list2) -> List.of(list1, list2) ) ); System.out.println(result); // -> [[Devoxx, Voxxed Days], [Code One, Basel One]]
  • 32. www.luxoft.com Java 12 :: Other • InputStream skipNBytes(long n) • java.lang.constant • java.lang.Character • java.lang.Class – arrayType() • java.lang.String (indent(), transform())
  • 33. www.luxoft.com 33www.luxoft.com References • https://www.oracle.com/corporate/features/understanding-java-9-modules.html • https://www.baeldung.com/java-9-http-client • https://docs.oracle.com/javase/9/docs/api/jdk/incubator/http/HttpClient.html • https://openjdk.java.net/jeps/325 • https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/stream/Collectors.html • https://dzone.com/articles/a-new-jdk12-stream-api-collection-collectorsteeing • https://www.baeldung.com/new-java-9 • https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html • https://openjdk.java.net/jeps/110 • https://openjdk.java.net/projects/jigsaw/