SlideShare a Scribd company logo
Preparing your code for Java 9
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Preparing your code for Java 9
Eclipse Summit, India
Deepu Xavier
Product Manager
Java Platform Group
26 August 2016
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Agenda
• Java 9 Schedule
• How a developer can leverage and adjust to Java 9 features
– Jshell
– Javadoc Search
– Internal API encapsulation
– Process API
– Convenience Factory Methods for Collections
– Version String – V for Verona
– Multi Release Jar Files
– Gone, gone, gone…
• The Jigsaw way
– How to make your own modular image
• What Next
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Java 9 Timeline
Schedule Milestone Target Date
Feature Complete 26 May 2016
All Tests Run 11 August 2016
Rampdown Start 01 September 2016
Zero bug Bounce 20 October 2016
Rampdown Phase 2 01 December 2016
Final Release Candidate 26 January 2017
General Availability 23 March 2017
https://jdk9.java.net/
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6
JDK Enhancement Proposals (JEPs) for Java 9
Total
84 JEPs
Jigsaw Client Lib Core Lib Core SVC Hotspot JavaFX Security Lib Tools XML Others
Version String
Linux/AArch64
Port
Infra & Deploy- 3
JEPs
7 JEPs 19 JEPs 2 JEPs 17 JEPs 3 JEPs 9 JEPs 15 JEPs 1 JEPs 5 JEPs
Note: The content of this slide is based on information available as of 26th July 2016
6 JEPs
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7
Java 9: Jigsaw and Many More…
Process API
Improvements
Multi-Resolution
Images
Interned String in CDS Unicode Compatibility
Default GC
JVM Command
Validation
Compact String
Segmented Code
Cache
Reserved Stack Areas
for Critical Sections
Better Import
Statement Handling
Convenient Collections
Handling
Concurrency Updates
Multi Release JAR
Smart Compilation 2
HiDPI Graphics on
Windows and Linux
Microbenchmark Suite
More JVM Diagnostic
Commands
Compile for Older
Platform Versions
Jigsaw
HTTP2 Compliance
New Version String
http://openjdk.java.net/projects/jdk9/
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 222: JShell
• Lets you try code.
• Supports libraries, tab completion, up/down arrows, etc.
• Not for “create a class or method from this prose.”
8
•Without JShell, I often wrote random unit tests or main
methods to try things.
•With JShell, I can try things and close it when I’m done.
JEP 222
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 225: Javadoc Search
• Add a search box to generated API documentation that can be used to search for program elements and
tagged words and phrases within the documentation.
tools / javadoc(tool)
Java 8 Javadoc:
https://docs.oracle.com/javase/8/docs/api/
Java 9 Javadoc:
http://download.java.net/java/jdk9/docs/api/index.html
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 260: Encapsulate Most Internal APIs
• Make most of the JDK's internal APIs inaccessible by default but leave a few critical, widely-used internal
APIs accessible, until supported replacements exist for all or most of their functionality
– In order to keep critical APIs without a replacement accessible by default sun.misc and sun.reflect will
not be hidden and a few APIs kept “public”
• sun.misc.Unsafe
• sun.misc.{Signal,SignalHandler}
• sun.reflect.Reflection::getCallerClass
• sun.reflect.ReflectionFactory
– All other APIs in these packages (e.g. sun.misc.Base64) will be removed
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11
Categories of APIs in JDK
• Supported, intended for external use
• JCP standard, java.*, javax.*
• JDK-specific API, some com.sun.*, some jdk.*
• Unsupported, JDK-internal, not intended for external use
• sun.* mostly
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12
Internal API Related Changes
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13
General compatibility policies
•If an application uses only supported, non-deprecated, APIs and works on release N then it should
work on N+1, even without recompilation
•Supported APIs can be removed but only with advanced notice
How we manage incompatibilities
• Judge risk and impact based on actual data (where possible)
• Communicate early and vigorously through Early Access, OpenJDK Mails etc.
• Make it easy to understand how existing code will be affected
• When removing unsupported APIs, provide replacements where it make sense
• Provide workarounds where possible
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14
JEP 260 proposal
Encapsulate all non-critical internal APIs by default
Encapsulate all critical internal APIs for which supported replacements exist in JDK 8
Do not encapsulate critical internal APIs
• Deprecate them in JDK 9
• Plan to remove in JDK 10
Provide a workaround via command-line flag
Non-critical
No evidence of use outside of JDK or used only for convenience
Critical
Functionality that would be difficult, if not impossible, to implement outside of the JDK
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15
Finding uses of JDK-internal APIs
• jdeps tool in JDK 8, improved in JDK 9
• Maven JDeps Plugin
$ jdeps -jdkinternals glassfish/modules/security.jar
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Code shown in the following examples are purely author’s imagination or used in a fictitious manner.
Any resemblance to your application code “could be” purely coincidental.
Internal API !!!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
jdeps To The Rescue
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
The Right Way
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 102: Process API Updates
19
• There has been a huge limitation in managing and controlling OS processes with Java
• Platform compatibility was always a challenge. At present, developers resort to native code or much
verbose workaround
• With Java 9, processes can be handled using new direct methods like:
• ProcessHandle currProcess = ProcessHandle.current();
• ProcessHandle.allProcesses()
.filter(processHandle -> processHandle.info().command().isPresent())
.limit(3)
.forEach((process) ->{// action here}
//In Windows
Process myProc = Runtime.getRuntime().exec ("tasklist.exe");
InputStream procOutput = myProc.getInputStream ();
if (0 == myProc.waitFor ()) {
// actions here
}
//For Linux
Process myProc = Runtime.getRuntime().exec("ps -e");
InputStream procOutput = myProc.getInputStream ();
if (0 == myProc.waitFor ()) {
// actions here
}
Note: This is just couple of new methods/ classes. Please refer the respective javadoc for full list
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
The Right Way
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 269: Convenience Factory Methods for Collections
• Define library APIs to make it convenient to create instances of collections and maps with small numbers
of elements, so as to ease the pain of not having collection literals in the Java programming language
• Less boilerplate and reduced amount of code needed for creating small collections and maps
• Set<String> set = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("a", "b", "c")));
– populate a collection using a copy constructor from another collection:
• Set<String> set = Collections.unmodifiableSet(new HashSet<String>() {{ add("a"); add("b"); add("c"); }});
– use the so-called "double brace" technique:
• Set<String> set = Collections.unmodifiableSet(Stream.of("a", "b", "c").collect(toSet()));
– by combining stream factory methods and collectors
Set<String> alphabet = Set.of("a", "b", "c");
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Overload Difficulty: List.of(array)
Oracle Confidential – Internal 22
Suppose you have this:
String[] array = { "a", "b", "c" };
List.of(array);
Should this create:
A. List<String> containing three strings?
B. List<String[]> containing a single array?
JEP 269
ANSWER:
A. Compiler chooses varargs, so we get List<String> with three strings
Probably right; list of arrays is rare. Workaround:
List<String[]> listOfArray = List.<String[]>of(array);
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23
JEP 223: New Version-String Scheme
Revise the JDK's version-string scheme so that it is easier to distinguish major, minor, and security-update releases.
Goal is to device a new version numbering scheme which is
 easily understandable
 aligning with industry best practices (Semantic Versioning)
 is easy to distinguish between major, minor and critical patch update (CPU) releases
