JDK 9 Language, Tooling, and Library Features More than modules!

#JDK9LangToolsLibs

Joseph D. Darcy (@jddarcy) Platform Group Oracle September 19, 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. 2

. Pictures copyright 2012 Joseph D. Darcy All rights reserved All rights Darcy 2012 JosephD. copyright Pictures

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 3 Survey: Which JDK train are you using in production?

• JDK 9 EA with cutting edge Jigsaw • JDK 9 EA • JDK 8 • JDK 7 • JDK 6 • JDK 5.0 or older

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 4 JDK 9 Overview

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 5 JDK 9 Information • Current proposed schedule: GA July 2017, weekly updates: • Early access binaries + docs: https://jdk9.java.net/ • Early access binaries with cutting edge Jigsaw: https://jdk9.java.net/jigsaw/ • 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/dev/ • Adoption: http://mail.openjdk.java.net/pipermail/adoption-discuss/ https://wiki.openjdk.java.net/display/quality/Quality+Outreach/ • JEPs (JDK Enhancement Proposals) used for project tracking

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7 Capsule summary of modularity impact in JDK 9 • Modules bundle together one or more packages 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 runtime • New reflective APIs to model modules (core reflection, javax.lang.model, etc.)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8 Jigsaw Team JavaOne 2016 Modularity Sessions & Tutorial • Prepare for JDK 9 [CON2937] • Project Jigsaw: Under the Hood Monday, Sep 19, 12:30 pm – 1:30 pm [CON2963], Tuesday, Sep 20, 2:30 pm – 3:30 pm Tuesday, Sep 20, 4:00 pm – 5:00 pm • Introduction to Modular Development • Modules and Services [CON2949], [CON3707], Tuesday, Sep 20, 11:00 am – 12:00 pm Monday, Sep 19, 2:30 pm – 3:30 pm Thursday, Sep 22, 2:30 pm – 3:30 pm Wednesday, Sep 21, 3:00 pm – 4:00 pm • Project Jigsaw Hack Session [TUT4210], • Advanced Modular Development Wednesday, Sep 21, 8:30 am – 10:30 am [CON3711], Monday, Sep 19, 5:30 pm – 6:30 pm Wednesday, Sep 21, 4:30 pm – 5:30 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 9 Outline • Stewardship and platform evolution • Tooling improvements • Language changes • Library updates • Q & A

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10 Outline • Stewardship and platform evolution • Tooling improvements • Language changes Cumulative Bugs fixes by build in JDK 8 and 9 18000 JDK 8 cumulative JDK 9 • Library updates 16000 JDK 9 cumulative b134 14000 • Q & A Difference (9-8) 12000 JDK 8 10000 GA 8000

6000

4000

2000

0 0 20 40 60 80 100 120 140

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10 Outline • Stewardship and platform evolution • Tooling improvements • Language changes Many feature cross these boundaries • Library updates • Q & A

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10 Stewardship

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11 Background: JDK General Evolution Policy From the OpenJDK Developers’ Guide

“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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12 Release Compatibility Regions

Binary

Behavioral

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13 Release Compatibility Regions

Binary Note: Figure not drawn to scale.

Behavioral Security Update Releases (CPU), 8u75, 8u81, 8u85, …

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13 Release Compatibility Regions Feature Update Releases (PSU), 8u20, 8u40, …

Binary Note: Figure not drawn to scale.

Behavioral Security Update Releases (CPU), 8u75, 8u81, 8u85, …

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13 Platform Release Compatibility Region

Binary

Behavioral

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14 Platform Release Compatibility Region Platform Release, JDK 8 GA, JDK 9 GA

Binary Note: Figure not drawn to scale.

Behavioral

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14 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 (same set of methods) • But a change in behavioral compatibility change; people can and do implicitly 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.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15 Check the release notes and compatibility guides • Use source, binary, behavioral categorization • Compatibility guides distinguish between • Java SE incompatibilities • JDK incompatibilities • JDK 8 Compatibility Guide discusses changing the order of methods returned by Class.getMethods() • (JDK 9 guide expected later in the release) • See also: The Science and Art of Backward Compatibility [CON5773], Ian Robertson, Tuesday, Sep 20, 12:30 pm – 1:30 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 16 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17 Outline • Stewardship and platform evolution • Tooling improvements • Language changes • Library updates • Q & A

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 18 jshell

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19 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 • What about Java?

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 20 jshell – new command in $JDK/bin in JDK 9 OpenJDK Project Kulla/JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21 jshell – new command in $JDK/bin in JDK 9 OpenJDK Project Kulla/JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)

