java se 8

Download Java SE 8

If you can't read please download the document

Upload: simon-ritter

Post on 11-Nov-2014

465 views

Category:

Software


6 download

DESCRIPTION

Java SE 8 presentation give at the LJC meeting in London on August 28th, 2014.

TRANSCRIPT

  • 1. Java 8: Create The Future Simon Ritter Head of Java Technology Evangelism Oracle Corp. Twitter: @speakjava Copyright 2012, Oracle and/or its affiliates. 1 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 Oracles products remains at the sole discretion of Oracle. Copyright 2012, Oracle and/or its affiliates. 2 All rights reserved.
  • 3. Java SE 8 New Features (Other Than Lambdas and Streams) Copyright 2012, Oracle and/or its affiliates. 3 All rights reserved.
  • 4. 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) {} Copyright 2012, Oracle and/or its affiliates. 4 All rights reserved.
  • 5. Access To Parameter Names At Runtime Mechanism to retrieve parameter names of methods and constructors At runtime via core reflection Improved code readability Eliminate redundant annotations Improve IDE capabilities Auto-generate template code Method and Constructor now inherit from new Executable class getParameters() returns array of Parameter objects Name, type, annotations for each parameter Copyright 2012, Oracle and/or its affiliates. 5 All rights reserved.
  • 6. 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 Copyright 2012, Oracle and/or its affiliates. 6 All rights reserved.
  • 7. 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 Leas ParallelArray implementation Requires working space the same size as the array being sorted Copyright 2012, Oracle and/or its affiliates. 7 All rights reserved.
  • 8. 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 Copyright 2012, Oracle and/or its affiliates. 8 All rights reserved.
  • 9. Unicode 6.2 Java SE 7 support Unicode 6.0 Changes in Unicode 6.1 (February, 2012) Add 11 new blocks to java.lang.Character.UnicodeBlock Add 7 new scripts to java.lang.Character.UnicodeScript Support over 700 new characters in java.lang.Character, String, and other classes Changes in Unicode 6.2 (September, 2012) Support a new Turkish currency sign (U+20BA) Copyright 2012, Oracle and/or its affiliates. 9 All rights reserved.
  • 10. HTTP URL Permissions New type of network permission Grant access in terms of URLs, rather than IP addresses Current way to specify network permissions java.net.SocketPermission Not restricted to just HTTP Operates in terms of IP addresses only New, higher level capabilities Support HTTP operations (POST, GET, etc) Build on limited doPrivileged feature Copyright 2012, Oracle and/or its affiliates. 10 All rights reserved.
  • 11. Compact Profiles Approximate static footprint goals Compact1 Profile Compact2 Profile Compact3 Profile 11Mb 16Mb Full JRE 54Mb Copyright 2012, Oracle and/or its affiliates. 11 All rights reserved. 30Mb
  • 12. 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 Copyright 2012, Oracle and/or its affiliates. 12 All rights reserved.
  • 13. Retire Rarely-Used GC Combinations Rarely used DefNew + CMS ParNew + SerialOld Incremental CMS Large testing effort for little return Will generate deprecated option messages Wont disappear just yet Copyright 2012, Oracle and/or its affiliates. 13 All rights reserved.
  • 14. Remove The Permanent Generation Permanently No more need to tune the size of it Current objects moved to Java heap or native memory Interned strings Class metadata Class static variables Part of the HotSpot, JRockit convergence Copyright 2012, Oracle and/or its affiliates. 14 All rights reserved.
  • 15. Lambdas And Streams Copyright 2012, Oracle and/or its affiliates. 15 All rights reserved.
  • 16. Concurrency in Java Project Lambda java.util.concurrent (jsr166) java.lang.Thread 1.4 5.0 6 7 8 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 Copyright 2012, Oracle and/or its affiliates. 16 All rights reserved. Fork/Join Framework (jsr166y) Phasers, etc (jsr166)
  • 17. The Problem: External Iteration List students = ... double highestScore = 0.0; for (Student s : students) { if (s.getGradYear() == 2011) { if (s.getScore() > highestScore) { highestScore = s.getScore(); } } } Copyright 2012, Oracle and/or its affiliates. 17 All rights reserved. Our code controls iteration Inherently serial: iterate from beginning to end Not thread-safe because business logic is stateful (mutable accumulator variable)
  • 18. Internal Iteration With Inner Classes Copyright 2012, Oracle and/or its affiliates. 18 All rights reserved. Iteration handled by the library Not inherently serial traversal may be done in parallel Traversal may be done lazily so one pass, rather than three Thread safe client logic is stateless High barrier to use Syntactically ugly More Functional, Fluent List students = ... double highestScore = students. filter(new Predicate() { public boolean op(Student s) { return s.getGradYear() == 2011; } }). map(new Mapper() { public Double extract(Student s) { return s.getScore(); } }). max();
  • 19. Internal Iteration With Lambdas SomeList students = ... double highestScore = students. filter(Student s -> s.getGradYear() == 2011). map(Student s -> s.getScore()). max(); Copyright 2012, Oracle and/or its affiliates. 19 All rights reserved. More readable More abstract Less error-prone
  • 20. Lambda Expressions Some Details Lambda expressions represent anonymous functions Same structure as a method typed argument list, return type, set of thrown exceptions, and a body Not associated with a class We now have parameterised behaviour, not just values double highestScore = students. filter(Student s -> s.getGradYear() == 2011). map(Student s -> s.getScore()) max(); What Copyright 2012, Oracle and/or its affiliates. 20 All rights reserved. How
  • 21. Lambda Expression Types Single-method interfaces are used extensively in Java Definition: a functional interface is an interface with one abstract method Functional interfaces are identified structurally The type of a lambda expression will be a functional interface Lambda expressions provide implementations of the abstract method interface Comparator { boolean compare(T x, T y); } interface FileFilter { boolean accept(File x); } interface Runnable { void run(); } interface ActionListener { void actionPerformed(); } interface Callable { T call(); } Copyright 2012, Oracle and/or its affiliates. 21 All rights reserved.
  • 22. Local Variable Capture Lambda expressions can refer to effectively final local variables from the enclosing scope Effectively final: A variable that meets the requirements for final variables (i.e., assigned once), even if not explicitly declared final Closures on values, not variables void expire(File root, long before) { root.listFiles(File p -> p.lastModified() checkExpiry(p.lastModified(), this.before)); } boolean checkExpiry(long time, long expiry) { ... } } Copyright 2012, Oracle and/or its affiliates. 23 All rights reserved.
  • 24. Type Inference The compiler can often infer parameter types in a lambda expression Inferrence based on the target functional interfaces method signature static T void sort(List l, Comparator