SlideShare a Scribd company logo
1 of 34
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

JUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talkJUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talk
Vijay Nair
 
Apache Aries Overview
Apache Aries   OverviewApache Aries   Overview
Apache Aries Overview
Ian Robinson
 
Changes
ChangesChanges
Changes
tony
 

What's hot (20)

Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
JDK 11
JDK 11JDK 11
JDK 11
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
 
Reaching the lambda heaven
Reaching the lambda heavenReaching the lambda heaven
Reaching the lambda heaven
 
JUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talkJUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talk
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
Java 9
Java 9Java 9
Java 9
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream Processing
 
Apache Aries Overview
Apache Aries   OverviewApache Aries   Overview
Apache Aries Overview
 
Changes
ChangesChanges
Changes
 
Shipping your logs to elk from mule app/cloudhub part 2
Shipping your logs to elk from mule app/cloudhub   part 2Shipping your logs to elk from mule app/cloudhub   part 2
Shipping your logs to elk from mule app/cloudhub part 2
 
SLF4J+Logback
SLF4J+LogbackSLF4J+Logback
SLF4J+Logback
 
Http programming in play
Http programming in playHttp programming in play
Http programming in play
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
Kafka Connect
Kafka ConnectKafka Connect
Kafka Connect
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 

Similar to Petro Gordiievych "From Java 9 to Java 12"

Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 

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

Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Reactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary GrygleskiReactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary Grygleski
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners
 
Java one2013
Java one2013Java one2013
Java one2013
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion MiddlewareAMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
AMIS Oracle OpenWorld 2013 Review Part 3 - Fusion Middleware
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Big Data EU 2016: Building Streaming Applications with Apache ApexApache Big Data EU 2016: Building Streaming Applications with Apache Apex
Apache Big Data EU 2016: Building Streaming Applications with Apache Apex
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web Services
 
Shopzilla On Concurrency
Shopzilla On ConcurrencyShopzilla On Concurrency
Shopzilla On Concurrency
 
Java >= 9
Java >= 9Java >= 9
Java >= 9
 

More from LogeekNightUkraine

More from LogeekNightUkraine (20)

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

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

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/