96
Copyright © 2017, Oracle and/or its affiliates. All rights reserved JDK 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs Joseph D. Darcy (@ jddarcy) Java Platform Group Oracle October 3, 2017 1

JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Embed Size (px)

Citation preview

Page 1: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved

JDK 9 Language, Tooling, and Library FeaturesMore than modules!#JDK9LangToolsLibs

Joseph D. Darcy (@jddarcy)Java Platform GroupOracleOctober 3, 2017

1

Page 2: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, 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.

Page 3: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved 3

Pic

ture

s co

pyr

igh

t 2

01

2 J

ose

ph

D. D

arcy

All

righ

ts r

eser

ved.

Page 4: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Survey: Which JDK train are you using in production?

4

• JDK 9

• JDK 8

• JDK 7

• JDK 6

• JDK 5.0 orolder

Page 5: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

JDK 9Overview

5

Page 6: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

JDK 9 Information

• JDK 9 GA September 21, 2017:

• Downloads: http://www.oracle.com/javadownload/

• OpenJDK :

• Project: http://openjdk.java.net/projects/jdk9/

• Mailing list: http://mail.openjdk.java.net/mailman/listinfo/jdk9-dev

• Source code: http://hg.openjdk.java.net/jdk9/jdk9/

• Adoption: http://mail.openjdk.java.net/pipermail/adoption-discuss/https://wiki.openjdk.java.net/display/quality/Quality+Outreach/

• JEPs (JDK Enhancement Proposals) used for feature organization and tracking

6

Page 7: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

http://openjdk.java.net/projects/jdk9/

7

JDK 9GA

Cumulative bugs fixes by build in JDK 8 and 9

0

5000

10000

15000

20000

0 20 40 60 80 100 120 140 160 180

JDK 8 cumulative

JDK 9 cumulative

Difference (9-8)

JDK 8GA

Page 8: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Capsule summary of modularity impact in JDK 9

• Modules for programming in the large

• Modules bundle together one or more packages for reuse and can offer stronger encapsulation than jars

• Supporting changes throughout the platform:

• module-info.java files to declare dependencies between modules

• Changes to javac command line to find types in modules as well as in jars

• Corresponding updates to java command line and HotSpot JVM runtime

• New reflective APIs to model modules (core reflection, javax.lang.model, etc.)

8

Page 9: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

• Prepare for JDK 9 [CON6074], Alan Bateman,Monday, Oct 02, 11:00 am – 11:45 am

• Modular Development with JDK 9 [CON2773], Alex Buckley,Monday, Oct 02, 5:30 pm – 6:15 pm

• Modules in One Lesson [CON6120], Mark Reinhold,Tuesday, Oct 03, 11:00 am – 11:45 am

• Migrating to Modules [CON6122], Mark Reinhold,Tuesday, Oct 03, 1:15 pm – 2:00 pm

• Modules and Services [CON2774], Alex Buckley,Wednesday, Oct 04, 9:30 am – 10:15 am

9

Jigsaw Team JavaOne 2017 Modularity Sessions

Page 10: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Outline

• Stewardship and platform evolution

• Tooling improvements

• Language changes

• Library updates

• Q & A

10

Many feature cross these boundaries

Page 11: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Stewardship11

Page 12: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Background: JDK General Evolution Policy

“The general evolution policy for Java SE APIs implemented in OpenJDK is:

1. Don’t break binary compatibility (as defined in the Java Language Specification).

2. Avoid introducing source incompatibilities.

3. Manage behavioral compatibility changes.”

• Extends to language evolution too

• Continue to recognize old class files

• Limit cases where currently legal code stops compiling

• Avoid changes in code generation introducing behavioral change

• Goal: balance between stability and progress

12

From the OpenJDK Developers’ Guide

Page 13: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs 13

Release Compatibility Regions

Behavioral

Bin

ary

Security Update Releases (CPU), 8u121, 8u131, 8u141, … …

Feature Update Releases (PSU), 8u20, 8u40, …

Note: Figure not drawn to scale.

Page 14: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs 14

Platform Release Compatibility Region

Behavioral

Bin