• Teaser Demo • Less ceremony for students learning Java • Less formal way for experienced developers to • Explore using a new API • Experiment with new language features • Leverages many existing JDK technologies • For more information see: JShell: An Interactive Shell for the Java Platform [CON7643], Robert Field, Wednesday, Sep 21, 10:00 am – 11:00 am

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21 JavaDoc.Next http://openjdk.java.net/projects/javadoc-next/

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 22 HTML 5 JEP 224: HTML5 Javadoc

• 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) HTML 5 logo from www.w3.org/html/logo/index.html from 5 logo HTML

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23 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.*'

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 25 Simplified API JEP 221: Simplified Doclet API

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 javax.lang.model API for language model • Use DocTree API (com.sun.source.doctree) • Simpler and more compact

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 26 javadoc search JEP 225: 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 27 Getting from one JDK release to another Multi-release jar files and javac --release

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 28 Cross-compiling with the --release flag

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 29 Cross-compiling to older releases 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 30 Policy on older releases: 1 + 3 back JEP 182: Policy for Retiring javac -source and -target Options

• 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, supported -source/-target values: 10, 9, 8, 7 (deprecated)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 31 Why the bootclasspath needs to be set

// JDK N public class Library { public void foo(double d) {…} }

// JDK N+1 public class Library { public void foo(double d) {…} public void foo(int i) {…} }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32 Why the bootclasspath needs to be set

// JDK N public class Client { public class Library { public static void main(String… args) { public void foo(double d) {…} (new Library()).foo(1234); } } } // JDK N+1 public class Library { public void foo(double d) {…} public void foo(int i) {…} }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32 Why the bootclasspath needs to be set

// JDK N public class Client { public class Library { public static void main(String… args) { public void foo(double d) {…} (new Library()).foo(1234); } } } // JDK N+1 public class Library { If Client is compiled against JDK N+1 but public void foo(double d) {…} run against JDK N: public void foo(int i) {…} }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32 Why the bootclasspath needs to be set

// JDK N public class Client { public class Library { public static void main(String… args) { public void foo(double d) {…} (new Library()).foo(1234); } } } // JDK N+1 public class Library { If Client is compiled against JDK N+1 but public void foo(double d) {…} run against JDK N: public void foo(int i) {…} } Exception in thread "main" java.lang.NoSuchMethodError: Library.foo(I)V at Client.main(Client.java:3)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32 An explicit warning as of JDK 7 https://blogs.oracle.com/darcy/entry/bootclasspath_older_source • 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 33 An explicit warning as of JDK 7 https://blogs.oracle.com/darcy/entry/bootclasspath_older_source • 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…

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 33 JDK 9’s do-what-I-want approach: --release N JEP 247: Compile for Older Platform Versions

• javac --release N … is semantically equivalent to javac -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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 34 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 • Speed improvements

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 35 Multi-release jar files JEP 238

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 36 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!)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 37 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. • Created using additional arguments to the jar command • java.util.jar.JarFile and consumers of jar files (java, javac, …) updated to be multi-release aware

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 38 Outline • Stewardship and platform evolution • Tooling improvements • Language changes • Library updates • Q & A

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 39 Milling Project Coin in JDK 9

JEP 213

Photo copyright 2011 Joseph D. Darcy. All rights reserved. All rights Darcy. 2011 JosephD. copyright Photo

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 40 Project Coin features in JDK 7 Standardized under JSR 334 • Binary literals and underscores in literals • Strings in switch • Diamond • Multi-catch and more precise rethrow • try-with-resources • Varargs warnings

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 41 Project Coin features in JDK 7 Standardized under JSR 334 • Binary literals and underscores in literals • Strings in switch • Diamond • Multi-catch and more precise rethrow • try-with-resources • Varargs warnings

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 41 A few small 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 all type arguments of the inferred types are denotable. • Complete the removal, begun in Java SE 8, of underscore from the set of legal identifier names. Project Lambda amendments • Source-level private interface methods.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 42 @SafeVarargs on private instance methods

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 43 Example from JDK 5.0 and 6 See JLSv3 §4.12.2.1 – Heap Pollution

