SlideShare a Scribd company logo
1 of 28
Download to read offline
An introduction to Java 9
@IoannisKolaxis
Senior Expert / Software Engineer @ Unify
JHUG Meetup – Athens, 20th Oct 2017
How can your applications benefit
from Java 9?
Java 9
The most important feature:
Modules!
@IoannisKolaxis - An introduction to Java 9 2
What is a package?
• Packages are used to organize classes & interfaces
3@IoannisKolaxis - An introduction to Java 9
A package is a
set of classes
[Classes]
FileReader.java,
FileWriter.java,
InputStream.java,
OutputStream.java, ...
[package]
java.io
[Classes]
Double.java,
Float.java,
String.java,
Thread.java, ...
[package]
java.lang
Quiz: How many packages does JDK 8 have?
@IoannisKolaxis - An introduction to Java 9 4
java
io lang
annotation instrument invoke management
math nio
channels
spi
charset
spi
file
attribute spi
A. 67 B. 117 C. 217
Challenges faced by Java engineers
•How do the classes of those 217 packages interact
between them?
• A public class is accessible by every other class, in any other
package.
• Tight coupling makes it too difficult to introduce changes,
resulting in increased development & testing costs.
•Can we create groups of packages, controlling how they
interact between them?
@IoannisKolaxis - An introduction to Java 9 5
Java 9: What is a module?
6
[Exported Packages]
Can be reused by other modules
java.lang, java.io, java.net, java.util
[Concealed Packages]
Cannot be reused by other modules
sun.nio.ch, sun.reflect.annotation,
sun.security.provider, ...
[module]
java.base
// module-info.java
module java.base {
exports java.lang;
exports java.io;
exports java.net;
exports java.util;
}
@IoannisKolaxis - An introduction to Java 9
A module is a
set of packages
… designed
for reuse
Reusing packages from another module
7
[Exported Packages]
Can be reused by other modules
java.lang, java.io, java.net, java.util
[Concealed Packages]
Cannot be reused by other modules
sun.nio.ch, sun.reflect.annotation,
sun.security.provider, ...
[module]
java.base
// module-info.java
module our.module {
exports our.package;
requires java.base;
}
@IoannisKolaxis - An introduction to Java 9
[Exported Packages]
Can be reused by other modules
our.package
[module]
our.module
Reused by
Requires
Using modules to control access
• In Java 9, a public class may not be visible to everyone!
• A public class in our.package may be:
8@IoannisKolaxis - An introduction to Java 9
module our.module {
exports our.package;
}
Accessible to everyone
Accessible to other classes in our
module & a friend module
module our.module {
exports our.package
to friend.module;
}
module our.module {
}
Accessible only to other classes in
our module
Modularizing Java 9
@IoannisKolaxis - An introduction to Java 9 9
java.base
java.compiler java.instrument java.logging java.xml java.datatransfer java.scripting
java.security.sasl java.sql java.xml.crypto
java.rmi java.naming java.prefs
java.management java.security.jgss java.sql.rowset java.desktop
java.se
Tailoring the JRE to fit our needs
•Are you worried about the size of the ?
•Are you building:
• Embedded, or
• Containerized applications?
@IoannisKolaxis - An introduction to Java 9 10
•If yes, then you can minimize your JRE:
• By deploying only the JRE modules that you need!
Using the Java Linker to minimize our JRE
• Let’s suppose that our application needs only the
java.base module:
jlink --module-path /opt/jdk-9/jmods
--add-modules java-base
--output /out/jdk-9-base
• As demonstrated here, the size of a Docker image of
Alpine Linux & JRE 9 is reduced:
• From: 356MB (JRE with all modules)
• To: 37MB (JRE with java.base module only)
@IoannisKolaxis - An introduction to Java 9 11
How can your apps benefit from modules?
•Enhanced security, through strong encapsulation.
•Performance is improved:
• only the required JRE modules may be loaded.
• the classloaderdoes not have to linearly search through all
the JARs in the classpath, in order to find a class.
@IoannisKolaxis - An introduction to Java 9 12
Creating collections made easy in Java 9!
• How would you create a small, unmodifiable collection?
@IoannisKolaxis - An introduction to Java 9 13
Set<String> set = new HashSet<>();
set.add(“a”);
set.add(“b”);
set.add(“c”);
set = Collections.unmodifiableSet(set);
• List, Map, and Set interfaces are enhanced in Java 9 with
static factory methods “of”:
Set<String> set = Set.of(“a”, “b”, “c”);
≤ Java 8
Java 9
Creating collections made easy in Java 9!
• More examples:
@IoannisKolaxis - An introduction to Java 9 14
List<String> list = List.of(“m”, “e”, “s”);
Map<String, Integer> map = Map.of(“e”, 5, “s”, 1);
• For Sets, and Maps the iteration order is randomized!
• What about Maps with more than 10 elements?
Map<String, Integer> map = Map.ofEntries(
entry(“a”, 1),
entry(“b”, 2),
…
entry(“z”, 26));
Collections are
immutable!
… cannot
add/delete
elements
Java 9: Changes to Garbage Collectors (GC)
• Garbage-First (G1) becomes the default Garbage Collector.
• Previously, the default one was the Parallel GC.
• Concurrent Mark Sweep (CMS) GC becomes deprecated.
@IoannisKolaxis - An introduction to Java 9 15
• How will those changes affect your
existing application?
What does your application aim for?
• Low Latency: Responding quickly, in short periods of time.
• e.g. when serving a web page, or returning a database query.
or
@IoannisKolaxis - An introduction to Java 9 16
• High Throughput: Maximizing the amount of work done in
a given time frame.
• e.g. number of database queries completed
in 1 hour.
Tuning the performance of your application
• As Java programmers, we don’t need to manage memory:
• We allocate memory for an object with new:
String meetup = new String(“jhug”);
• This memory will be automatically deallocated by the Garbage
Collector, when it is no longer in use.
• How do we tune the performance of an application?
• Heap: by properly sizing the heap (the memory area where all
the object data is stored).
• Garbage Collector: by choosing the most appropriate GC, usually
optimized for Low Latency or High Throughput.
@IoannisKolaxis - An introduction to Java 9 17
Moving to a Low-Latency Garbage Collector
Java 9 Garbage Collector Optimized for
Serial Memory footprint
(Ex-Default) Parallel High Throughput
Deprecated Concurrent Mark Sweep Low Latency
Default Garbage First / G1 Low Latency
@IoannisKolaxis - An introduction to Java 9 18
• Garbage Collectors in Java 9:
• Moving from a Throughput-oriented GC (Parallel) to a Low-
Latency GC (Garbage First/G1).
G1 Garbage Collector
• In Serial/Parallel/CMS GC, the Heap is divided into 2 regions (=Young
& Old Generation) of fixed size.
@IoannisKolaxis - An introduction to Java 9 19
S0 TenuredS1Eden
Young Generation Old Generation
Survivor
• In G1 GC, the Heap is divided into multiple, smaller regions.
E S O
O E E S
S O S
S E S
O
Eden
Old
Survivor
G1 Garbage Collector
@IoannisKolaxis - An introduction to Java 9 20
• The heap is partitioned into 2.000 equal-sized regions:
• Achieving a finer granularity on how much garbage to collect at each GC
pause.
• Default pause goal = 200msec
• May be adjusted, to achieve lower latency or higher throughput.
E S O
O E E S
S O S
S E S
O
Eden
Old
Survivor 6GB heap : 2.000 regions
= 3MB/region
Region size
depends on
Heap Size
O S O
S E E S
S O S
S E S
E
Compact Strings (JEP 254)
@IoannisKolaxis - An introduction to Java 9 21
Compact Strings - Will your apps run faster?
@IoannisKolaxis - An introduction to Java 9 22
• Allocation rate: the amount of memory allocated per time
unit, measured in MB/sec.
• Strings now have a reduced memory footprint, resulting in:
→ lower memory allocationrate,
→ the GC is called less frequently to clean the memory,
→ a decrease in the frequency and/or duration of pauses during
GC cleanup.
• Performance improvements of up to 10%
have been measured, as stated here.
Controlling native processes
• Ever had to control native processes from your Java app?
• Executed OS commands (like: ‘ps –ef’), and parsed their output?
• Java 9 makes it a “piece of cake” to:
• Get the native id of the current process:
long processId = ProcessHandle.current().pid();
• Check if a process is currently running.
• Retrieve information(like: start/total time) for a process.
• Wait for terminationof a process, and trigger dependent actions :
process.onExit().thenRun(()-> System.out.println(“Done"););
@IoannisKolaxis - An introduction to Java 9 23
HTTP/2 Client API
• Until Java 8, we used the HttpURLConnection API to establish an
HTTP 1.1 connection. However:
• It works only in blocking mode (=1 thread per request/response).
• It is hard to use, with many undocumentedbehaviors.
• Java 9 introduces a new HTTP client that supports:
• HTTP 1.1 and HTTP/2,
• a synchronous/blocking mode, and an asynchronous/non-blocking mode.
• Delivered as an incubator module
• A non-final API, provided for experimentation.
• May be finalized (or even removed!) in an upcoming Java version.
@IoannisKolaxis - An introduction to Java 9 24
Security related enhancements
• Improved performance for GHASH and RSA cryptographic
operations (JEP 246).
• By leveraging SPARC and Intel x64 CPU instructions.
• Support for SHA-3 hash algorithms (JEP 287).
• TLS Application-Layer Protocol Negotiation (JEP244)
• Provides the means to negotiate an application protocol over TLS.
• Required by HTTP/2.
• OCSP Stapling for TLS (JEP 249).
• Improves performance of TLS, by reducing the performance
bottleneck of the OCSP responder.
@IoannisKolaxis - An introduction to Java 9 25
Java Shell: Read-Evaluate-Print Loop (REPL)
• REPL - an interactive programming tool, that:
• Loops, continuously reading user input,
• Evaluates the input,
• Prints the value of the input.
• Expected to help students learn Java, without having to edit,
compile, and execute code.
• As developers, we can benefit from JShell by quickly:
• Exploring new APIs or language features,
• Prototyping something complex.
@IoannisKolaxis - An introduction to Java 9 26
Wish to learn more about Java 9?
• For more details, check the JEPs (Java Enhancement
Proposals) implemented in Java 9:
http://openjdk.java.net/projects/jdk9/
@IoannisKolaxis - An introduction to Java 9 27
References
1. JDK 9 Features
2. “Modular Development with JDK 9”, Alex Buckley, Devoxx United
States
3. “Java in a World of Containers”, Paul Sandoz
4. “The G1 GC in JDK 9”, Erik Duveblad
5. “JShell is Here”, Robert Field
@IoannisKolaxis - An introduction to Java 9 28

More Related Content

What's hot

Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Hiroshi Ono
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103shashank_ibm
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to GaleraHenrik Ingo
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With TerracottaPT.JUG
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle TroubleshootingHector Martinez
 
Advanced WebLogic Monitoring: JMX and WLSDM Automation
Advanced WebLogic Monitoring: JMX and WLSDM AutomationAdvanced WebLogic Monitoring: JMX and WLSDM Automation
Advanced WebLogic Monitoring: JMX and WLSDM AutomationM. Fevzi Korkutata
 
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla1512 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla15Frank Munz
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLKenny Gryp
 
Using and Benchmarking Galera in different architectures (PLUK 2012)
Using and Benchmarking Galera in different architectures (PLUK 2012)Using and Benchmarking Galera in different architectures (PLUK 2012)
Using and Benchmarking Galera in different architectures (PLUK 2012)Henrik Ingo
 
Easy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingEasy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingBob Burgess
 
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding Ulf Wendel
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationKenny Gryp
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master ReplicationMoshe Kaplan
 
HTTP Plugin for MySQL!
HTTP Plugin for MySQL!HTTP Plugin for MySQL!
HTTP Plugin for MySQL!Ulf Wendel
 
PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux ContainersJignesh Shah
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterSeveralnines
 

What's hot (20)

Ehcache 3 @ BruJUG
Ehcache 3 @ BruJUGEhcache 3 @ BruJUG
Ehcache 3 @ BruJUG
 
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
Solving_the_C20K_problem_PHP_Performance_and_Scalability-phpquebec_2009
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to Galera
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With Terracotta
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle Troubleshooting
 
Advanced WebLogic Monitoring: JMX and WLSDM Automation
Advanced WebLogic Monitoring: JMX and WLSDM AutomationAdvanced WebLogic Monitoring: JMX and WLSDM Automation
Advanced WebLogic Monitoring: JMX and WLSDM Automation
 
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla1512 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
 
Using and Benchmarking Galera in different architectures (PLUK 2012)
Using and Benchmarking Galera in different architectures (PLUK 2012)Using and Benchmarking Galera in different architectures (PLUK 2012)
Using and Benchmarking Galera in different architectures (PLUK 2012)
 
Easy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingEasy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and Troubleshooting
 
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding MySQL 5.7 Fabric: Introduction to High Availability and Sharding
MySQL 5.7 Fabric: Introduction to High Availability and Sharding
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master Replication
 
HTTP Plugin for MySQL!
HTTP Plugin for MySQL!HTTP Plugin for MySQL!
HTTP Plugin for MySQL!
 
PostgreSQL and Linux Containers
PostgreSQL and Linux ContainersPostgreSQL and Linux Containers
PostgreSQL and Linux Containers
 
Tomcatx performance-tuning
Tomcatx performance-tuningTomcatx performance-tuning
Tomcatx performance-tuning
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera Cluster
 

Similar to How can your applications benefit from Java 9?

What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9Gal Marder
 
Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Jamie Coleman
 
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"GlobalLogic Ukraine
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Rittercatherinewall
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11Arto Santala
 
Devoxx Belgium 2015
Devoxx Belgium 2015Devoxx Belgium 2015
Devoxx Belgium 2015GiedriusTS
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy EdgesJimmy Ray
 
Low latency in java 8 v5
Low latency in java 8 v5Low latency in java 8 v5
Low latency in java 8 v5Peter Lawrey
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Martijn Verburg
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9jClarity
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9Deepu Xavier
 
Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentationdhananajay95
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mSteve Elliott
 
The features of java 11 vs. java 12
The features of  java 11 vs. java 12The features of  java 11 vs. java 12
The features of java 11 vs. java 12FarjanaAhmed3
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ TokopediaQasim Zaidi
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)Markus Günther
 

Similar to How can your applications benefit from Java 9? (20)

What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019Are you ready for cloud-native java JavaCro2019
Are you ready for cloud-native java JavaCro2019
 
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
 
Devoxx Belgium 2015
Devoxx Belgium 2015Devoxx Belgium 2015
Devoxx Belgium 2015
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy Edges
 
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
 
Low latency in java 8 v5
Low latency in java 8 v5Low latency in java 8 v5
Low latency in java 8 v5
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 
Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentation
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
The features of java 11 vs. java 12
The features of  java 11 vs. java 12The features of  java 11 vs. java 12
The features of java 11 vs. java 12
 
Panama.pdf
Panama.pdfPanama.pdf
Panama.pdf
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)
 

