Java 9: What's inside

32
> < next previous Java 9: What’s Inside By Dmytrii Shchadei

Transcript of Java 9: What's inside

Page 1: Java 9: What's inside

>< nextprevious

Java 9: What’s InsideBy Dmytrii Shchadei

Page 2: Java 9: What's inside

>< nextprevious

What’s inside?‣ Project Jigsaw

‣ New Language Features

‣ Updates to API

‣ …

Page 3: Java 9: What's inside

>< nextprevious

Project Jigsaw

Page 4: Java 9: What's inside

>< nextprevious

‣ Project Jigsaw

‣ Module System in the Java Language

‣ Apply Module System to JDK

Page 5: Java 9: What's inside

>< nextprevious

JAR Hell

‣ Unexpressed Dependencies

‣ Class Shadowing

‣ Version Conflicts

‣ Complex class loading

Page 6: Java 9: What's inside

>< nextprevious

Java Module Heaven

‣ Explicit Dependencies

‣ Reliable Encapsulation

‣ Versioning 😭

Page 7: Java 9: What's inside

>< nextprevious

Modules in Practise

Page 8: Java 9: What's inside

>< nextprevious

JDK modularization

Page 9: Java 9: What's inside

>< nextprevious

JDK modularization

Compiled class

files for the base

JRE

Page 10: Java 9: What's inside

>< nextprevious

More JDK Changes

‣ Encapsulates most JDK internal API

‣ sun.misc.Unsafe

‣ sun.misc.Base64Encode/Decoder

‣ Remove 6 deprecated APIs (i.e. add/remove

PropertyChangeListener)

‣ Modules shared with Java EE not resolved by default

‣ New version-string format (i.e.

$MAJOR.$MINOR.$SECURITY)

Page 11: Java 9: What's inside

>< nextprevious

New version-string

format‣ Encapsulates most JDK internal API (i.e.

sun.*)

‣ Remove 6 deprecated APIs (i.e. add/remove

PropertyChangeListener)

‣ Modules shared with Java EE not resolved by

default

‣ New version-string format

Page 12: Java 9: What's inside

>< nextprevious

Jlink

‣ –module-path specifies where to find the

modules for the JDK.

‣ –add-modules adds the modules we need

‣ –limit-modules limits to just the modules that

we know our application needs (transitive

deps)

‣ –output is this directory where the run-time

image will be

Remember

Java 8

Compact

Profiles?

Page 13: Java 9: What's inside

>< nextprevious

Migration: Bridging

CodeModule type Origin Exports packages Can read modules

(Named) Platform Modules provided by JDK explicitly

(Named) Application Modules any JAR containing

module-info.class

on the module path

explicitly Platform

Application

Automatic

Automatic Modules any JAR without

module-info.class

on the module path

all Platform

Application

Automatic

Unnamed

Unnamed Module all JARs and classes

on the classpath

all Platform

Automatic

Application

Page 14: Java 9: What's inside

>< nextprevious

Migration: jdeps

Page 15: Java 9: What's inside

>< nextprevious

Multi-Release Jars

Page 16: Java 9: What's inside

>< nextprevious

JShell

Page 17: Java 9: What's inside

>< nextprevious

New Language

Features

Page 18: Java 9: What's inside

>< nextprevious

More concise try-with-resources

Page 19: Java 9: What's inside

>< nextprevious

Private Interface

Methods

‣ Must be implemented

‣ Can not be overridden

‣ Can only be called in a same source file

Page 20: Java 9: What's inside

>< nextprevious

Diamond OperatorWith Anonymous Inner Class

Page 21: Java 9: What's inside

>< nextprevious

Diamond OperatorWith Anonymous Inner Class

Page 22: Java 9: What's inside

>< nextprevious

SafeVarargs on Private

Methods

Page 23: Java 9: What's inside

>< nextprevious

New API

Page 24: Java 9: What's inside

>< nextprevious

Additions To Optional‣ Use Optional::stream to map an Optional to a

Stream.

‣ Use Optional::or to replace an empty Optional

with the result of a call returning another

Optional.

‣ With Optional::ifPresentOrElse you can do

both branches of an isPresent-if.

Page 25: Java 9: What's inside

>< nextprevious

Additions To Objects

‣ requireNonNullElseGet

‣ requireNonNullElse

Page 26: Java 9: What's inside

>< nextprevious

Additions to Process

API‣ Obtaining the PID with getPid()

‣ Obtaining process information ProcessHandle.Info

‣ Enumerating System Processes

ProcessHandle.allProcesses()

‣ Enumerating Child Processes

ProcessHandle.current().children()

‣ Triggering actions on process termination

ProcessHandle's onExit()

‣ Better Use of Hardware

Page 27: Java 9: What's inside

>< nextprevious

Collection Factories

All

immutable!

Page 28: Java 9: What's inside

>< nextprevious

Reactive StreamsJDK 9 Flow API at a Glance

Page 29: Java 9: What's inside

>< nextprevious

Stack-Walking APIWho called me?

Page 30: Java 9: What's inside

>< nextprevious

Stack-Walking APIWho called me?

‣ The forEach Method

‣ Walk the walk

why does it

not just

return the

Stream?

Page 31: Java 9: What's inside

>< nextprevious

Stack-Walking APIWho called me?

Page 32: Java 9: What's inside

>< nextprevious

Free Lunch!

‣ Multiple String Performance Improvements

‣ Better Graphics Performance

‣ Faster Compilation

‣ Better Use of Hardware