java8-features

28
Java SE 8 Features Neuerungen in Java SE 8 pr sentiert von Sascha Koch ä 12. M rz 2014 ä JUG Bielefeld

description

Java SE 8 Präsentation im Rahmen der JUG Bielefeld am 12.03.2014.

Transcript of java8-features

Page 1: java8-features

Java SE 8 Features

Neuerungen in Java SE 8pr sentiert von Sascha Kochä

12. M rz 2014ä

JUG Bielefeld

Page 2: java8-features

12.03.2014 Java SE 8

Alle freuen sich auf Java 8

Quelle www.heise.de

Page 3: java8-features

12.03.2014 Java SE 8

Programm f r heute abendü

● > 50 Neuerungen in Java SE 8● Hands-on Session mit λ-Expressions, der Stream API, den default methods und mehr

Page 4: java8-features

12.03.2014 Java SE 8

Java 8 JEPs General● 126 Lambda Expressions & Virtual Extension Methods

(aka defender or default methods)

● 138 Autoconf-Based Build System (for the jdk itself)

● 160 Lambda-Form Representation for Method Handles (reduce assembly code and native calls, performance optimization, reference implementation of invokedynamic / JSR-292)

● 161 Compact Profiles (instead of jigsaw 140/24/17/10 MB)→

● 162 Prepare for Modularization(getting ready for jigsaw, java.util.logging and swing)

Page 5: java8-features

12.03.2014 Java SE 8

Java 8 JEPs General● 164 Leverage CPU Instructions for AES Cryptography

(Intel M rz 2008)ä

● 174 Nashorn JavaScript Engine (lightweight, high-performance, ECMAScript-262 5.1)

● 176 Mechanical Checking of Caller-Sensitive Methods (improve security of method-handle implementation, behaviour changed based on the caller)

● 179 Document JDK API Support and Stability (mark core and non-core APIs, what is maintained?)

Page 6: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Core● 153 Launch JavaFX Applications

(launch() from java cmd line)

● 101 Generalized Target-Type Inference Code (only partly realized)