ary

Platform Release, JDK 8 GA, JDK 9 GA

Note: Figure not drawn to scale.

Page 15: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Example: changing the iteration order of HashSet

• Specification of HashSet.iterator() :“Returns an iterator over the elements in this set. The elements are returned in no particular order.”

• Changing iteration order is allowed by the specification and:

• Binary compatible (same set of methods)

• Source compatible (compilation of clients independent of iterator method body)

• But a change in behavioral compatibility;people can and do implicitly (and accidentally) rely on iteration order

• Therefore, this kind of change generally wouldn’t be made in either kind of update release, but would be (and has been) made in a platform release.

15

Page 16: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Check the release notes and compatibility/migration guides

• Use source, binary, behavioral categorization

• Compatibility guides distinguish between

• Java SE incompatibilities

• JDK incompatibilities

• JDK 8 Compatibility Guide discusses changingthe order of methods returned by Class.getMethods()

• JDK 9• Release notes

• Migration guide

16

Page 17: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

How is JDK 9 different?

• Same general model, but to support adding modularity, larger compatibility impact than usual allowed, including behavioral incompatibilities

• Certain build artifacts going away; no more rt.jar!

• Driven by modularity, even breaking binary compatibility in very select cases by removing ill-placed APIs including:

• Break unfortunate dependencies on Java Beans, part of the java.desktop module:• java.util.logging.LogManager.{add, remove}PropertyChangeListener

• java.util.jar.Pack200.Packer/Unpacker.{add, remove}PropertyChangeListener

• Also: java.awt.Component.getPeer removed since it referred to ComponentPeer types outside of Java SE

• More muscular deprecation policy with better tools to manage and inform

17

Page 18: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Outline

• Stewardship and platform evolution

• Tooling improvements

• Language changes

• Library updates

• Q & A

18

Page 19: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

jshell

19

Page 20: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

A historical perspective on REPL

• Lisp systems decades back provided a read-evaluate-print-loop (REPL) to interact with the language

• Similar functionality is found in Ruby and Python as well as Scala, Groovy, and Clojure

• What about Java?

20

Page 21: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

jshell – new command in $JDK/bin in JDK 9

• Teaser Demo

• Less ceremony for students learning Java;don’t have start with public static void main(…)

• Less formal way for experienced developers to

• Explore using a new API

• Experiment with new language features

• Snippets and commands

• Implementation leverages many existing JDK technologies

• Java Shell User’s Guide

21

OpenJDK Project Kulla/JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)

Page 22: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Wednesday is jshell day at JavaOne 2017!

• JShell: An Interactive Shell for the Java Platform [CON3969],Robert Field, Wednesday, Oct 04, 9:30 am – 10:15 am

• JShell: The Ultimate Missing Tool [CON1188],Hakan Ozler & Rahman USTA, Wednesday, Oct 04, 10:45 am – 11:30 pm

• Visual JShell: JShell on Steroids [CON6166],Michael Hoffer, Wednesday, Oct 04, 12:45 pm – 1:30 pm

• Exploring Java 9 with REPL [CON3423], Miro Cupak, Wednesday, Oct 04, 1:45 pm – 2:30 pm

22

(At least none of the talks are scheduled at the same time.)

Page 23: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

JavaDoc.Nexthttp://openjdk.java.net/projects/javadoc-next/

23

Page 24: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

HTML 5

• The javadoc tool has historically generated HTML 4.01 output

• HTML 5 is a new HTML standard, finalized October 2014

• Richer semantic structure

• New attributes defined

• Use javadoc -html5 …

to opt-into the new output

• (Still uses frames-style layout)

24

JEP 224: HTML5 Javadoc

HTM

L 5

logo

fro

m w

ww

.w3

.org

/htm

l/lo

go/i

nd

ex.h

tml

Page 25: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Configuring doclint

• Doclint checks can be run as part of javadoc or as part of javac;(both used in JDK build)

• HTML checks are appropriate for chosen version of HTML output

• Checks can be limited to chosen language accessibility (public, protected, …)

• Checks can be enabled / disabled per category

