SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
An introduction to Java 9
@IoannisKolaxis
Senior Expert / Software Engineer @ Unify
Java Meetup – Thessaloniki, 7th Nov 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
java
io lang
annotation instrument invoke management
math nio
channels
spi
charset
spi
file
attribute spi
Quiz: How many packages does JDK 8 have?
@IoannisKolaxis - An introduction to Java 9 4
A. 67 B. 117 C. 217
Quiz: How many packages does JDK 8 have?
@IoannisKolaxis - An introduction to Java 9 5
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 6
Java 9: What is a 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 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
8
[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:
9@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 10
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 11
•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 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 13
Creating collections made easy in Java 9!
• How would you create a small, unmodifiable collection?
@IoannisKolaxis - An introduction to Java 9 14
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 15
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 16
• 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 17
• 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 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 19
• 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 20
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 21
• 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 22
Compact Strings - Will your apps run faster?
@IoannisKolaxis - An introduction to Java 9 23
• 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 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 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 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 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 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 29

Weitere ähnliche Inhalte

Was ist angesagt?

Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 

Was ist angesagt? (20)

Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
 
java8-features
java8-featuresjava8-features
java8-features
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Migrating to Java 11
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
 
JDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUGJDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUG
 
Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...
 
Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)Batching and Java EE (jdk.io)
Batching and Java EE (jdk.io)
 
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java GuyGoogle AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Scaling Your Cache
Scaling Your CacheScaling Your Cache
Scaling Your Cache
 
Changes in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must KnowChanges in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must Know
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
LCache DrupalCon Dublin 2016
LCache DrupalCon Dublin 2016LCache DrupalCon Dublin 2016
LCache DrupalCon Dublin 2016
 
Apache Commons Pool and DBCP - Version 2 Update
Apache Commons Pool and DBCP - Version 2 UpdateApache Commons Pool and DBCP - Version 2 Update
Apache Commons Pool and DBCP - Version 2 Update
 
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
 
Getting started with sbt
Getting started with sbtGetting started with sbt
Getting started with sbt
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafe
 

Andere mochten auch

Better Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design ThinkingBetter Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design Thinking
Jeff Gothelf
 

Andere mochten auch (20)

Conference MicroServices101 - 1ere partie
Conference MicroServices101 - 1ere partieConference MicroServices101 - 1ere partie
Conference MicroServices101 - 1ere partie
 
Matinale DevOps / Docker
Matinale DevOps / DockerMatinale DevOps / Docker
Matinale DevOps / Docker
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Optimisez la performance de votre service client tout en maîtrisant votre b...
Optimisez la performance  de votre service client  tout en maîtrisant votre b...Optimisez la performance  de votre service client  tout en maîtrisant votre b...
Optimisez la performance de votre service client tout en maîtrisant votre b...
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
Company_Profile_Digital_1
Company_Profile_Digital_1Company_Profile_Digital_1
Company_Profile_Digital_1
 
Business intelligence v0.3
Business intelligence v0.3Business intelligence v0.3
Business intelligence v0.3
 
Séminaire en ligne - Email Kinetic - 30 Mai 2017
Séminaire en ligne - Email Kinetic - 30 Mai 2017Séminaire en ligne - Email Kinetic - 30 Mai 2017
Séminaire en ligne - Email Kinetic - 30 Mai 2017
 
NightClazz Java 8 Decouverte
NightClazz Java 8 DecouverteNightClazz Java 8 Decouverte
NightClazz Java 8 Decouverte
 
JavaFX et le JDK9
JavaFX et le JDK9JavaFX et le JDK9
JavaFX et le JDK9
 
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelleAgile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
Agile Wake Up #1 du 01/12/2015 : L'agilité à grande échelle
 
WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013WTF - What's The Fold - Bordeaux JUG 2013
WTF - What's The Fold - Bordeaux JUG 2013
 