● 104 Annotations on Java Types Code (applied to any use of a type, not at runtime :( )

● 105 DocTree API (provide structured access to javadoc content)● 106 Add Javadoc to javax.tools

(call javadoc from within vm)

Page 7: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Core● 117 Remove the Annotation-Processing Tool (in javac)● 118 Access to Parameter Names at Runtime Code

(partly realized)

● 120 Repeating Annotations Code (avoid container annotations, somehow)

● 139 Enhance javac to Improve Build Speed (use of all available cores)

● 172 DocLint Code(static doc analysis, Fusselig, W3C HTML 4.01 HTML conform)

Page 8: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Garbage Collection● 142 Reduce Cache Contention on Specified Fields (pad variables to avoid sharing cache lines)

● 122 Remove the Permanent Generation(Permanently, PermGen moves to native memory)

● 173 Retire Some Rarely-Used GC Combination (e.g. ParNew + SerialOld, reduce testing effort)

Page 9: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Garbage Collection● 142 Reduce Cache Contention on Specified Fields (pad variables to avoid sharing cache lines)

● 122 Remove the Permanent Generation(Permanently, PermGen moves to native memory)

● 173 Retire Some Rarely-Used GC Combination (e.g. ParNew + SerialOld, reduce testing effort)

Page 10: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Runtime● 136 Enhanced Verification Errors

(additional information bytecode verification errors)

● 147 Reduce Class Metadata Footprint(taken from ME)

● 148 Small VM(libjvm.so < 3MB, compiling size over speed)

● 171 Fence Intrinsics(sun.misc.Unsafe, memory access)

Page 11: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Core Libraries● 103 Parallel Array Sorting (new methods in java.util.Arrays)

● 107 Bulk Data Operations for Collections(java.util.function, java.util.stream)

● 109 Enhance Core Libraries with Lambda(Java SE 7 has 4024 standard classes)

● 112 Charset Implementation Improvements(fewer, quicker, better)

● 119 javax.lang.model Implementation Backed by Core Reflection

Page 12: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Core Libraries● 135 Base64 Encoding & Decoding

(previously in sun.misc.*, now java.util.*)

● 149 Reduce Core-Library Memory Usage(reduce dynamic memory)

● 150 Date & Time API (Wurde auch Zeit!)

● 155 Concurrency Updates(Doug Lea Stuff)

● 170 JDBC 4.2 (new Date API support)

Page 13: java8-features

12.03.2014 Java SE 8

How many Bugs?Date date = new Date(2014, 12, 24, 16, 40);

TimeZone zone =

   TimeZone.getTimeZone(“Asia/HongKong”);

Calendar cal = 

   new GregorianCalendar(date, zone);

DateFormat fm = 

   new SimpleDateFormat(“HH:mm Z”);

String str = fm.format(cal);

Page 14: java8-features

12.03.2014 Java SE 8

How many Bugs? 6!Date date = new Date(114, 11, 24, 16, 40);

TimeZone zone =

   TimeZone.getTimeZone(“Asia/Hong_Kong”);

Calendar cal = new GregorianCalendar(zone);

cal.setTime(date);

DateFormat fm = 

   new SimpleDateFormat(“HH:mm Z”);

fm.setTimeZone(zone);

Date calDate = cal.getTime();

String str = fm.format(calDate);

Page 15: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Diverses● 177 Optimize java.text.DecimalFormat.format

(2 x faster for 2 or 3 digits after decimal point)

● 178 Statically-Linked JNI Libraries(previously only dynamically linked)

● 180 Handle Frequent HashMap Collisions with Balanced Trees (performance improvement, previously with linked lists)

Page 16: java8-features

12.03.2014 Java SE 8

Java 8 JEPs Diverses● 127 Improve Locale Data Packaging and Adopt Unicode CLDR Data(standardized locale support)

● 128 BCP 47 Locale Matching(as defined in rfc-4647)

● 133 Unicode 6.2

● 184 HTTP URL Permissions (previously based on IP addresses)

Page 17: java8-features

12.03.2014 Java SE 8

Java 8 Security● 113 MS-SFU Kerberos 5 Extensions

(Microsoft interoperability)

● 114 TLS Server Name Indication (SNI) Extension (new feature)

● 115 AEAD CipherSuites (meet US government and banking requirements)

● 121 Stronger Algorithms for Password-Based Encryption(evolution of cryptography, PBEwith*, previously DESede and RC2 with SHA1)

● 123 Configurable Secure Random-Number Generation(/dev/random Entropie unter Linux ist alle)→

● 124 Enhance the Certificate Revocation-Checking API(more complete,flexible)

Page 18: java8-features

12.03.2014 Java SE 8

Java 8 Security● 129 NSA Suite B Cryptographic Algorithms

(meet US government and banking requirements)

● 130 SHA-224 Message Digests (known flaw in SHA-1)● 131 PKCS#11 Crypto Provider for 64-bit Windows

(use of native Win64 libraries)

● 140 Limited doPrivileged (Lambda expressions)

● 166 Overhaul JKS-JCEKS-PKCS12 Keystores(simplification of keystore handling)

Page 19: java8-features

12.03.2014 Java SE 8

Java 8 JEPs / Web JAXP● 185 JAXP 1.5: Restrict Fetching of External Resources(restrict the set of network protocols used to fetch external resources)

Page 20: java8-features

12.03.2014 Java SE 8

Lambda Expressions

● Aka closures, function literals or Lambdas● From anonymous inner classes to FunctionalInterfaces; previously known as SAM (single abstract method)

● Syntax:1. argument list enclosed in parentheses2. an arrow token ( )→3. a function body

Page 21: java8-features

12.03.2014 Java SE 8

Default methods● Interfaces can have default implementations● Method starts with default

Page 22: java8-features

12.03.2014 Java SE 8

Lambda form representation method handles

● object::instanceMethodArrays.asList(0, -2, 2).forEach(System.out::println); Arrays.asList(0, -2, 2).forEach((x) System.out.println(x));→ →

● Class::staticMethodArrays.asList(0, -2, 2).sort(Integer::compare); Arrays.asList(0, -2, 2).sort((x, y) Integer.compare(x, y));→ →

● Class::instanceMethodArrays.asList(0, -2, 2).sort(Integer::compareTo); Arrays.asList(0, -2, 2).sort((x, y) x.compareTo(y));→ →

Page 23: java8-features

12.03.2014 Java SE 8

Collection vs Stream

Quelle: wikimedia.org

Page 24: java8-features

12.03.2014 Java SE 8

Stream-API● Get a stream from a collectioncollection<E>.stream();

● Generate, limit and skip a streamStream.generate(Supplier<T> s) // staticstream<T>.limit(long)stream<T>.skip(long)

● Manipulate a streamstream<T>.map(Function<T, R>) Stream<R>→

stream<T>.filter(Predicate<T>) Stream<T>→

stream<T>.sorted() Stream<T>→

stream<T>.distinct() Stream<T>→

Page 25: java8-features

12.03.2014 Java SE 8

Stream-API● “Collection a result” of a streamstream<T>.allMatch(Predicate<T>) boolean→

stream<T>.anyMatch(Predicate<T>) boolean→

stream<T>.findAny() Optional<T>→

stream<T>.findFirst() Optional<T>→

stream<T>.max(Comparator<T>) Optional<T>→

stream<T>.min(Comparator<T>) Optional<T>→

stream<T>.reduce(T, BinaryOperator<T>) T→

stream<T>.collect(T, A, R) R→

Page 26: java8-features

12.03.2014 Java SE 8

Stream-API● Default CollectorsCollectors.toList() Collector<T, ?, List<T>>→

Collectors.reducing(T, BinaryOperator<T>) T→

Collectors.joining() Collector<CharSeq, ?, String>→

Collectors.counting() Collector<T, ?, Long>→

Page 27: java8-features

12.03.2014 Java SE 8

Danke!

Page 28: java8-features

12.03.2014 Java SE 8

Referenzen● http://www.youtube.com/watch?v=rtAredKhyac, Simon Ritter● Java SE 8 for the Really Impatient, Cay S. Horstmann● Java 8 in Action, Raoul-Gabiel Urma et.al● http://openjdk.java.net/projects/jdk8/features