Recently uploaded

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 

Recently uploaded (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 

How can your applications benefit from Java 9?

  • 1. An introduction to Java 9 @IoannisKolaxis Senior Expert / Software Engineer @ Unify JHUG Meetup – Athens, 20th Oct 2017 How can your applications benefit from Java 9?
  • 2. Java 9 The most important feature: Modules! @IoannisKolaxis - An introduction to Java 9 2
  • 3. What is a package? • Packages are used to organize classes & interfaces 3@IoannisKolaxis - An introduction to Java 9 A package is a set of classes [Classes] FileReader.java, FileWriter.java, InputStream.java, OutputStream.java, ... [package] java.io [Classes] Double.java, Float.java, String.java, Thread.java, ... [package] java.lang
  • 4. Quiz: How many packages does JDK 8 have? @IoannisKolaxis - An introduction to Java 9 4 java io lang annotation instrument invoke management math nio channels spi charset spi file attribute spi A. 67 B. 117 C. 217
  • 5. Challenges faced by Java engineers •How do the classes of those 217 packages interact between them? • A public class is accessible by every other class, in any other package. • Tight coupling makes it too difficult to introduce changes, resulting in increased development & testing costs. •Can we create groups of packages, controlling how they interact between them? @IoannisKolaxis - An introduction to Java 9 5
  • 6. Java 9: What is a module? 6 [Exported Packages] Can be reused by other modules java.lang, java.io, java.net, java.util [Concealed Packages] Cannot be reused by other modules sun.nio.ch, sun.reflect.annotation, sun.security.provider, ... [module] java.base // module-info.java module java.base { exports java.lang; exports java.io; exports java.net; exports java.util; } @IoannisKolaxis - An introduction to Java 9 A module is a set of packages … designed for reuse
  • 7. Reusing packages from another module 7 [Exported Packages] Can be reused by other modules java.lang, java.io, java.net, java.util [Concealed Packages] Cannot be reused by other modules sun.nio.ch, sun.reflect.annotation, sun.security.provider, ... [module] java.base // module-info.java module our.module { exports our.package; requires java.base; } @IoannisKolaxis - An introduction to Java 9 [Exported Packages] Can be reused by other modules our.package [module] our.module Reused by Requires
  • 8. Using modules to control access • In Java 9, a public class may not be visible to everyone! • A public class in our.package may be: 8@IoannisKolaxis - An introduction to Java 9 module our.module { exports our.package; } Accessible to everyone Accessible to other classes in our module & a friend module module our.module { exports our.package to friend.module; } module our.module { } Accessible only to other classes in our module
  • 9. Modularizing Java 9 @IoannisKolaxis - An introduction to Java 9 9 java.base java.compiler java.instrument java.logging java.xml java.datatransfer java.scripting java.security.sasl java.sql java.xml.crypto java.rmi java.naming java.prefs java.management java.security.jgss java.sql.rowset java.desktop java.se
  • 10. Tailoring the JRE to fit our needs •Are you worried about the size of the ? •Are you building: • Embedded, or • Containerized applications? @IoannisKolaxis - An introduction to Java 9 10 •If yes, then you can minimize your JRE: • By deploying only the JRE modules that you need!
  • 11. Using the Java Linker to minimize our JRE • Let’s suppose that our application needs only the java.base module: jlink --module-path /opt/jdk-9/jmods --add-modules java-base --output /out/jdk-9-base • As demonstrated here, the size of a Docker image of Alpine Linux & JRE 9 is reduced: • From: 356MB (JRE with all modules) • To: 37MB (JRE with java.base module only) @IoannisKolaxis - An introduction to Java 9 11
  • 12. How can your apps benefit from modules? •Enhanced security, through strong encapsulation. •Performance is improved: • only the required JRE modules may be loaded. • the classloaderdoes not have to linearly search through all the JARs in the classpath, in order to find a class. @IoannisKolaxis - An introduction to Java 9 12
  • 13. Creating collections made easy in Java 9! • How would you create a small, unmodifiable collection? @IoannisKolaxis - An introduction to Java 9 13 Set<String> set = new HashSet<>(); set.add(“a”); set.add(“b”); set.add(“c”); set = Collections.unmodifiableSet(set); • List, Map, and Set interfaces are enhanced in Java 9 with static factory methods “of”: Set<String> set = Set.of(“a”, “b”, “c”); ≤ Java 8 Java 9
  • 14. Creating collections made easy in Java 9! • More examples: @IoannisKolaxis - An introduction to Java 9 14 List<String> list = List.of(“m”, “e”, “s”); Map<String, Integer> map = Map.of(“e”, 5, “s”, 1); • For Sets, and Maps the iteration order is randomized! • What about Maps with more than 10 elements? Map<String, Integer> map = Map.ofEntries( entry(“a”, 1), entry(“b”, 2), … entry(“z”, 26)); Collections are immutable! … cannot add/delete elements
  • 15. Java 9: Changes to Garbage Collectors (GC) • Garbage-First (G1) becomes the default Garbage Collector. • Previously, the default one was the Parallel GC. • Concurrent Mark Sweep (CMS) GC becomes deprecated. @IoannisKolaxis - An introduction to Java 9 15 • How will those changes affect your existing application?
  • 16. What does your application aim for? • Low Latency: Responding quickly, in short periods of time. • e.g. when serving a web page, or returning a database query. or @IoannisKolaxis - An introduction to Java 9 16 • High Throughput: Maximizing the amount of work done in a given time frame. • e.g. number of database queries completed in 1 hour.
  • 17. Tuning the performance of your application • As Java programmers, we don’t need to manage memory: • We allocate memory for an object with new: String meetup = new String(“jhug”); • This memory will be automatically deallocated by the Garbage Collector, when it is no longer in use. • How do we tune the performance of an application? • Heap: by properly sizing the heap (the memory area where all the object data is stored). • Garbage Collector: by choosing the most appropriate GC, usually optimized for Low Latency or High Throughput. @IoannisKolaxis - An introduction to Java 9 17
  • 18. Moving to a Low-Latency Garbage Collector Java 9 Garbage Collector Optimized for Serial Memory footprint (Ex-Default) Parallel High Throughput Deprecated Concurrent Mark Sweep Low Latency Default Garbage First / G1 Low Latency @IoannisKolaxis - An introduction to Java 9 18 • Garbage Collectors in Java 9: • Moving from a Throughput-oriented GC (Parallel) to a Low- Latency GC (Garbage First/G1).
  • 19. G1 Garbage Collector • In Serial/Parallel/CMS GC, the Heap is divided into 2 regions (=Young & Old Generation) of fixed size. @IoannisKolaxis - An introduction to Java 9 19 S0 TenuredS1Eden Young Generation Old Generation Survivor • In G1 GC, the Heap is divided into multiple, smaller regions. E S O O E E S S O S S E S O Eden Old Survivor
  • 20. G1 Garbage Collector @IoannisKolaxis - An introduction to Java 9 20 • The heap is partitioned into 2.000 equal-sized regions: • Achieving a finer granularity on how much garbage to collect at each GC pause. • Default pause goal = 200msec • May be adjusted, to achieve lower latency or higher throughput. E S O O E E S S O S S E S O Eden Old Survivor 6GB heap : 2.000 regions = 3MB/region Region size depends on Heap Size O S O S E E S S O S S E S E
  • 21. Compact Strings (JEP 254) @IoannisKolaxis - An introduction to Java 9 21
  • 22. Compact Strings - Will your apps run faster? @IoannisKolaxis - An introduction to Java 9 22 • Allocation rate: the amount of memory allocated per time unit, measured in MB/sec. • Strings now have a reduced memory footprint, resulting in: → lower memory allocationrate, → the GC is called less frequently to clean the memory, → a decrease in the frequency and/or duration of pauses during GC cleanup. • Performance improvements of up to 10% have been measured, as stated here.
  • 23. Controlling native processes • Ever had to control native processes from your Java app? • Executed OS commands (like: ‘ps –ef’), and parsed their output? • Java 9 makes it a “piece of cake” to: • Get the native id of the current process: long processId = ProcessHandle.current().pid(); • Check if a process is currently running. • Retrieve information(like: start/total time) for a process. • Wait for terminationof a process, and trigger dependent actions : process.onExit().thenRun(()-> System.out.println(“Done");); @IoannisKolaxis - An introduction to Java 9 23
  • 24. HTTP/2 Client API • Until Java 8, we used the HttpURLConnection API to establish an HTTP 1.1 connection. However: • It works only in blocking mode (=1 thread per request/response). • It is hard to use, with many undocumentedbehaviors. • Java 9 introduces a new HTTP client that supports: • HTTP 1.1 and HTTP/2, • a synchronous/blocking mode, and an asynchronous/non-blocking mode. • Delivered as an incubator module • A non-final API, provided for experimentation. • May be finalized (or even removed!) in an upcoming Java version. @IoannisKolaxis - An introduction to Java 9 24
  • 25. Security related enhancements • Improved performance for GHASH and RSA cryptographic operations (JEP 246). • By leveraging SPARC and Intel x64 CPU instructions. • Support for SHA-3 hash algorithms (JEP 287). • TLS Application-Layer Protocol Negotiation (JEP244) • Provides the means to negotiate an application protocol over TLS. • Required by HTTP/2. • OCSP Stapling for TLS (JEP 249). • Improves performance of TLS, by reducing the performance bottleneck of the OCSP responder. @IoannisKolaxis - An introduction to Java 9 25
  • 26. Java Shell: Read-Evaluate-Print Loop (REPL) • REPL - an interactive programming tool, that: • Loops, continuously reading user input, • Evaluates the input, • Prints the value of the input. • Expected to help students learn Java, without having to edit, compile, and execute code. • As developers, we can benefit from JShell by quickly: • Exploring new APIs or language features, • Prototyping something complex. @IoannisKolaxis - An introduction to Java 9 26
  • 27. Wish to learn more about Java 9? • For more details, check the JEPs (Java Enhancement Proposals) implemented in Java 9: http://openjdk.java.net/projects/jdk9/ @IoannisKolaxis - An introduction to Java 9 27
  • 28. References 1. JDK 9 Features 2. “Modular Development with JDK 9”, Alex Buckley, Devoxx United States 3. “Java in a World of Containers”, Paul Sandoz 4. “The G1 GC in JDK 9”, Erik Duveblad 5. “JShell is Here”, Robert Field @IoannisKolaxis - An introduction to Java 9 28