©2011 Oracle Corporation
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.
<Insert Picture Here>
The Java SE 7 & 8 : now and the future
Francisco Morero PeyronaJava ArchitectDuke Award Winner Based in a previous work of Simon Ritter
[email protected]@javahispano.org
The state of Java
<Insert Picture Here>
©2011 Oracle Corporation
Java Communities
©2011 Oracle Corporation
Middleware and Java in Oracle’s Strategy
•Comprehensive foundation for building and running custom and packaged applications• Extremely well integrated• Industry-leading reliability and performance
•Unified development and management•Basis for Oracle Fusion Applications
•Built with and for Java technology
©2011 Oracle Corporation
©2011 Oracle Corporation
100% of Blu-ray Disc Players
5 Billion SIM Cards
3 Billion Mobile Handsets
Java Client Deployment
75m desktops updated/month
©2011 Oracle Corporation
7July 2011
Java SE 7 Highlights
• Careful additions to the Java language• New filesystem API• New Fork/Join framework for concurrent
programming• New bytecode to speed dynamic
languages on the JVM
int 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: ...
Strings in Switch Statements
Did you know it produces generally more efficient byte codes than an if-then-else statement? Case Sensitive!
try (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);}
Automatic Resource Management
• New superinterface java.lang.AutoCloseable• All AutoCloseable (throws Exception) and by extension java.io.Closeable
(throws IOException) types useable with try-with-resources• Anything with a void close() method is a candidate• JDBC 4.1 retrofitted as AutoCloseable too
try {...
} catch( ClassCastException e ) { doSomethingClever(e); throw e;} catch( InstantiationException | NoSuchMethodException |
InvocationTargetException e ) { // Useful if you do generic actions
log( e ); throw e;
}
Multi-Catch
List<String> strList = new ArrayList<>();
OR
List<Map<String, List<String>> strList = new ArrayList<>();
OR
Foo<Bar> foo = new Foo<>();foo.mergeFoo( new Foo<>() );
Diamond Operator → compiler infers type
Watching A Directory
•Create a WatchService “watcher” for the filesystem•Register a directory with the watcher•“Watcher” can be polled or waited on for events
• Events raised in the form of Keys• Retrieve the Key from the Watcher• Key has filename and events within it for create/delete/modify
•Ability to detect event overflows
● FileSystems class is factory to great FileSystem (interface)
● Java 7 allows for developing custom FileSystems, for example:● Memory based or zip file based systems● Fault tolerant distributed file systems
● Replacing or supplementing the default file system provider
● Two steps:● Implement java.nio.file.spi.FileSystemProvider
●URI, Caching, File Handling, etc.● Implement java.nio.file.FileSystem
●Roots, RW access, file store, etc.
Custom FileSystems
Fork Join Framework - JSR 166y - Pools
• ForkJoinPool–Service for running ForkJoinTasks–aFjp.execute(aTask); // async–aFjp.invoke(aTask); // wait–aFjp.submit(aTask); // async + future
–ForkJoinPool(); // default to platform–ForkJoinPool(int n); // # concurrent threads–ForJoinPool(n,aThreadFactory,exHandler,FIFOtasks); // Create your own thread handler, exception // handler, and boolean on task ordering (default LIFO)
Fork Join Framework - JSR 166y - Tasks
• ForkJoinTask–The abstract base class for:• RecursiveAction
– A recursive resultless task– Implements compute() abstract method to perform calculation
• RecursiveTask– Similar to RecursiveAction but returns a result
ForkJoinPool p = new ForkJoinPool(); MyTask mt = new MyTask(n); // implements compute p.submit(mt);while (!mt.isDone()) {/*THUMPER!*/ }System.out.println(mt.get());
Fork Join Framework - JSR 166y - compute()
• RecursiveAction example to increment an entire arrayprotected void compute() { if (hi - lo < THRESHOLD) { for (int i = lo; i < hi; ++i) array[i]++; } else { int mid = (lo + hi) >>> 1; invokeAll(new IncrementTask(array, lo, mid), new IncrementTask(array, mid, hi)); }
• RecursiveTask example for Fibonacci numbersprotected Integer compute() { if (n <= 1) return n; Fibonacci f1 = new Fibonacci(n - 1); Fibonacci f2 = new Fibonacci(n - 2); f1.fork(); f1.fork(); return f2.join() + f1.join();}
<Insert Picture Here>
invokedynamic Illustrated
this[method_name](x, y)
invokedynamic [#bootstrapMethod] .this_method_name
class LangaugeRuntime {bootstrapMethod(info) {...return new CallSite();
}
class AClass {aMethod(x, y) {...
}
CallSite
MethodHandle
1. Invoke bootstrap
2. Produces CallSite
3.Complete linkage
4. Invokes method implementation
Se une a:●invokevirtual●invokestatic●invokeinterface●invokespecial
JavaFX
<Insert Picture Here>
©2011 Oracle Corporation
JavaFX 1.0JavaFX Script
Scenegraph
Media
2008 2009 2010 2011
JavaFX 2.0Java APIs
UI Controls
New media stack
New graphics stack
JavaFX 1.1Mobile
JavaFX 1.2UI Controls
JavaFX 1.3Performance
More UI Controls
©2011 Oracle Corporation
JavaFX 2.0 Motivation
• Java developers didn’t want to learn a new language for RIA development
• Web developers did not adopt JavaFX Script as quickly as we’d hoped
• Interest in using JavaFX features in other languages
©2011 Oracle Corporation 15
Desktop: JavaFX 2.0 takes a fresh view
•Development now in Java language •New Java APIs for JavaFX functionality•New media stack•New lightweight graphics stack•Swing integration
JavaFX RoadmapJavaFX 8.0
• Included in JDK 8
• Concurrent OS support(Windows, Mac OS, Linux)
JavaFXScene Builder GA
NetBeans• JavaFX 8.0 Support
JavaFX 2.2• Linux GA
JavaFX 2.1• Mac OS X GA
• Linux Dev. Preview
2011 2012 2013 2014
JavaFXScene Builder EA
JavaFX 2.0
• Windows GA
• Mac OS X Dev. Preview
NetBeans 7.1• JavaFX 2.0 Support
JavaFX 2.0.2• JDK 7 co-install
©2011 Oracle Corporation
82013
Java SE 8 Projects
• Project Lambda• Lambda expressions• Interface evolution• Concurrent bulk data operations
• Date and time API updates• Annotations on Java types
©2011 Oracle Corporation
JDK 8 – Proposed Content
← Probably deferred
Lambda I: Abstract Method (SAM) Types
● Lots of examples in the Java APIs•Runnable, Callable, EventHandler, Comparator
● Noise: work ratio is 5:1● Lambda expressions grow out of the idea of making callback objects easier
foo.doSomething( new CallbackHandler() { public void callback( Context c ) { System.out.println( c.v() ); } });
Lambda II: Expression Examples
(Context c) -> System.out.println( c.v() );
c -> System.out.println( c.v() ); // Inferred
int x -> x + 1
Lambda III: Rules
● Rule #1: Only in a context where it can be converted to a SAM type
● Rule #2: A list of statements just like in a method body, except no break or continue at the top level. The return type is inferred from the unification of the returns from the set of return statements
● Rule #3: ‘this’ has the same value as ‘this’ immediately outside the Lambda expression
● Rule #4: Lambdas can use‘effectively final’ variables as well as final variables (compiler inferred)
Classpath hell - I
classpath
$ java -cp $APPHOME/lib/jdom-1.0.jar:$APPHOME/lib/jaxen-1.0.jar:$APPHOME/lib/saxpath-1.0.jar:$APPHOME/lib/rome.jar-1.0.jar:$APPHOME/lib/rome-fetcher-1.0.jar:$APPHOME/lib/joda-time-1.6.jar:$APPHOME/lib/tagsoup-1.2.jar:org.planetjdk.aggregator.Main
Classpath hell – II : module-info.java
module org.planetjdk.aggregator @ 1.0 { requires jdom @ 1.0; requires tagsoup @ 1.2; requires rome @ 1.0; requires rome-fetcher @ 1.0; requires joda-time @ 1.6; requires jaxp @ 1.4.4; class org.openjdk.aggregator.Main;}
jdom-1.0
jaxen-1.0
saxpath-1.0
rome-1.0
joda-time-1.6
tagsoup-1.2
jaxp-1.4.4
org.planetjdk.aggregator
rome-fetcher-1.0
Java SE Profiles and Modules
● Rules for creating modules of the Java SE platform• Java SE base profile• Java SE base module• Component modules for separable technologies
©2011 Oracle Corporation
9++Java SE 9, 10, 11, 12 Projects
• Project Jigsaw• Modular applications• Modular JRE
• Careful changes to the Java language• Cloud computing support
✔ Java continues to evolve✔ Addressing needs of new application types✔ Supporting new computing platforms
The Future of Java
• Java continues to evolve• Addressing needs of new application types• Supporting new computing platforms
9 (and beyond…)
Vision: Interoperability
● Improved support for non-Java languages• Invokedynamic (done)• Java/JavaScript interop (in progress – JDK 8)• Meta-object protocol (JDK 9)• Long list of JVM optimizations (JDK 9+)
● Java/Native• Calls between Java and Native without JNI boilerplate (JDK 9)
Vision: Cloud
● Multi-tenancy (JDK 8+)• Improved sharing between JVMs in same OS• Per-thread/threadgroup resource tracking/management
● Hypervisor aware JVM (JDK 9+)•Co-operative memory page sharing•Co-operative lifecycle, migration
Vision: Language Features
● Large data support (JDK 9)•Large arrays (64 bit support)
● Unified type system (JDK 10+)•No more primitives, make everything objects
● Other type reification (JDK 10+)•True generics•Function types
● Data structure optimizations (JDK 10+)•Structs, multi-dimensional arrays, etc•Close last(?) performance gap to low-level languages
Vision: Integration
● Modern device support (JDK 8+)• Multitouch (JDK 8)• Location (JDK 8)• Sensors – compass, accelerometer, temperature, pressure, ... (JDK 8+)
● Heterogenous compute models (JDK 9+)• Java language support for GPU, FPGA, offload engines, remote PL/SQL...
Java SE 2012 to Java 12
20112011 20152015 20192019 20142014
JDK 7JDK 7
20132013 20212021
JDK 12JDK 12
20172017
JDK 8JDK 8 JDK 9JDK 9 JDK 10JDK 10 JDK 11JDK 11
20122012
JVM convergence
Mac OS X
JVM convergence
Mac OS X