• Example, for public and protected types, do all checks except for reference:-Xdoclint:all/protected,-reference

• Checks can be limited to selected packages (new in JDK 9):

• To check java.* and javax.*: '-Xdoclint/package:java.*,javax.*'

• To exclude example.com: '-Xdoclint/package:-example.com.*'

25

Page 26: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Doclint and package filtering

• Doclint, added in JDK 8, performs various structural and semantic checks on javadoc tags in various categories:

• Accessibility: conditions that may be flagged by an accessibility checker, such as obsolete attributes or headers out of sequence

• HTML: HTML conformance issues (vary with DOCTYPE), e.g. anchor already defined, bad start-end tag matching

• Missing: missing comment or missing tag within a comment (e.g. not all parameters have a @param tag)

• Reference: the target of an @see, @link, @throws, etc. is invalid

• Syntax: malformed HTML in comments

26

Page 27: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Simplified Doclet API

• Doclets are plugins to javadoc; standard doclet most commonly used

• Doclet APIs

• Don’t follow current best-practices for API design

• Uses an inaccurate and hard to evolve language model

• Replace old Doclet APIs with newer APIs with better functionality

• Use java.compiler/javax.lang.model API for language model

• Use DocTree API (jdk.compiler/com.sun.source.doctree)

• Simpler and more compact

27

JEP 221: Simplified Doclet API

Page 28: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

javadoc search

• Demo!

• By default javadoc output now has a search box• Client-side implementation in JavaScript

• Indexes package names, type names, field names, module names

• Can include new tag to add other index items using {@index}

28

JEP 225: Javadoc Search

Page 29: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Getting from one JDK release to anotherMulti-release jar files and javac --release

29

Page 30: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Cross-compiling with the --release flag

30

Page 31: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Cross-compiling to older releases

31

https://blogs.oracle.com/darcy/entry/how_to_cross_compile_for

• To use javac to compile to older release N, must set

• -source N

• -target N

• -bootclasspath jdkN/lib/rt.jar

Page 32: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Policy on older releases: 1 + 3 back

• Started implementing in JDK 8

• In JDK 9, supported -source/-target values:• 9 (the default)

• 8

• 7

• 6 (deprecated, warning issued when used)

• In JDK 10/18.3, supported -source/-target values: 10/18.3, 9, 8, 7 (deprecated)

32

JEP 182: Policy for Retiring javac -source and -target Options

Page 33: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs 33

Why the bootclasspath needs to be set

// JDK Npublic class Library {

public void foo(double d) {…}}

// JDK N+1public class Library {

public void foo(double d) {…}public void foo(int i) {…}

}

public class Client {public static void main(String… args) {

(new Library()).foo(1234);}

}

If Client is compiled against JDK N+1 but run against JDK N:Exception in thread "main" java.lang.NoSuchMethodError: Library.foo(I)V

at Client.main(Client.java:3)

Page 34: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

An explicit warning as of JDK 7

• javac –cp … -source 6 -target 6 Client.java warning: [options] bootstrap class path not set in conjunction with -source 1.6

• The warning can be suppressed with -Xlint:-options

• But despite the warning, bugs still came in…

34

https://blogs.oracle.com/darcy/entry/bootclasspath_older_source

Page 35: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

JDK 9’s do-what-I-want approach: --release N

• javac --release N … is semantically equivalent tojavac -source N -target N –bootclasspath rtN.jar…

• Information about APIs of earlier releases available to javac• Stored in a compressed fashion

• Only provide Java SE N and JDK N-exported APIs that are platform neutral

• Same set of release values N as for -source/-target

• Incompatible combinations of options rejected

35

JEP 247: Compile for Older Platform Versions

Page 36: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Advantages of --release N

• No user need to manage artifacts storing old API information

• Should remove need to use tools like the Maven plugin Animal Sniffer

• May use newer compilation idioms than the javac in older releases• Bug fixes

• Performance improvements; faster type inference implemented in JDK 9 (JEP 215: Tiered Attribution for javac)

36

SecondsNote: log scale

on y-axis

Diamond nesting level0.25

1

4

16

64

256

1024

4096

2 7 12 17 22

