What's new in Java 8

38
What’s New in Java 8? John Clingan Oracle Product Manager – Java EE, GlassFish, EclipseLink, Avatar

description

Java SE 8 presentation.

Transcript of What's new in Java 8

Page 1: What's new in Java 8

What’s New in Java 8? John Clingan Oracle Product Manager – Java EE, GlassFish, EclipseLink, Avatar

Page 2: What's new in Java 8

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

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: What's new in Java 8

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

Lambda (JSR 335)

Date/Time API (JSR 310)

Type Annotations (JSR 308)

Compact Profiles

Lambda-Form Representation for Method Handles

Remove the Permanent Generation

Improve Contended Locking

Generalized Target-Type Inference

DocTree API

Parallel Array Sorting Bulk Data Operations

Unicode 6.2

Base64

Prepare for Modularization

Parameter Names

TLS Server Name Indication

Configurable Secure-Random Number Generation

Java SE 8 Nashorn

Enhanced Verification Errors

Fence Intrinsics

Repeating Annotations

HTTP URL Permissions

Limited doPrivileged

http://openjdk.java.net/projects/jdk8/features

Page 4: What's new in Java 8

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

Java SE 8: Enhancing The Core Java Platform

Page 5: What's new in Java 8

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

Java SE 8

! Biggest change in the Java language since Java SE 5 ! Significant enhancements to the class libraries ! The main goal of these changes are …

–  Better developer productivity –  More reliable code –  Better utilization of multi-core / multi-processor systems

!  Code is no longer inherently serial or parallel

Page 6: What's new in Java 8

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

Lambda Expressions

! Almost all machines now are multi-core, multi-processor, or both ! We need to make it simpler to write multi-threaded Java code

–  Java has always had the concept of threads –  Even using the concurrency utilities and fork-join framework this is hard

! Let’s add better library code –  This is good, but sometimes we need to change the language too

! The answer: Lambda expressions and the streams API ! Backwards compatible with existing APIs like Collections.

Why Do We Need Them?

Page 7: What's new in Java 8

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

Lambda & Streams Demos

Page 8: What's new in Java 8

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

Stream Sources

! From collections and arrays –  Collection.stream()

–  Collection.parallelStream() –  Arrays.stream(T array) or Stream.of()

! Static factories –  IntStream.range() –  Files.walk()

! Roll your own –  java.util.Spliterator()

Many Ways To Create

Page 9: What's new in Java 8

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

Stream Sources

! Access to stream elements ! Decomposition (for parallel operations)

–  Fork-join framework

! Stream characteristics –  ORDERED –  DISTINCT –  SORTED –  SIZED –  SUBSIZED –  NONNULL –  IMMUTABLE –  CONCURRENT

Manage Three Aspects

Page 10: What's new in Java 8

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

Optional<T>

! Used in new Java 8 APIs to replace null !  Indicates that reference may, or may not have a value ! Makes developer responsible for checking

Reducing NullPointerException Occurences

Optional<GPSData> maybeGPS = Optional.of(gpsData); maybeGPS = Optional.ofNullable(gpsData);

maybeGPS.ifPresent(GPSData::printPosition);

GPSData gps = maybeGPS.orElse(new GPSData());

maybeGPS.filter(g -> g.lastRead() < 2).ifPresent(GPSData.display());

Page 11: What's new in Java 8

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

java.util.function Package

! Predicate<T> –  Determine if the input of type T matches some criteria

! Consumer<T> –  Accept a single input argumentof type T, and return no result

! Function<T, R> –  Apply a function to the input type T, generating a result of type R

! Plus several more

Page 12: What's new in Java 8

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

Annotations On Java Types

! Annotations can currently only be used on type declarations –  Classes, methods, variable definitions

! Extension for places where types are used –  e.g. parameters

! Permits error detection by pluggable type checkers –  e.g. null pointer errors, race conditions, etc

public void process(@notnull List data) {…}

Page 13: What's new in Java 8

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

Concurrency Updates

! Scalable update variables –  DoubleAccumulator, DoubleAdder, etc –  Multiple variables avoid update contention –  Good for frequent updates, infrequent reads

