KEMBAR78
JavaOne 2011 Recap | PPTX
JavaOne 2011 Recap
Agenda
• New Java SE 7 features
• Java 8 / 9 feature pipeline
• Up and coming Java EE 7 features
• Java EE 7 / Glassfsh 4 beta elasticity demo
New Java 7 Features – Project Coin
• Project Coin – “Small language changes”
– Underscores in Numbers
– Strings in Switch
– Improved Type Inference for Generic Instance
Creation (diamond)
– Try-with-resources
– Multi-catch with more precise rethrow
Underscores in Numbers
• Our scoring models frequently use large
numbers – e.g. 25 million:
25000000
• Hard to read and quickly determine amount
• We can now type:
25_000_000
• Much easier on the eyes!
Strings in Switch
• Instead of having
if(a.equals(“test”)){ return val;} else if
(a.equals(“test2”)) {return val2;} else {return 0;}
• We can now have
switch(a){
case test: return val;
case test2: return val2;
default: return 0;
}
Improved Type Inference
• Tired of typing
Map<String,List<String> > map = new
HashMap<String, List<String>>();
• Now you can type
Map<String, List<String> > map = new
HashMap<>();
instead
• Less typing, more readable code
Improved Type Inference
• Compiler will figure out what needs to go on the
Right Hand Side
• Will work for roughly 90% of cases
• Can be used several places
– Field / Local Variable initialiser (previously shown)
– Assignment Statement
perms = new ArrayList<>();
– Method Argument
setVal(new ArrayList<>());
– Return Statement (based on return type)
return new ArrayList<>();
Try-With-Resources
• Tired of this?
static String readFirstLineFromFileWithFinallyBlock(String path)
throws IOException {
BufferedReader br =
new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
if (br != null) br.close();
}
}
• Fear no more!
Try-With-Resources
• You can do this now:
static String readFirstLineFromFile(String path)
throws IOException {
try (BufferedReader br =
new BufferedReader(new FileReader(path))) {
return br.readLine();
}
}
• No more finally block
• Less clutter in code
Try-With-Resources
• Works on:
– File classes
– Stream classes
– Network classes
– SQL classes
– Classes that implements java.lang.Autocloseable
– Large number of classes retrofitted for Java 7
Multi-Catch
• Instead of having to catch multiple exceptions
and doing the same thing:
try{//dostuff }
catch(Exception1 e){
log.error(e);
} catch(Exception2 e){
log.error(e);
} catch(Exception3 e){
log.warn(e);
}
Multi-Catch
• Can be simplified to
try{//dostuff }
catch(Exception1 | Exception2 e){
log.error(e);
} catch(Exception3 e){
log.warn(e);
}
• Improved readability, less typing
More Precise Rethrow
• Allows for more specific types in exception
clause of method declaration
• Previously, you could only specify one
exception type
More Precise Rethrow
• Previously had to throw parent exception
• public void rethrowException(String exceptionName) throws Exception {
try { if (exceptionName.equals("First")) {
throw new FirstException();
} else {
throw new SecondException();
}
} catch (Exception e) {
throw e;
}
}
More Precise Rethrow
• Can now declare multiple thrown exceptions
public void rethrowException(String exceptionName)
throws FirstException, SecondException {
try {
// ...
} catch (Exception e) {
throw e;
}
}
G1 Garbage Collector
• “Garbage First”
• Introduced in Java 6 release 14 as beta,
• Released for production use in Java 7
• Targeted for multi-processor machines with
large memories
• Decreases the probability of a full GC by
focusing first on areas likely to have most
garbage
NIO.2
• New APIs for filesystem access, scalable
asynchronous I/O operations, socket-channel
binding and configuration, and multicast
datagrams
• Able to treat Zip and Jar files as filesystems
Fork/Join Framework
• Divide and conquer style processing:
• if (my portion of the work is small enough)
– do the work directly
• else
– split my work into two pieces
– invoke the two pieces and wait for the results
• Steals work to ensure all processors are busy
Fork/Join Framework
• Work is split among multiple processors /
cores on a single computer
• Removes the burden of knowing the
intricacies of Java’s concurrency libraries
InvokeDynamic
• Adds the invokedynamic JVM instruction
• Allows dynamically typed language designers
to optimize their JVM instruction calls and
improve dynamic language performance
• Not called from Java
• Used by JRuby, Jython, others
Enhanced MBeans
• Enhancements to existing MBeans to report
the recent CPU load of the whole system, the
CPU load of the JVM process, and to send JMX
notifications when GC events occur
• Could allow for better troubleshooting
capabilities by our support desk staff
Java 8 Features
• Going to two year release cycle
– Jigsaw (modularity)
– Coarse grain modularity baked in – not OSGi
– Smaller footprint, faster startup
– Support for native packages
– New executable format, faster, can include native
libraries
– Dependency specs
Java 8 Features
• Closures
– Novel approach for Java: structural typing
– Single abstract method – SAM
– Will work with existing interfaces/classes
– New parallel collections
– Many cores is the driver for this feature
• Nashorn
– Javascript running natively in the JVM
– Replace Rhino
Java 9 Proposals
• Self-tuning JVM
• Improved JNI
• Big Data
• Type reification (use unknown type information)
• Tail calls / continuations (save a program’s state)
• Meta-object protocol (code that changes
behavior of other code on the fly)
• Heterogeneous Compute
• GPU support
Other Java SE news
• Java FX 2.0 released
– Will replace Swing – Swing no longer enhanced
– Java FX components & engine to be open sourced
• Efforts to bridge Java SE / Java ME
– Cobining development environments
– Combining JCP committees
• Project Avatar – easier web development
– Unified HTML 5 and JavaScript development on all Java
platforms (ME/SE/EE)
• Demos of Java FX running on iPad & Android
• Java 7 released for Mac OS X
Java EE 7
• Big initiatives:
– The Cloud: Make Java 7 a PaaS cloud provider
• Goal is elasticity -> scalability
• Automatic Service Level Management
• Service endpoints handled through load balancer – URLs, JDBC
connections, JMS endpoints, etc.
– Multi-Tenancy
• Ability to allow multiple customers to use same application
instance
• Requires only two annotations on stateful classes:
– @MultiTenant
– @TenantDescriminator
• Other initiatives are largely technology updates
• Final release scheduled for Q3 2012
Could we Benefit? Yes!
• PaaS approach removes burden of guessing
memory configuration for onsite customers
• Dynamically spin up more instances during
End of Day / Exposure Engine runs
• Have one instance that is managed for all
customers, all customers upgraded at once
Java EE 7 Demo
• Demo
• Try it yourself!
• http://glassfish.java.net/javaone2011/
Caching
• Big focus on caching – slated for Java EE 7
• Would enable standardized session replication
• JSR 107 update (and completion?)
• Only need annotations to indicate an object
needs to be managed by a cache
• CAP Theorem – Pick 2
– Consistence (same data on all nodes)
– Availability (every request receives a response)
– Partitioning (system operates despite partial loss)
Data Grids
• Standardization underway – aiming for EE 8
• Builds on JSR 107 Cache spec
• Enables remote code execution - map/reduce
• Grouping API allows grouping of like objects
• Full & partial data replication allow data
scaling
• Synchronous & asynchronous transport APIs
Data Grids
• Transactions not optional
• Querying
• Aggregates both storage and processing
power of a set of apps
• Provides linear scale
• Removes bottleneck on database
• System of Truth – Cache vs. System of Record
– Boils down to when database update occurs
Notable Duke Award Winners
• Java.com/dukeschoice
• SodBeans – sodbeans.sourceforge.net
• JHome
– control Arduino hardware with Java EE
Content Available
• Content at
https://oracleus.wingateweb.com/scheduler/ev
entcatalog/eventCatalogJavaOne.do
• Audio/slides at parleys
– http://www.parleys.com/#st=4&id=102979
(parleys.com -> Java Space -> JavaOne 2011)
– Currently 59 talks – more being added

JavaOne 2011 Recap

  • 1.
  • 2.
    Agenda • New JavaSE 7 features • Java 8 / 9 feature pipeline • Up and coming Java EE 7 features • Java EE 7 / Glassfsh 4 beta elasticity demo
  • 3.
    New Java 7Features – Project Coin • Project Coin – “Small language changes” – Underscores in Numbers – Strings in Switch – Improved Type Inference for Generic Instance Creation (diamond) – Try-with-resources – Multi-catch with more precise rethrow
  • 4.
    Underscores in Numbers •Our scoring models frequently use large numbers – e.g. 25 million: 25000000 • Hard to read and quickly determine amount • We can now type: 25_000_000 • Much easier on the eyes!
  • 5.
    Strings in Switch •Instead of having if(a.equals(“test”)){ return val;} else if (a.equals(“test2”)) {return val2;} else {return 0;} • We can now have switch(a){ case test: return val; case test2: return val2; default: return 0; }
  • 6.
    Improved Type Inference •Tired of typing Map<String,List<String> > map = new HashMap<String, List<String>>(); • Now you can type Map<String, List<String> > map = new HashMap<>(); instead • Less typing, more readable code
  • 7.
    Improved Type Inference •Compiler will figure out what needs to go on the Right Hand Side • Will work for roughly 90% of cases • Can be used several places – Field / Local Variable initialiser (previously shown) – Assignment Statement perms = new ArrayList<>(); – Method Argument setVal(new ArrayList<>()); – Return Statement (based on return type) return new ArrayList<>();
  • 8.
    Try-With-Resources • Tired ofthis? static String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path)); try { return br.readLine(); } finally { if (br != null) br.close(); } } • Fear no more!
  • 9.
    Try-With-Resources • You cando this now: static String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } } • No more finally block • Less clutter in code
  • 10.
    Try-With-Resources • Works on: –File classes – Stream classes – Network classes – SQL classes – Classes that implements java.lang.Autocloseable – Large number of classes retrofitted for Java 7
  • 11.
    Multi-Catch • Instead ofhaving to catch multiple exceptions and doing the same thing: try{//dostuff } catch(Exception1 e){ log.error(e); } catch(Exception2 e){ log.error(e); } catch(Exception3 e){ log.warn(e); }
  • 12.
    Multi-Catch • Can besimplified to try{//dostuff } catch(Exception1 | Exception2 e){ log.error(e); } catch(Exception3 e){ log.warn(e); } • Improved readability, less typing
  • 13.
    More Precise Rethrow •Allows for more specific types in exception clause of method declaration • Previously, you could only specify one exception type
  • 14.
    More Precise Rethrow •Previously had to throw parent exception • public void rethrowException(String exceptionName) throws Exception { try { if (exceptionName.equals("First")) { throw new FirstException(); } else { throw new SecondException(); } } catch (Exception e) { throw e; } }
  • 15.
    More Precise Rethrow •Can now declare multiple thrown exceptions public void rethrowException(String exceptionName) throws FirstException, SecondException { try { // ... } catch (Exception e) { throw e; } }
  • 16.
    G1 Garbage Collector •“Garbage First” • Introduced in Java 6 release 14 as beta, • Released for production use in Java 7 • Targeted for multi-processor machines with large memories • Decreases the probability of a full GC by focusing first on areas likely to have most garbage
  • 17.
    NIO.2 • New APIsfor filesystem access, scalable asynchronous I/O operations, socket-channel binding and configuration, and multicast datagrams • Able to treat Zip and Jar files as filesystems
  • 18.
    Fork/Join Framework • Divideand conquer style processing: • if (my portion of the work is small enough) – do the work directly • else – split my work into two pieces – invoke the two pieces and wait for the results • Steals work to ensure all processors are busy
  • 19.
    Fork/Join Framework • Workis split among multiple processors / cores on a single computer • Removes the burden of knowing the intricacies of Java’s concurrency libraries
  • 20.
    InvokeDynamic • Adds theinvokedynamic JVM instruction • Allows dynamically typed language designers to optimize their JVM instruction calls and improve dynamic language performance • Not called from Java • Used by JRuby, Jython, others
  • 21.
    Enhanced MBeans • Enhancementsto existing MBeans to report the recent CPU load of the whole system, the CPU load of the JVM process, and to send JMX notifications when GC events occur • Could allow for better troubleshooting capabilities by our support desk staff
  • 22.
    Java 8 Features •Going to two year release cycle – Jigsaw (modularity) – Coarse grain modularity baked in – not OSGi – Smaller footprint, faster startup – Support for native packages – New executable format, faster, can include native libraries – Dependency specs
  • 23.
    Java 8 Features •Closures – Novel approach for Java: structural typing – Single abstract method – SAM – Will work with existing interfaces/classes – New parallel collections – Many cores is the driver for this feature • Nashorn – Javascript running natively in the JVM – Replace Rhino
  • 24.
    Java 9 Proposals •Self-tuning JVM • Improved JNI • Big Data • Type reification (use unknown type information) • Tail calls / continuations (save a program’s state) • Meta-object protocol (code that changes behavior of other code on the fly) • Heterogeneous Compute • GPU support
  • 25.
    Other Java SEnews • Java FX 2.0 released – Will replace Swing – Swing no longer enhanced – Java FX components & engine to be open sourced • Efforts to bridge Java SE / Java ME – Cobining development environments – Combining JCP committees • Project Avatar – easier web development – Unified HTML 5 and JavaScript development on all Java platforms (ME/SE/EE) • Demos of Java FX running on iPad & Android • Java 7 released for Mac OS X
  • 26.
    Java EE 7 •Big initiatives: – The Cloud: Make Java 7 a PaaS cloud provider • Goal is elasticity -> scalability • Automatic Service Level Management • Service endpoints handled through load balancer – URLs, JDBC connections, JMS endpoints, etc. – Multi-Tenancy • Ability to allow multiple customers to use same application instance • Requires only two annotations on stateful classes: – @MultiTenant – @TenantDescriminator • Other initiatives are largely technology updates • Final release scheduled for Q3 2012
  • 27.
    Could we Benefit?Yes! • PaaS approach removes burden of guessing memory configuration for onsite customers • Dynamically spin up more instances during End of Day / Exposure Engine runs • Have one instance that is managed for all customers, all customers upgraded at once
  • 28.
    Java EE 7Demo • Demo • Try it yourself! • http://glassfish.java.net/javaone2011/
  • 29.
    Caching • Big focuson caching – slated for Java EE 7 • Would enable standardized session replication • JSR 107 update (and completion?) • Only need annotations to indicate an object needs to be managed by a cache • CAP Theorem – Pick 2 – Consistence (same data on all nodes) – Availability (every request receives a response) – Partitioning (system operates despite partial loss)
  • 30.
    Data Grids • Standardizationunderway – aiming for EE 8 • Builds on JSR 107 Cache spec • Enables remote code execution - map/reduce • Grouping API allows grouping of like objects • Full & partial data replication allow data scaling • Synchronous & asynchronous transport APIs
  • 31.
    Data Grids • Transactionsnot optional • Querying • Aggregates both storage and processing power of a set of apps • Provides linear scale • Removes bottleneck on database • System of Truth – Cache vs. System of Record – Boils down to when database update occurs
  • 32.
    Notable Duke AwardWinners • Java.com/dukeschoice • SodBeans – sodbeans.sourceforge.net • JHome – control Arduino hardware with Java EE
  • 33.
    Content Available • Contentat https://oracleus.wingateweb.com/scheduler/ev entcatalog/eventCatalogJavaOne.do • Audio/slides at parleys – http://www.parleys.com/#st=4&id=102979 (parleys.com -> Java Space -> JavaOne 2011) – Currently 59 talks – more being added