Java SE 8 - Java Technologie Update Update

Werbung
Java SE 8 - Java Technologie
Update
Wolfgang Weigend
Sen. Leitender Systemberater
Java Technologie und Architektur
1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Disclaimer
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.
2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JDK 8
Innovation
Java for Everyone
Client
• Lambda JSR 335
• Profiles for constrained devices
• Deployment enhancements
• Language Interoperability
• JSR 310 – Date & Time API‘s
• JavaFX 8
• Nashorn
• Non-Gregorian calendars
• Public UI Control API
• Unicode 6.1
• Java SE Embedded support
• ResourceBundle
• Enhanced HTML5 support
• BCP47 locale matching
• 3D shapes and attributes
• Globalization & Accessibility
• Printing
Tools
Security
• Compiler control & logging
• Limited doPriviledge
Core Libraries
• Parallel operations for core collections API‘s
• Improvements in functionality
• Improved type inference
General Goodness
• JVM enhancements
• No PermGen limitations
• Performance Improvements
3
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
• JSR 308 – Annotations on Java Type • NSA Suite B algorithm support
• Native app bundling
• SNI Server Side support
• App Store Bundling tools
• DSA update to FIPS186-3
• AEAD JSSE CipherSuites
Lambda Ausdrücke JSR-335
• Functional Interfaces: “An interface with one method”
• Gehört zum Sprachumfang von Java SE 8
− Final Release Specification
file:///C:/Java/jsr335-final/index.html
− http://www.oracle.com/technetwork/java/javase/downloads/index.html
• Lambda Expressions (closures)
/* (int
x,
int
y)
{return
x+y; } */
• Parameter Liste → -> Operator → Expression od. Statements
(String x) -> {return !x.isEmpty();}
• Was hergeleitet werden kann, kann auch weggelassen werden
x -> !x.isEmpty()
4
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Extension Methods
Bringt Mehrfachvererbung und Funktionalität für Java
• Provide a mechanism to add new methods to existing interfaces
– Without breaking backwards compatibility
– Gives Java multiple inheritance of behaviour, as well as types
• but not state!
public interface Set<T> extends Collection<T> {
public int size();
...
// The rest of the existing Set methods
public T reduce(Reducer<T> r)
default Collections.<T>setReducer;
}
5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Erweiterung der Core Libraries mit Lambdas
• Modernize general library API’s
• Improve performance
– Gains from use of invokedynamic to implement Lambdas
• Demonstrate best practices for extension methods
6
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
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
7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Bulk Data Operations für Collections
Filter, Map, Reduce for Java
• Add functionality to the Java Collections Framework for bulk
operations upon data
• This is commonly referenced as “filter/map/reduce for Java”
• The bulk data operations include both serial (on the calling thread)
and parallel (using many threads) versions of the operations
– Serial and parallel implementations
• Operations upon data are generally expressed as lambda functions
• Parallel implementation builds on Fork-Join framework
8
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
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
9
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Lambda Ausdrücke – Parallelisiert
State of the Lambda Libraries Edition
List<Student> students = new ArrayList<>(...);
...
double highestScore =
students.parallelStream()
.filter(s -> s.getGradYear() == 2013)
.map(s -> s.getScore())
.reduce(0.0, Integer::max);
−
More readable
−
Better abstraction
−
No reliance on mutable state
−
Runs in parallel
−
Works on any data structure that knows how to subdivide itself
Concurrent Bulk Data Operations in Java collections API’s (JEP 107)
− filter/map/reduce
10
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Date and Time API – JSR 310
• JEP 150 by Stephen Colebourne
• 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
11
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Date and Time API – JSR 310
New Classes
• The main difference you will notice is that there are several different classes to represent time,
date, time period, and timezone specific data. Also there are transformers for dates and times
• For dates and times without a timezone, use the following:
– LocalDate – Day, month, year
– LocalTime – Time of day only
– LocalDateTime – Both date and time
• For timezone specific times you use ZonedDateTime
• Previous to Java 8, to calculate the time eight hours in the future you would need to write
something like the following:
– 1 Calendar cal = Calendar.getInstance();
– 2 cal.add(Calendar.HOUR, 8);
– 3 cal.getTime();
// actually returns a Date
• With Java 8, you can more simply write the following:
– 1 LocalTime now = LocalTime.now();
– 2 LocalTime later = now.plus(8, HOURS);
12
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quelle: https://leanpub.com/whatsnewinjava8/read#leanpub-auto-new-date-and-time-api
Date and Time API – JSR 310
Creation
• Creating new date and time objects is much easier and less error-prone in Java 8. Every class
has static factory methods that are easy to understand
• For example, creating a new LocalDate for 17th of July 2014 is as simple as:
– 1 date = LocalDate.of(2014, 7, 17);
• For more type-safety, you can use the new Month enum:
– 1 date = LocalDate.of(2014, Month.JULY, 17);
• You can also easily create a LocalDateTime from an instance of LocalDate:
– 1 LocalTime time = LocalTime.of(23, 59, 0);
– 2 LocalDateTime datetime = date.atTime(time);
• You could also use any of the following methods (on LocalDate):
– atTime(int hour, int minute)
– atTime(int hour, int minute, int second)
– atTime(int hour, int minute, int second, int nanoOfSecond)
• Every class also has the now()method, which corresponds the moment (or date) it is called
13
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quelle: https://leanpub.com/whatsnewinjava8/read#leanpub-auto-new-date-and-time-api
Date and Time API – JSR 310
java.time API Packages
Package
Description
java.time
The main API for dates, times, instants, and durations
java.time.chrono
Generic API for calendar systems other than the default ISO
java.time.format
Provides classes to print and parse dates and times
java.time.temporal
Access to date and time using fields and units, and date
time adjusters
java.time.zone
Support for time-zones and their rules
14
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quelle: https://leanpub.com/whatsnewinjava8/read#leanpub-auto-new-date-and-time-api
Date and Time API – JSR 310
Basisklassen im Package java.time
Klasse
Beschreibung
Clock
A clock providing access to the current instant, date and time using a time-zone.
Duration
A time-based amount of time, such as '34.5 seconds'.
Instant
An instantaneous point on the time-line.
LocalDate
A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.
LocalDateTime
A date-time without a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30.
LocalTime
A time without time-zone in the ISO-8601 calendar system, such as 10:15:30.
MonthDay
A month-day in the ISO-8601 calendar system, such as --12-03.
OffsetDateTime
A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00.
OffsetTime
A time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.
Period
A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.
Year
A year in the ISO-8601 calendar system, such as 2007.
YearMonth
A year-month in the ISO-8601 calendar system, such as 2007-12.
ZonedDateTime
A date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00 Europe/Paris.
ZoneId
A time-zone ID, such as Europe/Paris.
ZoneOffset
A time-zone offset from Greenwich/UTC, such as +02:00.
15
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quelle: https://leanpub.com/whatsnewinjava8/read#leanpub-auto-new-date-and-time-api
Larger Security Policy Areas
SA / CPU RSS Feeds
Security Blog
eBlasts
Java.com Security
Communications
Deployment
Lifecycle
Architecture Review
Peer Review
Security Testing
Post Mortems
Security
Remediation
16
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
CPU
Security Alerts
Java Critical Patch Updates
Rules for Java CPU’s
− Main release for security vulnerabilities
− Covers all JDK families (8, 7, 6, 5.0)
− CPU release triggers Auto-update
− Dates published 12 months in advance
− Security Alerts are released as necessary
− Based off the previous (non-CPU) release
− Released simultaneously on java.com and OTN
17
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JDK 8u20 - Security Baselines
JRE Family Version
JRE Security Baseline
(Full Version String)
8
1.8.0_11
7
1.7.0_65
6
1.6.0_81
5.0
1.5.0_71
Java Security Resource Center
What’s new
•
•
•
•
•
•
•
•
New Secure Coding Guidelines
Java 8 Security Enhancements
JavaOne 2014 Java Security Track
Manage multiple versions on client systems
Exception Site List and Deployment Rule Set
RIA Checklist
OpenJDK Security Group Information
Security for Developers
• http://www.oracle.com/technetwork/java/javase/overview/security-2043272.html
18
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Mission Control 5.4
19
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Flight Recorder – How is it built?
• Information
gathering
− Instrumentation calls all over the JVM
− Application information via Java API
• Collected
in Thread Local buffers
⇢ Global Buffers ⇢Disk
• Binary, proprietary file format
• Managed via JMX
• Java Flight Recorder
− Start from JMC 5.3 or CLI
• Activate Flight Recorder
− -XX: +UnlockCommercialFeatures
− -XX: +FlightRecorder
20
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Advanced Management Console
Build for managing the Java clients in enterprises
Automatically tracks Java applet and Java web Start application usage
Enables management of deployment rules
Deployment Rule Sets - Desktop Administrators can control multiple Java versions
•
•
•
•
Lots of managed clients
Different applications need different Java versions
and different users need several at once
Mitigate risk of security by limiting the exposure of old versions
Controlling Compatibility with Deployment Rule Sets
• This application needs JDK 8u20, that needs JDK 6u38, those need JDK 7u40
Blocking Applications with Deployment Rules
•
•
21
Block configurations are whitelist or blacklist
Use old version only for known-safe programs
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Advanced Management Console
22
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JavaFX via Open Source im JDK 8
Open Source
Übergang
Standardisierung
OpenJFX Project under Common license with
Oracle committed to
JavaFX standardization
First phase to focus on JavaFX included in
JSR to be submitted
through JCP and JSR
expected for JDK 9
OpenJDK
UI Controls
Java SE
Java SE with JDK 8
JavaFX for Java SE
Embedded (ARM)
23
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JavaFX ist die strategische Java-UI-Technologie
für Rich-Client-Anwendungen
Einheitliche Applikationsentwicklung für Java- und Web-Anwendungen
•
•
•
Browser Plug-in, Web Start, Native Executables
Hardware Accelerated Graphics (DirectX, OpenGL)
JavaFX wird mit HTML-DOM ausgestattet
−
JavaFX mit WebView für HTML5 Features (Web Sockets, offline Browsing, lokale Datenbank)
−
Leistungsfähige JavaScript Engine
−
JavaFX als Applet eingebettet in einer Web-Seite lauffähig
JavaFX 2.0 Plattform Sprachwechsel vollzogen
•
Java als native Sprache - anstatt JavaFX Script
•
JavaFX APIs in Java implementiert
•
Vorteile bei Verwendung von Generics, Annotations und Multithreading für JavaFX
JavaFX 8 im JDK 8 enthalten und mit NetBeans 8 unterstützt
•
•
•
Migrationspfad für Swing- und SWT-basierte Anwendungen
JFXPanel Komponente ermöglicht das Einbinden von JavaFX Anwendungen in Swing
Open Source mit OpenJFX und im JCP standardisiert
JavaFX Scene Builder 2.0 GA
24
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JavaFXPorts: JavaFX on Mobile and Tablets
Package your JavaFX Application for deployment on iOS and Android
• JavaFX on client, desktop, laptop and embedded systems
• JavaFX on mobile and tablets
• Why is a port needed? - Isn't Java Write Once Run Anywhere?
OpenJDK
http://javafxports.org/page/home
25
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Compact-Profile für festgelegten Speicherbedarf
RI Binaries under the GNU General
Public License version 2 and
under the Oracle Binary Code License
• Compact Profile 1 (13.8 MB)
• Compact Profile 2 (17.5 MB)
• Compact Profile 3 (19.5 MB)
26
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Compact-Profile mit Packages
Compact1 Profil
java.lang
java.io
java.nio
java.text
java.math
java.net
javax.net
java.util
java.util.logging
java.security
javax.crypto
javax.security
27
Compact2 Profil
java.sql
jvax.sql
javax.xml
org.w3c.dom
org.xml.sax
java.rmi
javax.rmi
javax.transaction
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Compact3 Profil
java.lang.management
javax.management
javax.naming
java.sql.rowset
javax.security.auth.kerberos
org.ietf.jgss
javax.script
javax.xml.crypto
java.util.prefs
javax.security.sasl
javax.security.acl
javax.lang.instrument
javax.annotation.processing
javax.lang.model
javax.lang.model.element
javax.lang.model.type
javax.lang.model.util
javax.tools
Vollständige JRE
java.applet
java.awt
java.beans
javax.activity
javax.rmi
javax.rmi.CORBA
org.omg
javax.accessibility
javax.imagio
javax.print
javax.sound
javax.swing
javax.activation
javax.jws
javax.xml.bind
javax.xml.soap
javax.xml.ws
javax.annotation
Compact-Profile – Neue Option für „javac“
• New “javac” option
‒ javac -target 8 -profile Profile
‒ The javac compiler will verify java code against APIs available in profile
‒ $ javac -profile compact1 Hello.java
• New “jar” option
‒ jar -profile Profile
‒ Marks jar file with minimum required profile
‒ Main application jar file defines default minimum profile
• Runtime verification of profile
‒ jar files will be validated at startup to ensure minimum profile is running
• “java -version” will report active profile
28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Der Weg zur polyglotten VM:
Sprachen die auf der JVM laufen
Groovy
JRuby
…
…
Scala
Clojure
29
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
JavaScript
Project Nashorn
• Lightweight, high-performance JavaScript engine
− Integrated into JRE
• ECMAScript 5.1 compliant JavaScript that runs on the JVM
− Accessible via javax.script API or jjs command line
• Replacement for Rhino
• Exploits JSR-292 via Dynalink
• Fully part of the OpenJDK
• Available on Java SE and Java ME
• Nashorn - Der Weg zur polyglotten VM
30
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Project Nashorn Leistungsfähigkeit
‒Test app executes Esprima parser and tokenizer
bitbucket.org/ariya/nashorn-speedtest
‒Rhino gets the first chance, Nashorn follows right after, each engine gets 30 runs
In the beginning, Rhino’s first run is 2607 ms and slowly it speeds up and finally this parsing is completed in just 824 ms
‒Nashorn timings have a different characteristic
When it is cold, Nashorn initially takes 5328 ms to carry out the operation but it quickly picks up the pace and imediate,
it starts moving full steam ahead, reaching 208 ms per run
‒Nashorn compiles JavaScript code into Java bytecodes and run them on the JVM itself
Nashorn is taking advantage of invokedynamic instruction to permit "efficient and flexible execution" in a dynamic
environment such as JavaScript
mytext
31
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quelle: http://ariya.ofilabs.com/2014/03/nashorn-the-new-rhino-on-the-block.html
Project Nashorn
Invokedynamic Bytecode und „MethodHandle“
32
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java SE Roadmap
JDK 7u21
JDK 7u40/45/51/55
JDK 8 GA18th of March 2014
JDK 8.1 (Q3 2014)
• Java Client
Security
Enhancements
• Java Flight Recorder
in JDK
• Lambda
• Deterministic G1
• Jigsaw
• Native Memory
Tracking
• Complete JVM Convergence
• JMC 6
• Interoperability
• JavaScript Interoperability
• Improved JRE
installer
• Optimizations
• Japp bundling
enhancements
• Ease of Use
• Java Discovery
Protocol
• JavaFX 8
− Public UI Control API
− Java SE Embedded support
• App Store Packaging
Tools
JDK 9
• Cloud
• JavaFX JSR
− Enhanced HTML5 support
2014
2013
JDK 8.2
2015
2016
NetBeans IDE 7.3
NetBeans IDE 8
NetBeans IDE 9
• New hints and refactoring
• Scene Builder support
• JDK 8 support
• Scene Builder 2.0 support
• JDK 9 support
• Scene Builder 3.0 support
Scene Builder 1.1
• Linux support
33
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Scene Builder 2.0
• JavaFX 8 support
• Enhanced Java IDE support
Scene Builder 3.0
• JavaFX 9 support
JDK 8 Update 40 Early Access Release
• 8u40 Build b02
https://jdk8.java.net/download.html
Feedback forum
Report Bugs
• Changes in JDK 8u40 Build b02
http://hg.openjdk.java.net/jdk8u/jdk8u40/hotspot
•These early access release downloads of the JRE and JDK are based on code
available on OpenJDK at the time they were built and might not include the latest
security patches
34
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Zusammenfassung
• Java SE 8 enthält neue Funktionalität
– Language
– Libraries
– JVM
• Java entwickelt sich kontinuierlich weiter
– jdk8.java.net
– www.jcp.org
– openjdk.java.net/jeps
35
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Danke!
[email protected]
Twitter:
36
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
@wolflook
Herunterladen