Compilation time

$JDK8/javac

$JDK9/javac

JDK9/javac --release 8

Page 37: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Multi-release jar filesJEP 238: Multi-Release JAR Files

37

Page 38: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Issues distributing a jar file for multiple JDK releases

• Inconvenient to package and distribute multiple jar files for an API, one for JDK N, another for JDK N+1, etc.

• Instead use a single jar file to run against multiple JDK releases, so compile for the oldest release supported

• Slows adoption of new features

• Able to use reflection in some circumstances, but slow and awkward

• Modularity features of JDK 9 make some shouldn’t-be-used JDK APIs harder to access (don’t use sun.* APIs!)

38

Page 39: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

An alternative: multi-release jar files

• Common/shared contents of the jar are put in the root as usual

• JDK-platform specific overrides are put in the META-INF directory in subdirs, e.g. META-INF/versions/9, META-INF/versions/10, etc.

• Can have a jar file that acts as a traditional jar file pre-JDK 9 but a modular jar file on JDK 9 and later

• Created using additional arguments to the jar command

• java.util.jar.JarFile and consumers of jar files (java, javac, jarsigner, …) updated to be multi-release aware

39

Page 40: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Building multi-release jar files

• Tool support

• Ant

• Maven: Use two execution blocks

• Demo by @trisha_gee of creating multi-release jar files in IntelliJ

• Check your local tool documentation

40

Page 41: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Outline

• Stewardship and platform evolution

• Tooling improvements

• Language changes

• Library updates

• Q & A

41

Page 42: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Project Coin features in JDK 7

• Binary literals and underscores in literals

• Strings in switch

• Diamond

• Multi-catch and more precise rethrow

• try-with-resources

• Varargs warnings

42

Standardized under JSR 334

Page 43: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

A few small planned amendments in JDK 9

• Allow @SafeVargs on private instance methods.

• Allow effectively-final variables to be used as resources in the try-with-resources statement.

• Allow diamond with anonymous classes if alltype arguments of the inferred types are denotable.

• Complete the removal, begun in Java SE 8, of underscore from the set of legal identifier names.

• Source-level private interface methods.

43

JEP 213: Milling Project Coin

Ph

oto

co

pyr

igh

t 2

01

1 J

ose

ph

D. D

arcy

. All

righ

ts r

eser

ved

.

λ

Page 44: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

@SafeVarargs on private instance methods

44

Page 45: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Example from JDK 5.0 and 6

List<List<String>> monthsInTwoLanguages =

Arrays.asList(Arrays.asList("January", "February"),

Arrays.asList("Gennaio", "Febbraio"));

45

See JLSv3 §4.12.2.1 – Heap Pollution

warning: [unchecked] unchecked generic array creation for varargs parameter of type List<String>[]