! ConcurrentHashMap updates –  Improved scanning support, key computation

! ForkJoinPool improvements –  Completion based design for IO bound applications –  Thread that is blocked hands work to thread that is running

Page 14: What's new in Java 8

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

Parallel Array Sorting

! Additional utility methods in java.util.Arrays –  parallelSort (multiple signatures for different primitives)

! Anticipated minimum improvement of 30% over sequential sort –  For dual core system with appropriate sized data set

! Built on top of the fork-join framework –  Uses Doug Lea’s ParallelArray implementation –  Requires working space the same size as the array being sorted

Page 15: What's new in Java 8

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

Date And Time APIs

! A new date, time, and calendar API for the Java SE platform ! Supports standard time concepts

–  Partial, duration, period, intervals –  date, time, instant, and time-zone

! Provides a limited set of calendar systems and be extensible to others ! Uses relevant standards, including ISO-8601, CLDR, and BCP47 ! Based on an explicit time-scale with a connection to UTC

Page 16: What's new in Java 8

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

Base64 Encoding and Decoding

! Currently developers are forced to use non-public APIs –  sun.misc.BASE64Encoder

–  sun.misc.BASE64Decoder

!  Java SE 8 now has a standard way –  java.util.Base64.Encoder

–  java.util.Base64.Decoder –  encode, encodeToString, decode, wrap methods

Page 17: What's new in Java 8

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

Nashorn JavaScript Engine

! Lightweight, high-performance JavaScript engine –  Integrated into JRE

! Use existing javax.script API ! ECMAScript-262 Edition 5.1 language specification compliance ! New command-line tool, jjs to run JavaScript !  Internationalised error messages and documentation

Page 18: What's new in Java 8

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

Native Memory Usage

! No more tuning PermGen –  PermGen – Artificial memory limitation –  Metaspace – Regular native allocation

!  Limited only by process address space !  Can force a limit: -XX:MaxMetaspaceSize=<size>

–  Part of the HotSpot, JRockit convergence

! Class data sharing across processes – Experimental feature –  Available on all platforms, -Xshare:[off|on|auto] –  Reduce footprint and startup sharing JDK classes between processes

No more “java.lang.OutOfMemoryError: PermGen space”

Page 19: What's new in Java 8

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

Multistep Optimization

!  Interpreter " Client Compiler " Server Compiler –  Fast initial compilation –  Keep peak performance –  Enabled by default

!  Improve time to performance –  Startup of large applications –  Performance for short running applications

Tiered Compilation

Page 20: What's new in Java 8

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

Java EE Application Deployment Tiered Compilation

Page 21: What's new in Java 8

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

JSR 292 - InvokeDynamic

! Complete rewrite of the VM support for JSR 292 –  Improved stability, maintainability and performance

! Lambda –  Avoid repeated calculations during capture –  No allocation for non-capturing Lambdas –  On par or faster than inner classes

!  JavaScript Engine – Nashorn –  Incremental inlining of MethodHandle invocations

Major Updates

Page 22: What's new in Java 8

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

JavaScript Engine - Nashorn JSR 292 - InvokeDynamic

JDK 8 updates double performance of a couple of these

Page 23: What's new in Java 8

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

Java Mission Control

Page 24: What's new in Java 8

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

JavaFX 8 New Stylesheet

24

Caspian vs Modena

Page 25: What's new in Java 8

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

JavaFX 8

! Customisable –  Configurable key combinations to exit full screen mode –  Ability to prevent user exiting full screen mode

Improvements To Full Screen Mode

// Set the key combination that the user can use to exit stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);

// Setup the click handler so we can escape from full screen Rectangle r = new Rectangle(0, 0, 250, 250); r.setOnMouseClicked(e -> stage.setFullScreen(false));

// Set full screen again stage.setFullScreen(true);

Page 26: What's new in Java 8

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

JavaFX 8

! New API for printing –  Currently only supported on desktop

! Any node can be printed

Printing Support