List> monthsInTwoLanguages = Arrays.asList(Arrays.asList("January", "February"), Arrays.asList("Gennaio", "Febbraio"));

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 44 Example from JDK 5.0 and 6 See JLSv3 §4.12.2.1 – Heap Pollution

List> monthsInTwoLanguages = Arrays.asList(Arrays.asList("January", "February"), Arrays.asList("Gennaio", "Febbraio")); warning: [unchecked] unchecked generic array creation for varargs parameter of type List[] Arrays.asList(Arrays.asList("January", ^

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 44 Example from JDK 5.0 and 6 See JLSv3 §4.12.2.1 – Heap Pollution

List> monthsInTwoLanguages = Arrays.asList(Arrays.asList("January", "February"), Arrays.asList("Gennaio", "Febbraio")); warning: [unchecked] unchecked generic array creation for varargs parameter of type List[] Arrays.asList(Arrays.asList("January", ^ But nothing bad actually happens in this case, so the error is uninformative.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 44 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: • List Arrays.asList(T... a) • boolean Collections.addAll(Collection c, T... elements) • > EnumSet EnumSet.of(E first, E... rest) • void javax.swing.SwingWorker.publish(V... chunks) • Removes warnings from method call sites

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 45 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 JDK 7)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 46 Language Specification updates

• JLS §9.6.4.7. @SafeVarargs It is a compile-time error if a variable arity method declaration that is neither static nor final is annotated with the annotation @SafeVarargs.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 47 Language Specification updates

• JLS §9.6.4.7. @SafeVarargs It is a compile-time error if a variable arity method declaration that is neither static nor final nor private is annotated with the annotation @SafeVarargs.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 47 Effectively final variables & try-with-resources

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 48 Refresher: try-with-resources You type this: try (Resource r = aa()) { bb(r); } catch (Exception e) { cc(); } finally { dd(); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Refresher: try-with-resources You type this: Compiler generates (approximately) this: try (Resource r = aa()) { try { bb(r); Resource r = null; } catch (Exception e) { try { cc(); r = aa(); } finally { ⇒ bb(r); dd(); } finally { } if (r != null) r.close(); } } catch (Exception e) { cc(); } finally { dd(); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Refresher: try-with-resources You type this: Compiler generates (approximately) this: try (Resource r = aa()) { try { bb(r); Resource r = null; } catch (Exception e) { try { cc(); r = aa(); bb(r); } finally { ⇒ It’s actually more complicated dd(); } finally { because of the way exceptions } if (r != null) from close() are handled. r.close(); } } catch (Exception e) { cc(); } finally { dd(); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Full disclosure: try-with-resources actual desugaring try ResourceSpecification Block

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Full disclosure: try-with-resources actual desugaring { try ResourceSpecification final VariableModifiers_minus_final R #resource = Expression; Block Throwable #primaryException = null;

try ResourceSpecificationtail Block 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(); } } } }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 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 object try (r) { r = new Resource2(); // Second resource object } // Which object(s) should have a close method called?

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 51 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.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 52 Example Instead of final Resource r = new Resource(); try (Resource r2 = r) { … }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 53 Example Instead of final Resource r = new Resource(); try (Resource r2 = r) { … } can just use final Resource r = new Resource(); try (r) { … // Cannot mutate r }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 53 Grammar of the specification change, JLS §14.20.3 Resource: {VariableModifier} UnannType VariableDeclaratorId = Expression

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 54 Grammar of the specification change, JLS §14.20.3 Resource: {VariableModifier} UnannType VariableDeclaratorId = Expression VariableAccess

VariableAccess: ExpressionName FieldAccess

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 54 Core of the semantics of the specification change An operand to try-with-resources statement may be a VariableAccess expression, which is an expression name (6.5.6) or a field access expression (15.11). The name or expression must denote a final or effectively final variable of type AutoCloseable which is definitely assigned before the try-with-resources statement; otherwise, a compile-time error occurs.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 55 Core of the semantics of the specification change An operand to try-with-resources statement may be a VariableAccess expression, which is an expression name (6.5.6) or a field access expression (15.11). The name or expression must denote a final or effectively final variable of type AutoCloseable which is definitely assigned before the try-with-resources statement; otherwise, a compile-time error occurs.

(Besides a direct construct like a local variable or method parameter, a resource to be managed could be a final field in an object or a final static field of a nested class, including a construct like (new Foo()).finalResourceField).

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 55 Diamond with anonymous classes, take two

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 56 Diamond and anonymous classes, review

public class Box { Object o; private T value;

List arg = ...; public Box(T value) { this.value = value; o = new Box<>(arg); }

T getValue() { return value; } }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Diamond and anonymous classes, review

public class Box { Object o; private T value;

List arg = ...; public Box(T value) { this.value = value; o = new Box<>(arg); }

T getValue() { The compiler needs to infer the type to use for Box. return value; The language is still statically typed even though it } is not always explicitly typed. }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Inside the compiler…

Object o; List arg = ...; o = new Box< >(arg);

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Inside the compiler…

Object o; List arg = ...; o = new Box >(arg);

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Inside the compiler…

Object o; List arg = ...; o = new Box >(arg);

Capture conversion; results in a non-denotable type (For details see JLS §5.1.10)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. A Box can be subclassed, including anonymously

Object o; List arg = ...; o = new Box >(arg){…};

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. A Box can be subclassed, including anonymously

Object o; List arg = ...; o = new Box >(arg){…};

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Class file expressed as lower-level source code

Object o; List arg = ...; o = new Box$1(arg);

class Box$1 extends Box >{…}

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Class file expressed as lower-level source code Anonymous classes Object o; translate into a new class file with a full set List arg = ...; of attributes. o = new Box$1(arg);

class Box$1 extends Box >{…}

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Class file expressed as lower-level source code Anonymous classes Object o; translate into a new class file with a full set List arg = ...; of attributes. o = new Box$1(arg);

class Box$1 extends Box >{…} Type info needs to be stored in a Signature attribute (JVMS §4.7.9)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Language feature interactions over time

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Language feature interactions over time

Inner classes, JDK 1.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Language feature interactions over time

Generics, JDK 5.0

Inner classes, JDK 1.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Language feature interactions over time Diamond, JDK 7

Generics, JDK 5.0

Inner classes, JDK 1.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Language feature interactions over time Diamond, JDK 7 “Today’s problems come from yesterday’s solutions.” –Brian Goetz via Peter Senge via …

Generics, JDK 5.0

JDK 7 Result: Inner classes, JDK 1.1 Cannot use diamond with anonymous classes in any circumstances.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. A forward-looking statement from the JSR 334 Expert Group JSR 334 Proposed Final Draft, June 2011 “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-denotable types. Non-denotable types can occur as the result of the inference used by diamond. Therefore, using diamond with anonymous inner classes is not supported 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.”

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Java SE 9 allows use of diamond when creating an anonymous inner class as long as the inferred type is denotable. (JDK-8073593)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 63 Partial specification updates: JLS §15.9.3 Choosing the Constructor and its Arguments It is a compile-time error if the superclass or superinterface type of the anonymous class, T, or any subexpression of T, has one of the following forms: • A type variable (4.4) that was not declared as a type parameter (such as a type variable produced by capture conversion (5.1.10)) • An intersection type (4.9) • A class or interface type, where the class or interface declaration is not accessible from the class or interface in which the expression appears. The term “subexpression” includes type arguments of parameterized types (4.5), bounds of wildcards (4.5.1), and element types of array types (10.1). It excludes bounds of type variables.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 64 Partial specification updates: JLS §15.9.5 Anonymous Class Declarations The superclass or superinterface type is given by the class instance creation expression (15.9.1); if this type is generic and its type arguments are elided using '<>', the type arguments are inferred while choosing a constructor (15.9.3).

If the class instance creation expression elides the supertype's type arguments using '<>', then for all non-private methods declared in the class body, it is as if the method declaration is annotated with @Override (9.6.4.4).

[Note:] When the diamond form is used, the inferred type arguments may not be as anticipated by the programmer. Consequently, the supertype of the anonymous class may not be as anticipated, and methods declared in the anonymous class may not override supertype methods as intended. Treating such methods as if annotated with @Override (if they are not actually annotated with @Override) helps avoid silently incorrect programs.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 65 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 66 An underscore is no longer an identifier name JDK-8061549: Disallow ‘—‘ as a one-character identifier

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 67 Starting in Java SE 8 Discussed in http://mail.openjdk.java.net/pipermail/lambda-dev/2013-July/010661.html • 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 68 Future possibilities Syntactic name reclamation • Partial diamond: new Foo(); • Partial witnesses: foo.bar() • “Don’t care” parameter names, suppress “var not used” warnings • …

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 69 private interface methods

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 70 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.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 71 Now in Java SE 9... JDK-8071453: Allow interface methods to be private • 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 default methods

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 72 Deprecation and imports JEP 211: Elide Deprecation Warnings on Import Statements

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 73 Background: warnings, warnings, everywhere

12000 default

static 10000 cast serial

unchecke 8000 raw

deprecat 6000

4000

2000

0

b97 b01 b05 b09 b13 b17 b21 b25 b29 b33 b37 b41 b45 b49 b53 b57 b61 b65 b69 b73 b77 b81 b85 b89 b93 b01 b05

------

b109 b121 b101 b105 b113 b117 b125 b129

------

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9

8 8 8 8 8 8 8 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 74 Background: warnings, warnings, everywhere

12000 A productive default summer intern static Lint warnings cast 10000 Warnings “fix-it” day serial Clean up day unchecke 8000 raw

deprecat 6000

4000

2000

0

b97 b01 b05 b09 b13 b17 b21 b25 b29 b33 b37 b41 b45 b49 b53 b57 b61 b65 b69 b73 b77 b81 b85 b89 b93 b01 b05

------

b109 b121 b101 b105 b113 b117 b125 b129

------

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9

8 8 8 8 8 8 8 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 74 Background: warnings, warnings, everywhere Lint warnings enabled in build 12000 A productive default summer intern static Lint warnings cast 10000 Warnings “fix-it” day serial Clean up day unchecke 8000 raw

deprecat 6000

4000

2000

0

b97 b01 b05 b09 b13 b17 b21 b25 b29 b33 b37 b41 b45 b49 b53 b57 b61 b65 b69 b73 b77 b81 b85 b89 b93 b01 b05

------

b109 b121 b101 b105 b113 b117 b125 b129

------

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9

8 8 8 8 8 8 8 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 74 Number of javac lint warnings in JDK 9 jdk repo today

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 75 Number of javac lint warnings in JDK 9 jdk repo today

Covers all of the following: • Open code • Closed code

• Platform-specific code

• Generated code • -Xlint:all –Werror in the build

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 75 Number of javac lint warnings in JDK 9 jdk repo today

Covers all of the following: Warnings-free modules include: • Open code • java.base: packages • Closed code java.lang, java.util, java.math, …. • Platform-specific code • java.desktop: packages • Generated code java.awt, javax.swing, … • -Xlint:all –Werror in • java.compiler: packages the build javax.lang.model, …

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 75 Number of javac lint warnings in JDK 9 jdk repo today

Covers all of the following: Warnings-free modules include:† • Open code • java.base: packages • Closed code java.lang, java.util, java.math, …. • Platform-specific code • java.desktop: packages • Generated code java.awt, javax.swing, … • -Xlint:all –Werror in • java.compiler: packages the build javax.lang.model, … †corba, jaxp, jax-ws, not included

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 75 Technical dividends of going warnings free javac as the first-line static analysis tool • Did you declare a serialVersionUID in your exception type? (All exceptions are serializable; thanks RMI!) • Did you override equals and hashCode correctly? (Nuanced and accurate check.) • Is that fallthrough in a switch intentional? (Possible security issue; c.f. “goto fail; goto fail;”) • Is it really acceptable to have a new use of that deprecated item? • “Advice on removing javac lint warnings” https://blogs.oracle.com/darcy/entry/warnings_removal_advice

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Oracle Confidential 76

Deprecation warnings • 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")

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 77 A wrinkle in Java SE 5.0 through 8 import p.DepLib; // DepLib.java package p; public class Client2 { @Deprecated public static void public class DepLib { main(String… args) { public DepLib() {} DepLib dl = new DepLib(); public void foo() {return;} dl.foo(); } }

}

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 78 A wrinkle in Java SE 5.0 through 8 import p.DepLib; // DepLib.java package p; public class Client2 { @Deprecated public static void public class DepLib { main(String… args) { public DepLib() {} DepLib dl = new DepLib(); public void foo() {return;} dl.foo(); } }

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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 78 A wrinkle in Java SE 5.0 through 8 import p.DepLib; // DepLib.java package p; public class Client2 { @Deprecated public static void public class DepLib { main(String… args) { public DepLib() {} DepLib dl = new DepLib(); public void foo() {return;} dl.foo(); } }

}

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 79 A wrinkle in Java SE 5.0 through 8 import p.DepLib; // DepLib.java @SuppressWarnings("deprecation") package p; public class Client2 { @Deprecated public static void public class DepLib { main(String… args) { public DepLib() {} DepLib dl = new DepLib(); public void foo() {return;} dl.foo(); } }

}

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 79 A wrinkle in Java SE 5.0 through 8 import p.DepLib; // DepLib.java @SuppressWarnings("deprecation") package p; public class Client2 { @Deprecated public static void public class DepLib { main(String… args) { public DepLib() {} DepLib dl = new DepLib(); public void foo() {return;} dl.foo(); } }

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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 79 Deprecation warning in detail With javac -Xlint:deprecation … Client2.java:1: warning: [deprecation] DepLib in p has been deprecated import 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.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 80 Specification update: JLS §9.6.3.6 @Deprecated A Java compiler must produce a deprecation warning when a type, method, field, or constructor whose declaration is annotated with the annotation @Deprecated is 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.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 81 Specification update: JLS §9.6.3.6 @Deprecated A Java compiler must produce a deprecation warning when a type, method, field, or constructor whose declaration is annotated with the annotation @Deprecated is 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.; or • The use is within an import statement that imports the type or member whose declaration is annotated with @Deprecated.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 81 Result: now tractable to clear a code base of deprecation warnings.

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

More on deprecation: API Deprecation isn’t necessarily API depredation

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 83 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? • …

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 84 More informative @Deprecated annotation in 9 JEP 277: Enhanced Deprecation • Clarified semantics and new information in the @Deprecated annotation: • boolean forRemoval() (defaults to false) • String since() (defaults to "") • example: @Deprecated(since="9", 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

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

Lots more to say about deprecation Get the full patient history and prognosis from Stuart Marks a.k.a. Dr. Deprecator (@DrDeprecator) at Enhanced Deprecation in Java 9 [CON3297] Wednesday, Sep 21, 1:00 pm – 2:00 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 86 Outline • Stewardship and platform evolution • Tooling improvements • Language changes • Library updates • Summary and Q & A

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 87 New Version-String Scheme JEP 223 • 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 • Old java 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) • New java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+135) Java HotSpot(TM) 64-Bit Server VM (build 9-ea+135, mixed mode)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 88 Process API Updates JEP 102 • On java.lang.Process new methods to get the PID, direct children, and all descendents • New java.lang.ProcessHandle interface for better control

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 89 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 • Compilers use this facility; dynamically linked at runtime, optimized by JVM

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 90 Tiered attribution Re-engineering type inference in javac; JEP 215

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 91 class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // javac uses type inference for the <> public static void main(String argv[]) { C c1 = new C<>(); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 92 But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.353s public static void main(String argv[]) { C c2 = new C<>( new C<>()); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.364s public static void main(String argv[]) { C c3 = new C<>( new C<>( new C<>())); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.436s public static void main(String argv[]) { C c4 = new C<>( new C<>( new C<>( new C<>()))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.510s public static void main(String argv[]) { C c5 = new C<>( new C<>( new C<>( new C<>( new C<>())))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.645s public static void main(String argv[]) { C c6 = new C<>( new C<>( new C<>( new C<>( new C<>( new C<>()))))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m0.899s public static void main(String argv[]) { C c7 = new C<>( new C<>( new C<>( new C<>( new C<>( new C<>( new C<>())))))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 0m1.448s public static void main(String argv[]) { C c8 = new C<>( new C<>( new C<>( new C<>( new C<>( new C<>( new C<>( new C<>()))))))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. But once we nest it... class C { U foo; C() {} C(C o) { foo = o.foo; } C(U foo) { this.foo = foo;} } // compilation time: 25m20.590s public static void main(String argv[]) { C c16 = new C<>( new C<>( new C<>( new C<>( ... new C<>( new C<>( new C<>()))))))))))))))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. Also for lambdas... class Klass { static class A0 { } static class A1 { } static class A2 { } Z m(A0 t, Callable ct) { return null; } // compilation time: 0m49.278s Z m(A1 t, void foo() { Callable ct) { return null; } m(null, () -> Z m(A2 t, m(null, () -> Callable ct) { return null; } m(null, () -> Z m(Object o, m(null, () -> Callable co) { return null; } } m(null, () -> m(null, () -> m(null, () -> m(null, () -> m(null, (Callable)null))))))))); }

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. JDK 8 Compiler performance, linear time scale Compilation time

1600 “I’m not slacking off. javac 8 My code’s compiling.” 1200

Seconds 800

400

0 2 4 6 8 10 12 14 16 18 20 22 Diamond nesting level

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 102 JDK 8 Compiler performance, log time scale Compilation time

4096

1024 javac 8 256

64 Seconds 16

Note: log scale 4 on y-axis 1 2 4 6 8 10 12 14 16 18 20 22 0.25 Diamond nesting level

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 103 JDK 9 Compiler performance with tiered attribution Compilation time

4096 javac 8 1024 javac 9 256 javac 9 -release 8 64 Seconds 16

Note: log scale 4 on y-axis 1 2 4 6 8 10 12 14 16 18 20 22 0.25 Diamond nesting level

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 104 Tiered Attribution results • More efficient construction of constraints used in type inference • Performance improvement, worst case dramatically improved • Compatibility with existing attribution approach • Opened the door to more optimizations and improvements

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 105 Security libraries and tooling overview

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 106 Security tools and libraries, three general categories • Language and Runtime security controls • APIs and Libraries for integrating security into your applications • JSSE (SSL/TLS) • JCE (crypto) • PKI (Public Key Infrastructure) • … • Tools for managing security (keytool, jarsigner, etc.)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 107 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 108 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 • MD2 or MD5, RSA or DSA with key size < 1024, etc. • System property to change configuration if really needed • New crypto hash SHA-3 (JEP 287: SHA-3 Hash Algorithms) • Better SecureRandom algorithm (JEP 273: DRBG-Based SecureRandom Implementations) • Accelerated crypto operations on x64 and Sparc (JEP 246: Leverage CPU Instructions for GHASH and RSA)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 109 For more security information… • Making the JDK More Secure [CON2699], Sean Mullan, Monday, Sep 19, 11:00 am – 12:00 pm • Bof: OpenJDK Security Group: Discussion and Q&A [BOF2637], Sean Mullan, Bradford Wetmore, & Jeffrey Nisewanger, Tuesday, Sep 20, 7:00 pm – 7:45 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 110 Client libraries and FX

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 111 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 112 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 • TIFF support in imageio, JEP 262 • For more information: • New and Noteworthy in the Java SE 9 Client [CON1469] Philip Race and Jim Graham, Monday, Sep 19, 11:00 am – 12:00 pm • Meet the Oracle JavaFX and JDK Client Team [BOF1463] Kevin Rushforth and Philip Race, Monday, Sep 19, 7:00 pm – 7:45 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 113 Miscellaneous library treats

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 114 Convenience Factory Methods for Collections JEP 269 How many times have you written code like: Set set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set);

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 115 Convenience Factory Methods for Collections JEP 269 How many times have you written code like: Set set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set); or like Set set = Collections.unmodifiableSet(new HashSet<>( Arrays.asList("a", "b", "c")));

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 115 No more!