New scheme will follow MAJOR.MINOR.SECURITY (-PRE)?(+BUILD)?(-OPT)? convention
MAJOR : The major version number will be incremented for every major release
MINOR : The minor version number will be incremented for every minor update release
MINOR is reset to zero when MAJOR is incremented
SECURITY: The security version number will be incremented for every security update release
SECURITY is reset to zero only when MAJOR is incremented
A higher value of SECURITY for a given MAJOR value, therefore, always indicates a more secure release, regardless of the value of MINOR
PRE: This represents a pre-release identifier. E.g. ea, for an early-access release
BUILD: Build number may be promoted by 1 for every promoted build. BUILD is reset to one when any portion of MAJOR.MINOR.SECURITY is incremented
OPT: Additional build information
Note: Existing code that assumes the initial element to have the value 1, however, and therefore always skips to the second element when comparing version numbers, will not work correctly
e.g., such code will consider 9.0.1 to precede 1.8.0.
Version # Detail
9 Java 9 GA
9.0.1 CPU: 9 + critical changes
9.1.1 Minor release: 9.0.1 + other changes
9.1.2 CPU: 9.1.1 + critical changes
9.2.2 Minor release: 9.1.2 + other changes
Hypothetical Release Sequence (for illustration only)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 282: jlink: The Java Linker
• Create a tool that can assemble and optimize a set of modules and their dependencies into a custom run-
time image as defined in JEP 220. Define a plugin mechanism for transformation and optimization during
the assembly process, and for the generation of alternative image formats
• Create a custom runtime optimized for a single program
• JEP 261 defines link time as an optional phase between the phases of compile time and run time. Link
time requires a linking tool that will assemble and optimize a set of modules and their transitive
dependencies to create a run-time image or executable.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 25
JEP 238: Multi-Release JAR Files
Extend the JAR file format to allow multiple, Java-release-specific versions of class files to coexist in a single archive.
• It is practically difficult to express conditional platform dependencies or to distribute separate
library artifacts for each new java version
• A multi-release JAR ("MRJAR") will contain additional directories for classes and resources
specific to particular Java platform releases.
With this, it is possible for versions of a class designed for a later Java platform version to
override the version of that same class designed for an earlier Java platform release.
META-INF
Content Root
A.class
B.class
C.class
D.class
Normal JAR
META-INF
versions
-8
A.class
B.class
-9
A.class
Content Root
A.class
B.class
C.class
D.class
MR JAR
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 289: Deprecate the Applet API
• Deprecate the Applet API, which is rapidly becoming irrelevant as web-browser vendors remove support for Java
browser plug-ins
JEP 241: Remove the jhat Tool
• Remove the antiquated jhat tool
• jhat is an experimental, unsupported, and out-of-date tool added in JDK 6
• Superior heap visualizers and analyzers have now been available for many years
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
JEP 231: Remove Launch-Time JRE Version Selection
• Remove the ability to request, at JRE launch time, a version of the JRE that is not the JRE being launched.
• Modern applications are typically deployed via Java Web Start (JNLP), native OS packaging systems, or
active installers, and all of these technologies have their own ways of finding, and even sometimes
installing and later updating, an appropriate JRE for the application.
JEP 240: Remove the JVM TI hprof Agent
• Remove the hprof agent from the JDK
• The hprof agent was written as demonstration code for the JVM Tool Interface and not intended to be a
production tool.
• The useful features of the hprof agent have been superseded by better alternatives.
Alternatives
Heap dumps: GC.heap_dump (jcmd <pid> GC.heap_dump)/ jmap –dump
Allocation profiler : Java VisualVm & other 3rd party tools
CPU profiler: Java VisualVm and Java Flight Recorder
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
What Next ?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Download Early Access and Try Java 9
https://jdk9.java.net/
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
How can Open Source projects get involved to test JDK 9?
• Helps open source projects understand changes and know how to test.
• Check your code for internal APIs using Jdeps.
• Run your tests on JDK 9.
https://wiki.openjdk.java.net/display/quality/Quality+Outreach
30
Join the OpenJDK Quality Outreach Campaign
Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Preparing your code for Java 9