Arrays.asList(Arrays.asList("January",^

But nothing bad actually happens in this case, so the error is uninformative.

Page 46: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Reminder: @SafeVarargs from Project Coin

• New annotation type java.lang.SafeVarargs and application to libs

• Summary: no longer receive uninformative unchecked compiler warnings from calling platform library methods:• <T> List<T> Arrays.asList(T... a)

• <T> boolean Collections.addAll(Collection<? super T> c, T... elements)

• <E extends Enum<E>> EnumSet<E> EnumSet.of(E first,E... rest)

• void javax.swing.SwingWorker.publish(V... chunks)

• Removes warnings from method call sites, the uses of the methods

46

Page 47: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Annotation Properties

• Annotations are only inherited on classes, not on interfaces or methods

• Therefore, a @SafeVarargs annotation can only be used on methods that cannot be overridden:

• final methods

• static methods

• Constructors (from a certain point of view, special static methods)

• private methods (omitted in Java SE 7)

47

Page 48: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Language Specification updates

• JLS §9.6.4.7. @SafeVarargsIt is a compile-time error if a variable aritymethod declaration that is neither static nor finalis annotated with the annotation @SafeVarargs.

48

nor private

Page 49: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Effectively final variables & try-with-resources

49

Page 50: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Refresher: try-with-resourcesYou type this:

try (Resource r = aa()) {bb(r);

} catch (Exception e) {cc();

} finally {dd();

}

Compiler generates (approximately) this:

try {Resource r = null;try {

r = aa();bb(r);

} finally {if (r != null)

r.close();}

} catch (Exception e) {cc();

} finally {dd();

}

It’s actually more complicated because of the way exceptions from close() are handled.

Page 51: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

try ResourceSpecificationBlock

{final VariableModifiers_minus_final R #resource = Expression;Throwable #primaryException = null;

try ResourceSpecificationtailBlock

catch (Throwable #t) {#primaryException = t;throw #t;

} finally {if (#resource != null) {if (#primaryException != null) {

try {#resource.close();

} catch(Throwable #suppressedException) {#primaryException.addSuppressed(#suppressedException);

}} else {

#resource.close();}

}}

}

Full disclosure: try-with-resources actual desugaring

Page 52: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Structure of the resources to be managed

• In Java SE 7, the resources to be managed by a try-with-resources statement must be fresh variables declared in the statement:try (Resource r = …)

• The original proposal allowed general expressions that were AutoCloseable, but this was found to be problematic for a variety of reasons such as:Resource r = new Resource1(); // First resource objecttry (r) {r = new Resource2(); // Second resource object

}// Which object(s) should have a close method called?

52

Page 53: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Refined proposal: reuse final or effectively final resources

• Instead of general expressions, just allows variables that are either:

• final or

• effectively final

to be used as resources.

• Effectively final variables are not explicitly declared as final, but could be and still have the program compile, see JLS §4.12.4.

• Variables have an explicit type, avoiding the need for type inference.

53

Page 54: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Example

Instead offinal Resource r = new Resource();try (Resource r2 = r) {…

}

can just usefinal Resource r = new Resource();try (r) {… // Cannot mutate r

}

54

Page 55: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Diamond with anonymous classes, take two

55

Page 56: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Diamond starting in JDK 7

• Use type inference inside the compiler to avoid having to include explicit type parameter arguments to constructors. Instead ofList<Map<String, Integer>> romanNumerals =

new ArrayList<Map<String, Integer>>();can just writeList<Map<String, Integer>> romanNumerals = new ArrayList<>();

• Very effective at removing the need for explicit type arguments, but due to a bad worst-case interaction forbidden from using diamond with anonymous classes.

• Type inference can infer non-denotable types which cannot be represented as needed in the class file generated for the anonymous class.

• In many cases, a denotable type is inferred, which could be represented in a class file.

Page 57: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

A forward-looking statement from the JSR 334 Expert Group

“Internally, a Java compiler operates over a richer set of types than those that can be written down explicitly in a Java program. The compiler-internal types which cannot be written in a Java program are called non-denotabletypes. Non-denotable types can occur as the result of the inference used by diamond. Therefore, using diamond with anonymous inner classes is notsupported since doing so in general would require extensions to the class file signature attribute to represent non-denotable types, a de facto JVM change. It is feasible that future platform versions could allow use of diamond when creating an anonymous inner class as long as the inferred type was denotable.”

JSR 334 Proposed Final Draft, June 2011

Page 58: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Java SE 9 allows use of diamond when creating an anonymous inner class as long as the inferred type is denotable. (JDK-8073593)

58

Page 59: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Effectiveness of recutting diamond

• In JDK 7, diamond could eliminate explicit type arguments at ≈90% of constructor call sites

• Diamond with anonymous classes should allow removal of a large fraction of the remaining 10%.

• JDK code base updated to use this feature, hundreds of call sites (JDK-8078467)

• Main beneficiaries were uses of java.security.PrivilegedAction

59

Page 60: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

An underscore is no longer an identifier nameJDK-8061549: Disallow ‘—‘ as a one-character identifier

60

Page 61: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Starting in Java SE 8

• Part of Project Lambda / JSR 335

• Cannot use ‘_’ as an identifier for a lambda parameter; avoid confusion with “wunderbar” from other languages

• If used elsewhere legal, but generates a warning; from javac:warning: '_' used as an identifier (use of '_' as an identifier might not be supported in releases after Java SE 8)

• Only a single underscore as an identifier generates a warning, use as a separator inside a longer identifier is fine

61

Discussed in http://mail.openjdk.java.net/pipermail/lambda-dev/2013-July/010661.html

Page 62: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Future possibilities

• Partial diamond:new Foo<String, _>();

• Partial witnesses:foo.<String, _>bar()

• “Don’t care” parameter names, suppress “variable not used” warnings

• …

• Some options under consideration as part of JEP 302: Lambda Leftovers, part of Project Amber

62

Syntactic name reclamation

Page 63: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

private interface methods

63

Page 64: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Background: default methods

• Starting in Java SE 8, as part of Project Lambda interfaces can have default methods.

• Default methods are non-abstract and thus have a method body.

• At the JVM level, interfaces could have private methods; helpful to implement lambdas, etc.

• However, private interface methods were not valid in the source language.

64

Page 65: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Now in Java SE 9...

• As planned, now in Java SE 9 interfaces can have private methods in the source level too:

• static methods

• instance methods

• Sample usage: helper methods to implement public default methods

65

JDK-8071453: Allow interface methods to be private

Page 66: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Forward looking statement

An anticipated benefit of the new six month release cadence for JDK releases is that small language changes like the preceding five cleanups should be able to be delivered into a shipping release with reduced latency.

66

Six month release cadence and small language cleanups

Page 67: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Deprecation and importsJEP 211: Elide Deprecation Warnings on Import Statements

67

Page 68: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Deprecation warnings historically

• Several hundred deprecation warnings in the JDK

• Generated by use of deprecated types, methods, constructors, fields

• Mandated by JLS §9.6.4.6 @Deprecated

• Can resolve warnings by:

• Removing use of the deprecated element(s)

• Propagating @Deprecated to the use-sites too (a cure worse than the disease!)

• @SuppressWarnings("deprecation")

68

Page 69: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

import p.DepLib;

public class Client2 {

public static void main(String… args) {

DepLib dl = new DepLib();

dl.foo();

}

}

Note: Client2.java uses or overrides a deprecated API.

// DepLib.java

package p;

@Deprecated

public class DepLib {

public DepLib() {}

public void foo() {return;}

}

69

A wrinkle in Java SE 5.0 through 8

Page 70: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

import p.DepLib;

@SuppressWarnings("deprecation")

public class Client2 {

public static void main(String… args) {

DepLib dl = new DepLib();

dl.foo();

}

}

Note: Client2.java uses or overrides a deprecated API.

// DepLib.java

package p;

@Deprecated

public class DepLib {

public DepLib() {}

public void foo() {return;}

}

70

A wrinkle in Java SE 5.0 through 8

Page 71: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Deprecation warning in detail

Client2.java:1: warning: [deprecation] DepLib in p has been deprecatedimport p.DepLib;

^1 warning

• Warning on import mandated by the JLS

• Use of the type in this location cannot be annotated for suppression

• Warning is unhelpful; if all other uses of the deprecated type can be suppressed, shouldn’t have to resort to using its fully qualified name everywhere to be warning-free.

71

With javac -Xlint:deprecation …

Page 72: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Specification update in JLS 9: JLS §9.6.4.6 @Deprecated

A Java compiler must produce a deprecation warning when a type, method, field, or constructor whose declaration is annotated with the annotation @Deprecatedis used (i.e. overridden, invoked, or referenced by name), unless:

• The use is within an entity that is itself annotated with the annotation @Deprecated; or

• The use is within an entity that is annotated to suppress the warning with the annotation @SuppressWarnings("deprecation"); or

• The use and declaration are both within the same outermost class.

• The use is within an import statement that imports the type or member whose declaration is annotated with @Deprecated.

72

; or

Page 73: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Result: now tractable to clear a code base of deprecation warnings.Existence proof: java.base and java.desktop modules in the JDK.

73

Page 74: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

More on deprecation: what does deprecation mean?

• Don’t use it because it’s harmful?

• Don’t use it because it is going away?

• Why aren’t items deprecated years ago removed yet?

• …

74

Page 75: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

More informative @Deprecated annotation type in 9

• Clarified semantics and more information in the Deprecated type:

• boolean forRemoval() (defaults to false)

• String since() (defaults to "")

• Example: @Deprecated(since="9", forRemoval=true)

• New lint category “removal” for using items @Deprecated(forRemoval=true)

• @Deprecated annotations in core platform updated

• Supporting updates to JLS, javac, javadoc

• New static analysis tool: jdeprscan, analyzes class files and jar files for use of APIs deprecated in the JDK

75

JEP 277: Enhanced Deprecation

Page 76: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Outline

• Stewardship and platform evolution

• Tooling improvements

• Language changes

• Library updates

• Summary and Q & A

76

Page 77: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

New Version-String Scheme

• Summary the “1.” in “1.9” is going away being replaced with$MAJOR.$MINOR.$SECURITY

• Full version strings can also have build numbers and optional information

• Oldjava version "1.8.0_101"Java(TM) SE Runtime Environment (build 1.8.0_101-b13)Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

• Newjava version "9"Java(TM) SE Runtime Environment (build 9+181)Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

77

JEP 223: New Version-String Scheme

Page 78: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Process API Updates

• On java.lang.Process new methods to get the PID, direct children, and all descendents

• New java.lang.ProcessHandle interface for better control

78

JEP 102: Process API Updates

Page 79: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Strings and string concatenation

• JEP 254: Compact Strings: replace String-internal char[] representation (16 bits/char) with a byte[] array plus encoding field

• Based on contents of string, either 1-byte per character or 2-bytes per character representation. Transparent to users; same API with better memory density

• JEP 280: Indify String Concatenation: string concatenation is a common operation; javac compiles this down to StringBuilder calls. Call pattern may not be optimal for a given JVM implementation.

• New stable library entry point java.lang.invoke.StringConcatFactory

• Effectively adds new JVM capability without defining a new bytecode

• Compilers use this facility; dynamically linked at runtime, optimized by JVM; used in javac with –source 9 (and later)

79

Page 80: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Security libraries and tooling overview

80

Page 81: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Security area goals and roadmap

• Provide out-of-the box secure defaults

• Restrict broken or weak cryptographic algorithms and protocols

• Ensure API and tool defaults are safe to use

• Provide sufficiently strong algorithms for every security function

• Incorporate new security standards & adhere to industry best practices

• Crypto Roadmap: http://java.com/cryptoroadmap

• Public document of Oracle’s upcoming restrictions and changes to security defaults

• First published August 2016

• Most recent update July 2017

81

Page 82: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Highlights of security updates in 9

• More secure crypto defaults including increasing the key size for the RSA and DiffieHellman implementations from 1024 bits to 2048 bits

• Certificates with weak keys no longer accepted by default

• New crypto hash SHA-3 (JEP 287)

• Better SecureRandom algorithm (JEP 273)

• Accelerated crypto operations on x64 and Sparc (JEP 246)

• More information:Making the JDK More Secure [CON4604], Sean Mullan, Monday, Oct 02, 4:30 pm – 5:15 pm

82

Page 83: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Client libraries and FX

83

Page 84: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

FX

• Modularity

• JavaFX is now modularized; strong encapsulation

• JEP 253: Public UI Control skins and more CSS APIs

• New APIs for previously non-public features

• Other improvements:

• High DPI: Linux support + API to query & control scaling

• JEP 283: Enable GTK 3 on Linux

• Updated GStreamer and WebKit

• Smaller enhancements + Bug fixes

84

Page 85: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Client libraries (awt, swing, imageio, etc.) summary

• Finished generification of the Swing and awt APIs!

• High-dpi screens across all operating systems; JEP 263

• HarfBuzz Font-Layout Engine, JEP 258

• Marlin Graphics Renderer, JEP 265, replacing both Pisces and Ductus

• Reduces behavioral difference between OpenJDK and Oracle JDK builds

• TIFF support in imageio, JEP 262

• Read/write Exif metadata to native JPEG metadata, useful in dealing with many digital images

85

Page 86: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

More information on Client libraries and FX

• HarfBuzz: Modern OpenType Layout Comes to JDK 9 (JEP 258) [BOF4226], Philip Race & Steven Loomis, Monday, Oct 02, 6:30 pm – 7:15 pm

• Updating Your Java Client Desktop and JavaFX Applications for JDK 9 [CON5795], Kevin Rushforth & Philip Race, Tuesday, Oct 03, 3:00 pm – 3:45 pm

• Meet the Oracle JavaFX and JDK Client Team [BOF4507], Kevin Rushforth & Philip Race, Tuesday, Oct 03, 6:45 pm – 7:30 pm

• Marlin, a JDK9 Success Story: Vector Graphics on Steroids for Java 2D and JavaFX [CON4052], Jim Graham & Laurent Bourgès, Wednesday, Oct 04, 1:45 pm – 2:30 pm

86

Page 87: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Miscellaneous library treats

87

Page 88: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Convenience Factory Methods for Collections

How many times have you written code like:Set<String> set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set);