• Can now write: Set set = Set.of("a", "b", "c"); • New static factory methods named “of” on Set, List, and Map. • Return unmodifiable collections. • Randomized iteration for set and maps. • For more information see Collections Refueled, Stuart Marks, [CON4341] Thu Sep 22 4:00 pm – 5:00 pm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 116 New public static methods in java.util.Objects • T requireNonNullElse(T obj, T defaultObj) • T requireNonNullElseGet(T obj, Supplier supplier) • int checkIndex(int index, int length) • int checkFromToIndex(int fromIndex, int toIndex, int length) • int checkFromIndexSize(int fromIndex, int size, int length)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 117 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

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 118 Summary

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 119 JDK 9 Language, Tooling, and Library features

• Fundamental development changes coming with modularity • Smaller improvements coming in other areas: • Finish long-anticipated polishing of Projects Coin and Lambda • Features to support long-term evolution and multi-release planning • Features span language, tools, library, (and JVM) • Large and small features cross language, tooling, library, (and JVM) areas • Can follow developments in OpenJDK • EA builds of JDK 9 available today for your evaluation

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 120 Q & A Slides: https://blogs.oracle.com/darcy/resource/JavaOne/J1_2016-jdk9-lang-tools-libs.pdf

JDK 9 EA builds: https://jdk9.java.net/ JDK 9 EA builds with latest Jigsaw: https://jdk9.java.net/jigsaw/

Follow-up questions: #JDK9LangToolsLibs

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