More Related Content

PDF
Java 9 preview
PDF
Java 9 and Beyond
PPSX
Java 9 and the impact on Maven Projects (JavaOne 2016)
PPTX
Discuss about java 9 with latest features
PPTX
Java 9 Modularity and Project Jigsaw
PPSX
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
PDF
OpenJDK-Zulu talk at JEEConf'14
PDF
Migrating to Java 9 Modules
Java 9 preview
Java 9 and Beyond
Java 9 and the impact on Maven Projects (JavaOne 2016)
Discuss about java 9 with latest features
Java 9 Modularity and Project Jigsaw
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
OpenJDK-Zulu talk at JEEConf'14
Migrating to Java 9 Modules

What's hot (20)

PPSX
Java 9 and the impact on Maven Projects (Devoxx 2016)
PDF
Java11 New Features
PPSX
Java9 and the impact on Maven Projects (JFall 2016)
PDF
Workflow automation for Front-end web applications
PPTX
What's new in Java 11
PDF
Polygot Java EE on the GraalVM
PDF
Pitfalls of migrating projects to JDK 9
PDF
Java 10 New Features
PDF
Java SE 9 modules (JPMS) - an introduction
PDF
Flavors of Concurrency in Java
PPTX
Preparing for java 9 modules upload
PDF
Apache DeltaSpike the CDI toolbox
PDF
Migrating to java 9 modules
PDF
Java modularity: life after Java 9
PDF
JDK-9: Modules and Java Linker
PDF
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
PPTX
Node.js Development with Apache NetBeans
PDF
An Introduction to Play 2 Framework
PPTX
JDK 9: Big Changes To Make Java Smaller
PPTX
Faster Java EE Builds with Gradle
Java 9 and the impact on Maven Projects (Devoxx 2016)
Java11 New Features
Java9 and the impact on Maven Projects (JFall 2016)
Workflow automation for Front-end web applications
What's new in Java 11
Polygot Java EE on the GraalVM
Pitfalls of migrating projects to JDK 9
Java 10 New Features
Java SE 9 modules (JPMS) - an introduction
Flavors of Concurrency in Java
Preparing for java 9 modules upload
Apache DeltaSpike the CDI toolbox
Migrating to java 9 modules
Java modularity: life after Java 9
JDK-9: Modules and Java Linker
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Node.js Development with Apache NetBeans
An Introduction to Play 2 Framework
JDK 9: Big Changes To Make Java Smaller
Faster Java EE Builds with Gradle
Ad

