• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java7 normandyjug
 

Java7 normandyjug

on

  • 639 views

 

Statistics

Views

Total Views
639
Views on SlideShare
621
Embed Views
18

Actions

Likes
0
Downloads
9
Comments
0

1 Embed 18

http://www.normandyjug.org 18

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Java7 normandyjug Java7 normandyjug Presentation Transcript

    • Java 7NormandyJUGAlexis Moussine-PouchkineOracle
    • The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may not be incorporated intoany contract. It is not a commitment to deliver anymaterial, code, or functionality, and should not berelied upon in making purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle’sproducts remains at the sole discretion of Oracle. 2
    • Priorities for the Java Platforms Grow Developer Base Grow Adoption Increase Competitiveness Adapt to change
    • A long long time ago...
    • 1.0 • 1996 • WORA • BouncingDuke
    • 1.0 1.2 1.4 • 1996 • 1998 • 2002 • WORA • Collections • JCP • Bouncing • Swing • XMLDuke 1.1 1.3 • 1997 • 2000 • JDBC • Hotspot • JavaBeans
    • 1.0 1.2 1.4 6 • 1996 • 1998 • 2002 • 2006 • WORA • Collections • JCP • Perf. • Bouncing • Swing • XML • JConsoleDuke 1.1 1.3 5.0 • 1997 • 2000 • 2004 • JDBC • Hotspot • Generics • JavaBeans • Annotations
    • Evolving the LanguageFrom “Evolving the Java Language” - JavaOne 2005• Java language principles – Reading is more important than writing – Code should be a joy to read – The language should not hide what is happening – Code should do what it seems to do – Simplicity matters – Every “good” feature adds more “bad” weight – Sometimes it is best to leave things out• One language: with the same meaning everywhere • No dialects• We will evolve the Java language • But cautiously, with a long term view • “first do no harm” also “Growing a Language” - Guy Steele 1999 “The Feel of Java” - James Gosling 1997 9
    • 1.0 1.2 1.4 6 • 1996 • 1998 • 2002 • 2006 • WORA • Collections • JCP • Perf. • Bouncing • Swing • XML • JConsoleDuke 1.1 1.3 5.0 7 • 1997 • 2000 • 2004 2011 • • JDBC • Hotspot • Generics Project • • Annotations • JavaBeans Coin
    • Java SE 7 Release Contents JSR-336: Java SE 7 Release Contents• Java Language • Project Coin (JSR-334)• Class Libraries • NIO2 (JSR-203) • Fork-Join framework, ParallelArray (JSR-166y)• Java Virtual Machine • The DaVinci Machine project (JSR-292) • InvokeDynamic bytecode• Miscellaneous enhancements 12
    • Better Integer Literal• Binary literals int mask = 0b101010101010;• With underscores for clarity int mask = 0b1010_1010_1010; long big = 9_223_783_036_967_937L; 13
    • String Switch Statement• Today case label includes integer constants and enum constants• Strings are constants too (immutable) 14
    • Discriminating Strings Todayint monthNameToDays(String s, int year) { if("April".equals(s) || "June".equals(s)|| "September".equals(s)||"November".equals(s)) return 30; if("January".equals(s) ||"March".equals(s) || "May".equals(s) ||"July".equals(s) || "August".equals(s) ||"December".equals(s)) return 31; 15
    • Strings in Switch Statementsint monthNameToDays(String s, int year) { switch(s) { case "April": case "June": case "September": case "November": return 30; case "January": case "March": case "May": case "July": case "August": case "December": return 31; case "February”: ... default: ... 16
    • Simplifying Generics• Pre-generics List strList = new ArrayList(); 17
    • Simplifying Generics• Pre-generics List strList = new ArrayList();• With Generics List <String> strList = new ArrayList <String>(); List<String> ArrayList<String> (); 18
    • Simplifying Generics• Pre-generics List strList = new ArrayList();• With Generics List <String> strList = new ArrayList <String>(); List<String> ArrayList<String> (); List <Map<String, List<String> > strList = List< List<String>> new ArrayList <Map<String, List<String> >(); ArrayList< List<String>> 19
    • Diamond Operator• Pre-generics List strList = new ArrayList();• With Generics List <String> strList = new ArrayList <String>(); List<String> ArrayList<String> (); List <Map<String, List<String> > strList = List< List<String>> new ArrayList <Map<String, List<String> >(); ArrayList< List<String>> <>)• With diamond (<> compiler infers type List <String> strList = new ArrayList <>(); List<String> ArrayList<> (); List <Map<String, List<String> > strList = List< List<String>> new ArrayList <>(); ArrayList<> (); 20
    • Copying a FileInputStream in = new FileInputStream(src);OutputStream out = new FileOutputStream(dest);byte[] buf = new byte[8192];int n;while (n = in.read(buf)) >= 0) out.write(buf, 0, n); 21
    • Copying a File (Better, but wrong)InputStream in = new FileInputStream(src);OutputStream out = new FileOutputStream(dest);try { byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n);} finally { in.close(); out.close();} 22
    • Copying a File (Correct, but complex)InputStream in = new FileInputStream(src);try { OutputStream out = new FileOutputStream(dest); try { byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n); } finally { out.close(); }} finally { in.close();} 23
    • Copying a File (Correct, but complex)InputStream in = new FileInputStream(src);try { OutputStream out = new FileOutputStream(dest); try { byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n); } finally { out.close(); }} finally { Exception thrown from in.close(); potentially three places.} Details of first two could be lost
    • Automatic Resource Managementtry (InputStream in = new FileInputStream(src), OutputStream out = new FileOutputStream(dest)){ byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n);} 25
    • The Details• Compiler de-sugars try-with-resources into nested try-finally blocks with variables to track exception state• Suppressed exceptions are recorded for posterity using a new facility of Throwable• API support in JDK 7 • New superinterface java.lang.AutoCloseable • All AutoCloseable and by extension java.io.Closeable types useable with try-with-resources • anything with a void close() method is a candidate • JDBC 4.1 retrofitted as AutoCloseable too 26
    • Exceptions Galoretry { ...} catch(ClassNotFoundException cnfe) { doSomethingClever(cnfe); throw cnfe;} catch(InstantiationException ie) { log(ie); throw ie;} catch(NoSuchMethodException nsme) { log(nsme); throw nsme;} catch(InvocationTargetException ite) { log(ite); throw ite;} 27
    • Multi-Catchtry { ...} catch (ClassCastException e) { doSomethingClever(e); throw e;} catch(InstantiationException | NoSuchMethodException | InvocationTargetException e) { log(e); throw e;} 28
    • <Insert Picture Here>DemoProject Coin (with Java EE 6)
    • New I/O 2 (NIO2) LibrariesJSR 203• Original Java I/O APIs presented challenges for developers • Not designed to be extensible • Many methods do not throw exceptions as expected • rename() method works inconsistently • Developers want greater access to file metadata• Java NIO2 solves these problems 30
    • Java NIO2 Features• Path is a replacement for File • Biggest impact on developers• Better directory support • list() method can stream via iterator • Entries can be filtered using regular expressions in API• Symbolic link support• java.nio.file.Filesystem • interface to a filesystem (FAT, ZFS, Zip archive, network, etc)• java.nio.file.attribute package • Access to file metadata 31
    • java.nio.file.Path• Equivalent of java.io.File in the new API – Immutable• Have methods to access and manipulate Path• Few ways to create a Path – From Paths and FileSystem//Make a reference to the pathPath home = Paths.get("/home/fred");//Resolve tmp from /home/fred -> /home/fred/tmpPath tmpPath = home.resolve("tmp");//Create a relative path from tmp -> ..Path relativePath = tmpPath.relativize(home)File file = relativePath.toFile(); 32
    • File Operation – Copy, Move• File copy is really easy – With fine grain control Path src = Paths.get("/home/fred/readme.txt"); Path dst = Paths.get("/home/fred/copy_readme.txt"); Files.copy(src, dst, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);• File move is supported – Optional atomic move supported Path src = Paths.get("/home/fred/readme.txt"); Path dst = Paths.get("/home/fred/readme.1st"); Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE); 33
    • Directories• DirectoryStream iterate over entries – Scales to large directories – Uses less resources – Smooth out response time for remote file systems – Implements Iterable and Closeable for productivity• Filtering support – Build-in support for glob, regex and custom filters Path srcPath = Paths.get("/home/fred/src"); try (DirectoryStream<Path> dir = srcPath.newDirectoryStream("*.java")) { for (Path file: dir) System.out.println(file.getName()); } 34
    • Concurrency and Collections Updates - JSR 166y 10,000000 1,000,000 Transistors (1,000s) 100,000 10,000 1,000 Clock (MHz) 100 10 1 1970 1975 1980 1985 1990 1995 2000 2005 2010 35
    • ForkJoin Framework• Goal is to take advantage of multiple processor• Designed for task that can be broken down into smaller pieces – Eg. Fibonacci number fib(10) = fib(9) + fib(8)• Nearly always recursive – Probably not efficient unless it is if I can manage the task perform the task else fork task into x number of smaller/similar task join the results 36
    • ForkJoin Example – Fibonaccipublic class Fibonacci extends RecursiveTask< Integer> { RecursiveTask<Integer > private final int number; public Fibonacci(int n) { number = n; } @Override protected Integer compute() { switch (number) { case 0: return (0); case 1: return (1); default: Fibonaccif1 = new Fibonacci(number – 1); Fibonaccif2 = new Fibonacci(number – 2); f1.fork(); f2.fork(); return (f1.join() + f2.join()); } }} 37
    • ForkJoin Example – FibonacciForkJoinPool pool = new ForkJoinPool();Fibonacci r = new Fibonacci(10);pool.submit(r);while (!r.isDone()) { //Do some work ...}System.out.println("Result of fib(10) ="+r.get()); 38
    • <Insert Picture Here>DemoFork-Join Framework
    • invokedynamic Ceylon Fantom Gosu Kotlin 40
    • InvokeDynamic Bytecode• JVM currently has four ways to invoke method – Invokevirtual, invokeinterface, invokestatic, invokespecial• All require full method signature data• InvokeDynamic will use method handle – Effectively an indirect pointer to the method• When dynamic method is first called bootstrap code determines method and creates handle• Subsequent calls simply reference defined handle• Type changes force a re-compute of the method location and an update to the handle – Method call changes are invisible to calling code 41
    • Miscellaneous enhancements• JDBC 4.1, RowSet 1.1• Security: Elliptic curve cryptography, TLS 1.2• Unicode 6• JAXP 1.4.4, JAX-WS 2.2, JAXB 2.2• Swing: Nimbus L&F, JXLayer, HW accelerations• ClassLoader architecture changes• close() for URLClassLoader• Javadoc support for CSS• New Objects class 42
    • Other EnhancementsClient & Graphics• Added Nimbus L&F to the standard – Much better –modern- look than what was previously available• Platform APIs for Java 6u10 Graphics Features – Shaped and translucent windows• JXLayer core included in the standard – Formerly SwingLabs component – Allows easier layering inside of a component• Optimized Java2D Rendering Pipeline for X-Windows – Allows hardware accelerated remote X 43
    • 44
    • Java 7 : Available today!• Plan "B" - Sept. 2010• JSR approved - Dec. 2010• Java 7 Launch - 07/07• JSR Final Approval Ballots • JavaSE 8 passed with 15 YES, 1 NO (Google) votes • Project Coin passed with 16 YES votes • NIO2 passed with 16 YES votes • InvokeDynamic passed with 16 YES votes• Java SE 7 Reference Implementation (RI)• Java 7 Oracle SDK on July 28th 2011• ... You are• Java 7 updates here
    • Oracle JDK 7 Updates• Support for Apples Mac OS X • Use OpenJDK for the time being (easy)• Expect several JDK 7 update releases • More platform support • Improved performance • Bug fixes • Regular HotRockit* progress • remove PermGen (yay!) • large heaps with reasonable, then predictable latencies • serviceability improvements ported over to HotSpot from JRockit • JRockit Mission Control • JRockit Flight Controler *: tentative name for the HotSpot/JRockit converged JVM
    • Java SE 8 Project Jigsaw (JSR-294) Modularizing the Java Platform Project Lambda (JSR 335) Closures and lambda expressions More Project Coin Small Language Changes 47
    • More about Java 8• More Content : • Annotations on Java types (JSR 308) • Wish List * : • Serialization fixes • Multicast improvements • Java APIs for accessing location, compass and other ”environmental” data (partially exists in ME) • Improved language interop • Faster startup/warmup • Dependency injection (JSR 330) • Include select enhancements from Google Guava • Small Swing enhancements • More security/crypto features, improved support for x.509-style certificates etc • Internationalization: non-Gregorian calendars, more configurable sorting • Date and Time (JSR 310) • Process control API• Schedule • Late 2012 (planning in progress) *: a good number will NOT make the list
    • Priorities for the Java Platforms Grow Developer Base Grow Adoption Increase Competitiveness Adapt to change
    • Java Communities
    • • Free and Open Source Software (FOSS)• Open to all • Corporate contributors: Oracle, RedHat, IBM, Apple, SAP • Key individual contributors • Ratified By-laws• Serves as the JavaSE reference implementation (RI)• Where java.next is being developed• http://openjdk.org
    • How Java Evolves and Adapts Community Development of Java Technology Specifications
    • JCP Reforms• Developers voice in the Executive Committees • SOUJava • London JavaCommunity• JCP starting a program of reform • JSR 348: Towards a new version of the JCP (JCP.next) • First of two JSRs to update the JCP itself
    • Conclusions• Java SE 7 • Incremental changes • Evolutionary, not revolutionary • Good solid set of features to make developers life easier• OpenJDK as a thriving open source project• Java SE 8 • Major new features: Modularization and Closures • More smaller features to be defined• Java continues to grow and adapt to the challenges• Community play required 55
    • 57