PrinterJob job = PrinterJob.createPrinterJob(printer); job.getJobSettings().setPageLayout(pageLayout); job.getJobSettings().setPrintQuality(PrintQuality.HIGH); job.getJobSettings().setPaperSource(PaperSource.MANUAL); job.getJobSettings().setCollation(Collation.COLLATED);

if (job.printPage(someRichText)) job.endJob();

Page 27: What's new in Java 8

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

JavaFX 8

! DatePicker ! TreeTableView

New Controls

Page 28: What's new in Java 8

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

JavaFX 8

! Gestures –  Swipe –  Scroll –  Rotate –  Zoom

! Touch events and touch points

Touch Support

Page 29: What's new in Java 8

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

JavaFX 8

! Predefined shapes –  Box –  Cylinder –  Sphere

! User-defined shapes –  TriangleMesh, MeshView

! PhongMaterial ! Lighting ! Cameras

3D Support

Page 30: What's new in Java 8

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

Compact Profiles Approximate static footprint goals

Compact1 Profile

Compact2 Profile

Compact3 Profile

Full JRE 54Mb

30Mb

16Mb

11Mb [Migration path for CDC, logging and SSL]

[Adds XML, JDBC, RMI]

[Adds mgmt, naming, more security, compiler support]

Page 31: What's new in Java 8

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

Java SE Public Updates Schedule

GA Date Notification of End of Public Updates End of Public Updates

Java SE 1.4.2 Feb 2002 Dec 2006 Oct 2008

Java SE 5 May 2004 Apr 2008 Oct 2009

Java SE 6 Dec 2006 Feb 2011 Feb 2013

Java SE 7 July 2011 Mar 2014 April 2015

Java SE 8 Mar 2014 Mar 2016* TBD

For details see, http://www.oracle.com/technetwork/java/eol-135779.html * Or later. Exact date TBD.

Page 32: What's new in Java 8

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

Books

!  “Java SE 8 for the Really Impatient” (Horstmann)

!  “Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions” (Subramaniam)

!  “Mastering Lambdas: Java Programming in a Multicore World” (Naftalin)

!  “Java 8 in Action: Lambdas, Streams, and functional-style programming” (Urma, Fusco, Mycroft)

!  “Java 8 Lambdas: Pragmatic Functional Programming” (Warburton)

!  “Java in a Nutshell” (Evans, Flanagan)

Page 33: What's new in Java 8

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

Where Next?

Page 34: What's new in Java 8

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

Java 9 And Beyond

! Modularisation of the Java platform –  Project Jigsaw

! Foreign function interface –  Like JNA

! Enhanced volatiles

Java Never Stops

Page 35: What's new in Java 8

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

Page 36: What's new in Java 8

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

Page 37: What's new in Java 8

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

Java SE Lifetime Support Policy

GA Date Premier Support Extended Support

Java SE 1.4.2 Feb 2002 Feb 2010 Feb 2013

Java SE 5 May 2004 May 2011 May 2015

Java SE 6 Dec 2006 Dec 2015 Jun 2018

Java SE 7 July 2011 July 2019 July 2022

Java SE 8 Mar 2014 Mar 2022 Mar 2025

For details see, http://www.oracle.com/support/library/brochure/lifetime-support-middleware.pdf

Page 38: What's new in Java 8

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

Java SE Platform enhanced with enterprise-grade features for monitoring, manageability, and analytics.

# 24x7 support, offered in 27 local languages

# Security updates on older and current releases

# Only source for Java SE 6 updates after Feb 2013

# Monitor, manage, and profile Java desktop applications

# Enterprise JRE features i.e., Java SE usage tracking

Java SE Commercial Products

Java SE Suite

Java SE Platform hardened for mission critical applications having extreme and predictable computing needs.

# Soft real-time deterministic garbage collector for mission critical applications

# Memory leak server for dynamic memory leak detection on mission critical production systems

Java SE Support

Oracle Premier Support for Java SE.

# 24x7 support, offered in 27 local languages

# Security updates on older and current releases

# Only source for Java SE 6 updates after Feb 2013

# Enterprise JRE features i.e., update control

Java SE Advanced Desktop and Java SE Advanced