Viewers also liked (12)

PDF
Разговор про Java 9. Extended version
PPTX
Lean UX and Design winning mobile apps
PDF
PDF
Embracing Reactive Streams with Java 9 and Spring 5
PDF
What's New in Java SE 9
PPTX
자바9 특징 (Java9 Features)
PPTX
Java 9 Functionality and Tooling
PDF
Real World Java 9 (QCon London)
PDF
What to expect from Java 9
PDF
Java9 특징 훑어보기
PPTX
55 New Features in JDK 9
PPTX
55 New Features in Java SE 8
Разговор про Java 9. Extended version
Lean UX and Design winning mobile apps
Embracing Reactive Streams with Java 9 and Spring 5
What's New in Java SE 9
자바9 특징 (Java9 Features)
Java 9 Functionality and Tooling
Real World Java 9 (QCon London)
What to expect from Java 9
Java9 특징 훑어보기
55 New Features in JDK 9
55 New Features in Java SE 8
Ad

Similar to Preparing your code for Java 9 (20)

PDF
Java Cloud and Container Ready
PDF
Java is Container Ready - Vaibhav - Container Conference 2018
PDF
Hotspot & AOT
PDF
Java 8
PDF
What's new in Java 8
PDF
Java 8 Overview
PDF
Serverless Java - Challenges and Triumphs
PDF
JDK 8 and JDK 8 Updates in OpenJDK
PDF
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
PPTX
Interactive Java Support to your tool -- The JShell API and Architecture
PDF
Building Large Java Projects Faster: Multicore javac and Makefile integration
PDF
Concierge - Bringing OSGi (back) to Embedded Devices
PDF
Serverless Java: JJUG CCC 2019
ODP
Java code coverage with JCov. Implementation details and use cases.
PPTX
Configuration for Java EE: Config JSR and Tamaya
PDF
JDK 10 Java Module System
PPTX
Java EE Arquillian Testing with Docker & The Cloud
PPTX
Java @ Cloud - Setor Público SP
PDF
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
PPTX
Lucene, Solr and java 9 - opportunities and challenges
Java Cloud and Container Ready
Java is Container Ready - Vaibhav - Container Conference 2018
Hotspot & AOT
Java 8
What's new in Java 8
Java 8 Overview
Serverless Java - Challenges and Triumphs
JDK 8 and JDK 8 Updates in OpenJDK
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Interactive Java Support to your tool -- The JShell API and Architecture
Building Large Java Projects Faster: Multicore javac and Makefile integration
Concierge - Bringing OSGi (back) to Embedded Devices
Serverless Java: JJUG CCC 2019
Java code coverage with JCov. Implementation details and use cases.
Configuration for Java EE: Config JSR and Tamaya
JDK 10 Java Module System
Java EE Arquillian Testing with Docker & The Cloud
Java @ Cloud - Setor Público SP
Java Webinar #12: "Java Versions and Features: Since JDK 8 to 16"
Lucene, Solr and java 9 - opportunities and challenges

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Cloud computing and distributed systems.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Modernizing your data center with Dell and AMD
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
Modernizing your data center with Dell and AMD
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Per capita expenditure prediction using model stacking based on satellite ima...