or likeSet<String> set =Collections.unmodifiableSet(new HashSet<>(

Arrays.asList("a", "b", "c")));

88

JEP 269: Convenience Factory Methods for Collections

Page 89: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

No more!

• Can now write:Set<String> set = Set.of("a", "b", "c");

• New static factory methods named “of” on Set, List, and Map.• Approximates functionality of collection literals at a fraction of the complexity.

• Return unmodifiable collections.

• Randomized iteration for set and maps.

• For more information seeCollections Refueled [CON5965],Stuart Marks (@stuartmarks), Tuesday, Oct 03, 8:30 am – 9:15 am

89

Page 90: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

New public static methods in java.util.Objects

• <T> T requireNonNullElse(T obj, T defaultObj)

• <T> T requireNonNullElseGet(T obj,Supplier<? extends T> supplier)

• int checkIndex(int index, int length)

• int checkFromToIndex(int fromIndex, int toIndex, int length)

• int checkFromIndexSize(int fromIndex, int size, int length)

90

Page 91: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Odds and ends

• Mathematical functions

• {Math, StrictMath}.fma() (fused-multiply accumulate)

• {Math, StrictMath}.{multiplyExact, floorDiv, floorMod}

• BigInteger.sqrt, BigDecimal.sqrt

• Lexicographical array comparison in java.util.Arrays (with intrinsics!)

