taste of new in java 9 - zielona góra jugzielona-gora-jug.github.io/files/java_9.pdf · taste of...

32
Taste of new in Java 9 Arkadiusz Sokołowski 2015

Upload: lekiet

Post on 22-Mar-2018

220 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Taste of new inJava 9

Arkadiusz Sokołowski2015

Page 2: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Agenda

● A bit of history

● jshell

● JDK Benchmarks / jmh

● small stuff...

● jigsaw

● what’s beyond 9?

Page 3: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Bit of history1991: Green (Oak)

1994: JDK EAs

Jan 1996: JDK 1.0

Feb 1997: JDK 1.1

Dec 1998: J2SE 1.2

May 2000: J2SE 1.3

Feb 2002: J2SE 1.4

Sep 2004: J2SE 5.0

Dec 2006: Java SE 6

Jul 2011: Java SE 7

Mar 2014: Java SE 8

Sep 2016: Java SE 9 release

Dec 2015: Java SE 9 feature complete

Page 4: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

New versioning scheme

● Current scheme:○ Minor releases containing changes beyond security

fixes are multiples of 20○ Security releases based on the previous minor

release are odd numbers incremented by five, or by six if necessary in order to keep the update number odd

Page 5: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

New versioning scheme

● New scheme:○ MAJOR.MINOR.SECURITY

○ 1.8.0 => 8.0.0

○ 1.8.0_05 => 8.0.1

○ 1.8.0_11 => 8.0.2

○ 1.8.0_20 => 8.1.2

○ 1.8.0_25 => 8.1.3

Page 6: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

jshell

Page 7: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

JDK Benchmark Suite

● based on JMH

● stable, tuned benchmarks

● targeted for continuous performance check

● lot of benchmarks for standard libraries

● comparison with JDK 8

Page 8: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Http/2

HttpResponse response = HttpRequest

.create(new URI("http://www.ocado.com"))

.body(noBody())

.GET().send();

int responseCode = response.responseCode();

String responseBody = response.body(asString());

System.out.println(responseBody);

Page 9: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Http/2

HttpRequest req = HttpRequest

.create(new URI("http://www.ocado.com"))

.body(noBody())

.GET();

CompletableFuture<HttpResponse> asyncResp = req.sendAsync();

Thread.sleep(10);

if (!asyncResp.isDone()) {

asyncResp.cancel(true);

System.err.println("timeout");

return;

}

HttpResponse response = asyncResp.get();

Page 10: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

JVM logging-Xlog[:option]

option := [<what>][:[<output>][:

[<decorators>][:<output-options>]]]

'help'

'disable'

what := <selector>[,...]

selector := <tag-set>[*][=<level>]

tag-set := <tag>[+...]

'all'

tag := name of tag

level := trace

debug

info

warning

error

output := 'stderr'

'stdout'

[file=]<filename>

decorators := <decorator>[,...]

'none'

decorator := time

uptime

timemillis

uptimemillis

timenanos

uptimenanos

pid

tid

level

tags

output-options := <output_option>[,...]

output-option := filecount=<file count>

filesize=<file size in kb>

parameter=value

Page 11: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Coin project - language adjustments

● allow @SaveVargs on private instance methods

● allow effectively-final variables in try-with-resources

● more type inference with generics

● underscore will be no more a valid identifier

● private methods in interfaces

Page 12: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Hotspot / JDK diagnostics

● print_class_summary

● print_codegen_list

● print_utf8pool

● dump_codelist

● print_codeblocks

● set_vmflags

Page 13: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Other...● improved contented locking

● variable handles (Unsafe!)

● sjavac

● fixed imports processing by javac

● Security (Datagram / Application transport layer)

● HTML5 javadoc

● Unicode 7.0

Page 14: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Other...● String internal representation altered

● Java-Level JVM Compiler Interface

● Parser API for Nashorn

● Support for AArch64 (ARMv8) architecture

● Compile for Older Platform Versions

● G1 will be default garbage collector

● Store Interned Strings in CDS archives

Page 15: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - modules for Java● Motivation:

○ JAR/classpath hell reduction

○ unexpressed/transitive dependencies

○ manual dependencies management

○ hide some (private) packages; com.sun.misc.*

○ system instead of manual security

○ JRE size reduction

Page 16: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Copyright © Oracle 2015

Page 17: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - modules in Java8

Copyright © Oracle 2015

Page 18: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - piece of action...

Page 19: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - one more example

module com.foo.app {

requires com.foo.bar;

requires java.sql;

}

module java.sql {

requires java.logging;

requires java.xml;

exports java.sql;

exports javax.sql;

exports javax.transaction.xa;

}

Page 20: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - one more example

Copyright © Oracle 2015

Page 21: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - implied readability

String url = ...;

Properties props = ...;

Driver d = DriverManager.getDriver(url);

Connection c = d.connect(url, props);

d.getParentLogger().info("Connection acquired");

Page 22: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - implied readabilitymodule java.sql {

requires public java.logging;

requires public java.xml;

exports java.sql;

exports javax.sql;

exports javax.transaction.xa;

}

Page 23: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - implied readability

Copyright © Oracle 2015

Page 24: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - services

module com.mysql.jdbc {

requires java.sql;

requires org.slf4j;

exports com.mysql.jdbc;

}

Page 25: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - services

module java.sql {

requires public java.logging;

requires public java.xml;

exports java.sql;

exports javax.sql;

exports javax.transaction.xa;

uses java.sql.Driver;

}

Page 26: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - services

module com.mysql.jdbc {

requires java.sql;

requires org.slf4j;

exports com.mysql.jdbc;

provides java.sql.Driver with com.mysql.jdbc.Driver;

}

Page 27: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - services

Copyright © Oracle 2015

Page 28: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - qualified exportsmodule java.base {

...

exports sun.reflect to

java.corba,

java.logging,

java.sql,

java.sql.rowset,

jdk.scripting.nashorn;

}

Page 29: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Jigsaw - qualified exports

Copyright © Oracle 2015

Page 30: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Java 10: value classes

value class Point { int x; int y; Point(int x, int y) { this.x = x; this.y = y; } }

Page 31: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Java 10: generics

● Reified Generics

● Generics with valuesList<int> intList = new ArrayList<>();

…int val = intList.get(0);

class List$Point { Point get(Point index); }

Page 32: Taste of new in Java 9 - Zielona Góra JUGzielona-gora-jug.github.io/files/Java_9.pdf · Taste of new in Java 9 Arkadiusz Sokołowski 2015. ... manual dependencies management hide

Thank you!...questions?