Preparing your code for Java 9

  • 2. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Preparing your code for Java 9 Eclipse Summit, India Deepu Xavier Product Manager Java Platform Group 26 August 2016
  • 3. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Agenda • Java 9 Schedule • How a developer can leverage and adjust to Java 9 features – Jshell – Javadoc Search – Internal API encapsulation – Process API – Convenience Factory Methods for Collections – Version String – V for Verona – Multi Release Jar Files – Gone, gone, gone… • The Jigsaw way – How to make your own modular image • What Next
  • 5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Java 9 Timeline Schedule Milestone Target Date Feature Complete 26 May 2016 All Tests Run 11 August 2016 Rampdown Start 01 September 2016 Zero bug Bounce 20 October 2016 Rampdown Phase 2 01 December 2016 Final Release Candidate 26 January 2017 General Availability 23 March 2017 https://jdk9.java.net/
  • 6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6 JDK Enhancement Proposals (JEPs) for Java 9 Total 84 JEPs Jigsaw Client Lib Core Lib Core SVC Hotspot JavaFX Security Lib Tools XML Others Version String Linux/AArch64 Port Infra & Deploy- 3 JEPs 7 JEPs 19 JEPs 2 JEPs 17 JEPs 3 JEPs 9 JEPs 15 JEPs 1 JEPs 5 JEPs Note: The content of this slide is based on information available as of 26th July 2016 6 JEPs
  • 7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7 Java 9: Jigsaw and Many More… Process API Improvements Multi-Resolution Images Interned String in CDS Unicode Compatibility Default GC JVM Command Validation Compact String Segmented Code Cache Reserved Stack Areas for Critical Sections Better Import Statement Handling Convenient Collections Handling Concurrency Updates Multi Release JAR Smart Compilation 2 HiDPI Graphics on Windows and Linux Microbenchmark Suite More JVM Diagnostic Commands Compile for Older Platform Versions Jigsaw HTTP2 Compliance New Version String http://openjdk.java.net/projects/jdk9/
  • 8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 222: JShell • Lets you try code. • Supports libraries, tab completion, up/down arrows, etc. • Not for “create a class or method from this prose.” 8 •Without JShell, I often wrote random unit tests or main methods to try things. •With JShell, I can try things and close it when I’m done. JEP 222
  • 9. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 225: Javadoc Search • Add a search box to generated API documentation that can be used to search for program elements and tagged words and phrases within the documentation. tools / javadoc(tool) Java 8 Javadoc: https://docs.oracle.com/javase/8/docs/api/ Java 9 Javadoc: http://download.java.net/java/jdk9/docs/api/index.html
  • 10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 260: Encapsulate Most Internal APIs • Make most of the JDK's internal APIs inaccessible by default but leave a few critical, widely-used internal APIs accessible, until supported replacements exist for all or most of their functionality – In order to keep critical APIs without a replacement accessible by default sun.misc and sun.reflect will not be hidden and a few APIs kept “public” • sun.misc.Unsafe • sun.misc.{Signal,SignalHandler} • sun.reflect.Reflection::getCallerClass • sun.reflect.ReflectionFactory – All other APIs in these packages (e.g. sun.misc.Base64) will be removed
  • 11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11 Categories of APIs in JDK • Supported, intended for external use • JCP standard, java.*, javax.* • JDK-specific API, some com.sun.*, some jdk.* • Unsupported, JDK-internal, not intended for external use • sun.* mostly
  • 12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12 Internal API Related Changes
  • 13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13 General compatibility policies •If an application uses only supported, non-deprecated, APIs and works on release N then it should work on N+1, even without recompilation •Supported APIs can be removed but only with advanced notice How we manage incompatibilities • Judge risk and impact based on actual data (where possible) • Communicate early and vigorously through Early Access, OpenJDK Mails etc. • Make it easy to understand how existing code will be affected • When removing unsupported APIs, provide replacements where it make sense • Provide workarounds where possible
  • 14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14 JEP 260 proposal Encapsulate all non-critical internal APIs by default Encapsulate all critical internal APIs for which supported replacements exist in JDK 8 Do not encapsulate critical internal APIs • Deprecate them in JDK 9 • Plan to remove in JDK 10 Provide a workaround via command-line flag Non-critical No evidence of use outside of JDK or used only for convenience Critical Functionality that would be difficult, if not impossible, to implement outside of the JDK
  • 15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15 Finding uses of JDK-internal APIs • jdeps tool in JDK 8, improved in JDK 9 • Maven JDeps Plugin $ jdeps -jdkinternals glassfish/modules/security.jar
  • 16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Code shown in the following examples are purely author’s imagination or used in a fictitious manner. Any resemblance to your application code “could be” purely coincidental. Internal API !!!
  • 17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. jdeps To The Rescue
  • 18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. The Right Way
  • 19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 102: Process API Updates 19 • There has been a huge limitation in managing and controlling OS processes with Java • Platform compatibility was always a challenge. At present, developers resort to native code or much verbose workaround • With Java 9, processes can be handled using new direct methods like: • ProcessHandle currProcess = ProcessHandle.current(); • ProcessHandle.allProcesses() .filter(processHandle -> processHandle.info().command().isPresent()) .limit(3) .forEach((process) ->{// action here} //In Windows Process myProc = Runtime.getRuntime().exec ("tasklist.exe"); InputStream procOutput = myProc.getInputStream (); if (0 == myProc.waitFor ()) { // actions here } //For Linux Process myProc = Runtime.getRuntime().exec("ps -e"); InputStream procOutput = myProc.getInputStream (); if (0 == myProc.waitFor ()) { // actions here } Note: This is just couple of new methods/ classes. Please refer the respective javadoc for full list
  • 20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. The Right Way
  • 21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 269: Convenience Factory Methods for Collections • Define library APIs to make it convenient to create instances of collections and maps with small numbers of elements, so as to ease the pain of not having collection literals in the Java programming language • Less boilerplate and reduced amount of code needed for creating small collections and maps • Set<String> set = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("a", "b", "c"))); – populate a collection using a copy constructor from another collection: • Set<String> set = Collections.unmodifiableSet(new HashSet<String>() {{ add("a"); add("b"); add("c"); }}); – use the so-called "double brace" technique: • Set<String> set = Collections.unmodifiableSet(Stream.of("a", "b", "c").collect(toSet())); – by combining stream factory methods and collectors Set<String> alphabet = Set.of("a", "b", "c");
  • 22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Overload Difficulty: List.of(array) Oracle Confidential – Internal 22 Suppose you have this: String[] array = { "a", "b", "c" }; List.of(array); Should this create: A. List<String> containing three strings? B. List<String[]> containing a single array? JEP 269 ANSWER: A. Compiler chooses varargs, so we get List<String> with three strings Probably right; list of arrays is rare. Workaround: List<String[]> listOfArray = List.<String[]>of(array);
  • 23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23 JEP 223: New Version-String Scheme Revise the JDK's version-string scheme so that it is easier to distinguish major, minor, and security-update releases. Goal is to device a new version numbering scheme which is  easily understandable  aligning with industry best practices (Semantic Versioning)  is easy to distinguish between major, minor and critical patch update (CPU) releases New scheme will follow MAJOR.MINOR.SECURITY (-PRE)?(+BUILD)?(-OPT)? convention MAJOR : The major version number will be incremented for every major release MINOR : The minor version number will be incremented for every minor update release MINOR is reset to zero when MAJOR is incremented SECURITY: The security version number will be incremented for every security update release SECURITY is reset to zero only when MAJOR is incremented A higher value of SECURITY for a given MAJOR value, therefore, always indicates a more secure release, regardless of the value of MINOR PRE: This represents a pre-release identifier. E.g. ea, for an early-access release BUILD: Build number may be promoted by 1 for every promoted build. BUILD is reset to one when any portion of MAJOR.MINOR.SECURITY is incremented OPT: Additional build information Note: Existing code that assumes the initial element to have the value 1, however, and therefore always skips to the second element when comparing version numbers, will not work correctly e.g., such code will consider 9.0.1 to precede 1.8.0. Version # Detail 9 Java 9 GA 9.0.1 CPU: 9 + critical changes 9.1.1 Minor release: 9.0.1 + other changes 9.1.2 CPU: 9.1.1 + critical changes 9.2.2 Minor release: 9.1.2 + other changes Hypothetical Release Sequence (for illustration only)
  • 24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 282: jlink: The Java Linker • Create a tool that can assemble and optimize a set of modules and their dependencies into a custom run- time image as defined in JEP 220. Define a plugin mechanism for transformation and optimization during the assembly process, and for the generation of alternative image formats • Create a custom runtime optimized for a single program • JEP 261 defines link time as an optional phase between the phases of compile time and run time. Link time requires a linking tool that will assemble and optimize a set of modules and their transitive dependencies to create a run-time image or executable.
  • 25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 25 JEP 238: Multi-Release JAR Files Extend the JAR file format to allow multiple, Java-release-specific versions of class files to coexist in a single archive. • It is practically difficult to express conditional platform dependencies or to distribute separate library artifacts for each new java version • A multi-release JAR ("MRJAR") will contain additional directories for classes and resources specific to particular Java platform releases. With this, it is possible for versions of a class designed for a later Java platform version to override the version of that same class designed for an earlier Java platform release. META-INF Content Root A.class B.class C.class D.class Normal JAR META-INF versions -8 A.class B.class -9 A.class Content Root A.class B.class C.class D.class MR JAR
  • 26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 289: Deprecate the Applet API • Deprecate the Applet API, which is rapidly becoming irrelevant as web-browser vendors remove support for Java browser plug-ins JEP 241: Remove the jhat Tool • Remove the antiquated jhat tool • jhat is an experimental, unsupported, and out-of-date tool added in JDK 6 • Superior heap visualizers and analyzers have now been available for many years
  • 27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JEP 231: Remove Launch-Time JRE Version Selection • Remove the ability to request, at JRE launch time, a version of the JRE that is not the JRE being launched. • Modern applications are typically deployed via Java Web Start (JNLP), native OS packaging systems, or active installers, and all of these technologies have their own ways of finding, and even sometimes installing and later updating, an appropriate JRE for the application. JEP 240: Remove the JVM TI hprof Agent • Remove the hprof agent from the JDK • The hprof agent was written as demonstration code for the JVM Tool Interface and not intended to be a production tool. • The useful features of the hprof agent have been superseded by better alternatives. Alternatives Heap dumps: GC.heap_dump (jcmd <pid> GC.heap_dump)/ jmap –dump Allocation profiler : Java VisualVm & other 3rd party tools CPU profiler: Java VisualVm and Java Flight Recorder
  • 28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. What Next ?
  • 29. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Download Early Access and Try Java 9 https://jdk9.java.net/
  • 30. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. How can Open Source projects get involved to test JDK 9? • Helps open source projects understand changes and know how to test. • Check your code for internal APIs using Jdeps. • Run your tests on JDK 9. https://wiki.openjdk.java.net/display/quality/Quality+Outreach 30 Join the OpenJDK Quality Outreach Campaign
  • 31. Copyright © 2016, Oracle and/or its affiliates. All rights reserved.