• Timeouts added to java.util.concurrent.CompletableFuture

• java.lang.invoke.VarHandle on par with C++ atomics;see Paul Sandoz’s Safety First 2015 JVMLS talk

91

Page 92: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Other JDK 9 Survey Talks

• JDK 9 Hidden Gems [CON4529],Mikael Vidstedt & Sandhya Viswanathan,Monday, Oct 02, 12:15 pm – 1:00 pm

• 55 New Features In JDK 9 [CON3835],Simon Ritter, Wednesday, Oct 04, 10:45 am – 11:30 am

• The Good Cop/Bad Cop Guide to Java 9 [CON6076],Simon Maple & Oleg Shelajev, Wednesday, Oct 04, 4:30 pm – 5:15 pm

92

Page 93: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Summary

93

Page 94: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

JDK 9 Language, Tooling, and Library features

• Fundamental development changes with modularity

• Smaller improvements in other areas:

• Finish long-anticipated polishing of Project Coin, Project Lambda, and other language enhancements

• Features to support long-term evolution and multi-release planning

• Large and small features cross language, tooling, library, (and JVM) areas

• Can follow developments in OpenJDK

• Try out JDK 9 GA!

94

Page 95: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …

Copyright © 2017, Oracle and/or its affiliates. All rights reserved #JDK9LangToolsLibs

Q & ASlides:http://www.jddarcy.org/Conferences/JavaOne/J1_2017-jdk9-lang-tools-libs.pdf

JDK 9 downloads: http://www.oracle.com/javadownload/Follow-up questions: #JDK9LangToolsLibs

Future work: @OpenJDK

95

Page 96: JDK 9 Language, Tooling, and Library Features - … 9 Language, Tooling, and Library Features More than modules! #JDK9LangToolsLibs ... people can and do implicitly (and …