HTTP2 : ce qui va changer par Julien Landuré
HTTP2 : ce qui va changer par Julien LanduréHTTP2 : ce qui va changer par Julien Landuré
HTTP2 : ce qui va changer par Julien Landuré
 
Better Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design ThinkingBetter Product Definition with Lean UX and Design Thinking
Better Product Definition with Lean UX and Design Thinking
 
Introducing HTTP/2
Introducing HTTP/2Introducing HTTP/2
Introducing HTTP/2
 
Azure Business rules v0.3
Azure Business rules v0.3Azure Business rules v0.3
Azure Business rules v0.3
 
Microbox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien RoyMicrobox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien Roy
 
Going reactive in java
Going reactive in javaGoing reactive in java
Going reactive in java
 
Java 9 modulo les modules devoxx fr 2017
Java 9 modulo les modules devoxx fr 2017Java 9 modulo les modules devoxx fr 2017
Java 9 modulo les modules devoxx fr 2017
 

Ähnlich wie How can your applications benefit from Java 9?

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...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
Steve Elliott
 

Ähnlich wie How can your applications benefit from Java 9? (20)

JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for 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
 
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...
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)
 
Migrate Early, Migrate Often: JDK release cadence strategies
Migrate Early, Migrate Often: JDK release cadence strategiesMigrate Early, Migrate Often: JDK release cadence strategies
Migrate Early, Migrate Often: JDK release cadence strategies
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
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"
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Panama.pdf
Panama.pdfPanama.pdf
Panama.pdf
 
Lucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challengesLucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challenges
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy Edges
 
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 se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14Java se-7-evolves-toulouse-jug-2001-09-14
Java se-7-evolves-toulouse-jug-2001-09-14
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 

Kürzlich hochgeladen (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

How can your applications benefit from Java 9?

  • 1. An introduction to Java 9 @IoannisKolaxis Senior Expert / Software Engineer @ Unify Java Meetup – Thessaloniki, 7th Nov 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. java io lang annotation instrument invoke management math nio channels spi charset spi file attribute spi Quiz: How many packages does JDK 8 have? @IoannisKolaxis - An introduction to Java 9 4 A. 67 B. 117 C. 217
  • 5. Quiz: How many packages does JDK 8 have? @IoannisKolaxis - An introduction to Java 9 5 java io lang annotation instrument invoke management math nio channels spi charset spi file attribute spi A. 67 B. 117 C. 217
  • 6. 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 6
  • 7. Java 9: What is a 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 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
  • 8. Reusing packages from another module 8 [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
  • 9. 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: 9@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
  • 10. Modularizing Java 9 @IoannisKolaxis - An introduction to Java 9 10 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
  • 11. 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 11 •If yes, then you can minimize your JRE: • By deploying only the JRE modules that you need!
  • 12. 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 12
  • 13. 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 13
  • 14. Creating collections made easy in Java 9! • How would you create a small, unmodifiable collection? @IoannisKolaxis - An introduction to Java 9 14 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
  • 15. Creating collections made easy in Java 9! • More examples: @IoannisKolaxis - An introduction to Java 9 15 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
  • 16. 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 16 • How will those changes affect your existing application?
  • 17. 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 17 • High Throughput: Maximizing the amount of work done in a given time frame. • e.g. number of database queries completed in 1 hour.
  • 18. 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 18
  • 19. 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 19 • Garbage Collectors in Java 9: • Moving from a Throughput-oriented GC (Parallel) to a Low- Latency GC (Garbage First/G1).
  • 20. 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 20 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
  • 21. G1 Garbage Collector @IoannisKolaxis - An introduction to Java 9 21 • 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
  • 22. Compact Strings (JEP 254) @IoannisKolaxis - An introduction to Java 9 22
  • 23. Compact Strings - Will your apps run faster? @IoannisKolaxis - An introduction to Java 9 23 • 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.
  • 24. 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 24
  • 25. 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 25
  • 26. 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 26
  • 27. 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 27
  • 28. 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 28
  • 29. 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 29