terence barr - jdk7+8 - 24mai2011
TRANSCRIPT
![Page 1: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/1.jpg)
<Insert Picture Here>
The Future of the Java Platform:Java SE 7 & Java SE 8
Terrence BarrSenior Technologist, Mobile & Embedded Technologies
![Page 2: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/2.jpg)
22
The preceding 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.
![Page 3: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/3.jpg)
33
Project Coin (JSR 334)Small Language Changes
The DaVinci MachineMultiple Languages on the JVMinvokedynamic (JSR 292)
Agenda
Library changesMiscellaneous Updates
JSR 337: Java SE 8 Release Contents
SmallSmall(Language)(Language)
ChangesChangesProject CoinProject Coin
![Page 4: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/4.jpg)
44
Evolving the LanguageFrom “Evolving the Java Language” - JavaOne 2005
• Java language principles– Reading is more important than writing
– 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”
• Beware: Changes have many downstream implications (spec, tests, implementation(s), tools, compatibility, future, ...)
![Page 5: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/5.jpg)
55
Java Standard Edition (Java SE) vs.Java Development Kit (JDK)
• Java SE• Definition of the software
platform• Specification documents• Implementation• Test suite (TCK)
• Implemented by several groups
• Produced in the JCP
• Java Development Kit• Oracle's implementation of
Java SE• Additional features not in
the spec• Tools and documentation• Deployment and
management capabilities• Performance features• Produced in the OpenJDK
project
![Page 6: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/6.jpg)
66
Java SE 7
![Page 7: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/7.jpg)
77
<Insert Picture Here>
Section DividerSmallSmall
(Language)(Language)ChangesChanges
Project CoinProject Coin
![Page 8: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/8.jpg)
88
Project Coin Constraints
• Small language changes• Small in specification, implementation, testing• No new keywords!• Wary of type system changes
• Coordinate with larger language changes– Project Lambda– Modularity
• One language, one javac
![Page 9: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/9.jpg)
99
Better Integer Literal
• Binary literals
• With underscores for clarity
int mask = 0b101010101010;
int mask = 0b1010_1010_1010;long big = 9_223_783_036_967_937L;
![Page 10: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/10.jpg)
1010
String Switch Statement
• Today case label includes integer constants and enum constants
• Strings are constants too (immutable)
![Page 11: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/11.jpg)
1111
Discriminating Strings Today
int 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;
if("February".equals(s))...
![Page 12: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/12.jpg)
1212
Strings in Switchint 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:...
![Page 13: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/13.jpg)
1313
Simplifying Generics
• Pre-genericsList strList = new ArrayList();
![Page 14: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/14.jpg)
1414
Simplifying Generics
• Pre-genericsList strList = new ArrayList();
• With GenericsList<String> strList = new ArrayList<String>();
![Page 15: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/15.jpg)
1515
Simplifying Generics
• Pre-genericsList strList = new ArrayList();
• With GenericsList<String> strList = new ArrayList<String>();List<Map<String, List<String>> strList =
new ArrayList<Map<String, List<String>>();
![Page 16: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/16.jpg)
1616
Diamond Operator
• Pre-genericsList strList = new ArrayList();
• With Generics
• With diamond (<>) compiler infers type
List<String> strList = new ArrayList<String>();List<Map<String, List<String>> strList =
new ArrayList<Map<String, List<String>>();
List<String> strList = new ArrayList<>();List<Map<String, List<String>> strList =
new ArrayList<>();
![Page 17: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/17.jpg)
1717
Simplifying Resource Use
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);
![Page 18: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/18.jpg)
1818
Simplifying Resource Use
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();}
![Page 19: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/19.jpg)
1919
Simplifying Resource Use
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();}
![Page 20: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/20.jpg)
2020
Automatic Resource Management
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);}
![Page 21: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/21.jpg)
2121
Exceptions Galoretry {
...} catch(ClassNotFoundException cnfe) {
doSomething(cnfe);throw cnfe;
} catch(InstantiationException ie) {log(ie);throw ie;
} catch(NoSuchMethodException nsme) {log(nsme);throw nsme;
} catch(InvocationTargetException ite) {log(ite);throw ite;
}
![Page 22: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/22.jpg)
2222
Multi-Catch
try {// Reflective operations calling Class.forName,// Class.newInstance, Class.getMethod,// Method.invoke, etc.
} catch (final ClassCastException e) { doSomething(e); throw e;} catch(final InstantiationException |
NoSuchMethodException |InvocationTargetException e) {
log(e);throw e;
}
![Page 23: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/23.jpg)
2323
More Precise Rethrowtry {
// Reflective operations calling Class.forName,// Class.newInstance, Class.getMethod,// Method.invoke, etc.
} catch(final ReflectiveOperationException e) {//e means any of the subtype thrown from try {}log(e);throw e;
}
ReflectiveOperationException
ClassNotFoundException
InstantiationException
NoSuchMethodException
InvocationTargetException
http://download.java.net/jdk7/docs/api/java/lang/ReflectiveOperationException.html
![Page 24: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/24.jpg)
2424
The DaVinci Machine ProjectJSR 292A multi-language renaissance for the JVMopenjdk.java.net/projects/mlvm
● Dynamic Invocation● InvokeDynamic bytecode
● Method Handles
![Page 25: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/25.jpg)
2525
![Page 26: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/26.jpg)
2626
JVM Architecture
• Stack based • Push operand on to the stack• Instructions operates by popping data off the stack• Pushes result back on the stack
• Data types • Eight primitive types, objects and arrays
• Object model – single inheritance with interfaces• Method resolution
• Receiver and method name• Statically typed for parameters and return types• Dynamic linking + static type checking
• Verified at runtime
![Page 27: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/27.jpg)
2727
JVM Specification
“The Java virtual machine knows nothing about the Java
programming language, only of a particular binary format, the class
file format.”
1.2 The Java Virtual Machine Spec.
![Page 28: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/28.jpg)
2828
Languages Running on the JVM
28
Clojure
Tcl
JavaScript
v-language
CAL
Sather
Funnel
MiniPLAN
Lisp
Scheme
Basic
Logo JHCR
TermWare
Drools
Prolog
LLP
JESS
Eiffel
Smalltalk
C#
G
Groovy
Nice
Anvil
Hojo
Correlate
Ada
Bex Script
Tea
PHP
PhobosSleep
FScript
JudoScript
JRuby
ObjectScript
Jickle
Yoix
Simkin
BeanShell
DawnWebL
iScript
Jython
Pnuts
Yassl
Forth
PiccolaSALSA
Processing
Zigzag
Tiger
Tiger
IconPascal
Oberon
Modula-2
Luck
E
Rexx Scala
![Page 29: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/29.jpg)
2929
Method Calls● Calling a method is cheap (VMs can even inline!)● Selecting the right target method can be expensive
● Static languages do most of their method selection at compile time
● Single-dispatch on receiver type is left for runtime
● Dynamic languages do almost none at compile time● But it would be nice to not have to re-do method selection
for every single invocation
● Each Language has its own ideas about linkage
![Page 30: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/30.jpg)
3030
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
![Page 31: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/31.jpg)
3131
LibraryChanges
![Page 32: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/32.jpg)
3232
New I/O 2 (NIO2) Libraries
• 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
JSR 203
![Page 33: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/33.jpg)
3333
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• Two security models (POSIX, ACL based on NFSv4)• java.nio.file.Filesystem
• interface to a filesystem (FAT, ZFS, Zip archive, network, etc)
• java.nio.file.attribute package• Access to file metadata
![Page 34: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/34.jpg)
3434
Concurrency APIs
• JSR166y• Update to JSR166x which was an update to JSR166
• Adds a lightweight task framework• Also referred to as Fork/Join
• Uses ParallelArray• Greatly simplifies use of many cores/processors for tasks that
can easily be separated
![Page 35: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/35.jpg)
3535
Client Libraries
• Nimbus Look and Feel• Platform APIs for shaped and translucent windows• JLayer (formerly from Swing labs)• Optimized 2D rendering
![Page 36: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/36.jpg)
3636
Nimbus Look and Feel
![Page 37: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/37.jpg)
3737
JLayer componentEasy enrichment for Swing components
![Page 38: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/38.jpg)
3838
JLayer componentThe universal decorator
• Transparent decorator for a Swing component• Controls the painting of its subcomponents• Catches all input and focus events for the whole hierarchy
// wrap your component with JLayerJLayer<JPanel> layer = new JLayer<JPanel>(panel);
// custom ui provides all extra functionalitylayer.setUI(myLayerUI);
// add the layer as usual componentframe.add(layer);
![Page 39: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/39.jpg)
3939
Miscellaneous Updates
• Security• Eliptic curve cryptography• TLS 1.2
• JAXP 1.4.4 (Java API for XML processing)• JAX-WS 2.2 (Java API for XML Web Services)• JAXB 2.2 (Java Architecture for XML Binding)• ClassLoader architecture changes
• close() for URLClassLoader
• Javadoc support for CSS
![Page 40: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/40.jpg)
4040
Platform Support
• Windows (x86)• Linux (x86)
• Redhat• Ubuntu
• Solaris (x86)• New: Apple OSX (x86)
![Page 41: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/41.jpg)
4141
Java SE 8
![Page 42: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/42.jpg)
4242
More Project CoinSmall Language Changes
Project Lambda (JSR 335)Closures and moreBetter support for multi-core processors
Project JigsawModularising the Java Platform
Java SE 8
![Page 43: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/43.jpg)
4343
The Modular Java Platform
• Enables escape from “JAR Hell”– Eliminates class path– Package modules for automatic download & install– Generate native packages – deb, rpm, ips, etc
• Enables significant performance improvements– Incremental download → fast classloading– Optimise module content during installation
• Platform scalability – down to small devices– Well-specified SE subsets can fit into small devices
![Page 44: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/44.jpg)
4444
module-info.java
module com.foo @ 1.0.0 {class com.foo.app.Mainrequires org.bar.lib @ 2.1-alpha;requires edu.baz.util @ 5.2_11;provides com.foo.app.lib @ 1.0.0;
}
Module name
VersionEntry point
Dependency
Virtual module
![Page 45: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/45.jpg)
4545
Project LambdaClosures and moreopenjdk.java.net/projects/lambda
● Lambda expressions● SAM conversion with target typing● Method references● Library enhancements for internal iteration● Default methods for interface evolution
![Page 46: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/46.jpg)
4646
Hypothetical Internal Iteration
• Not inherently serial– students traversal not determined by developer– Looks like a functional language
• Anonymous inner class!
double highestScore = students.filter(new Predicate<Student>() {
public boolean isTrue(Student s) {return s.gradYear == 2010;
}}).map(new Extractor<Student,Double>() {
public Double extract(Student s) {return s.score;
}}).max();
![Page 47: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/47.jpg)
4747
Introducing Lambda Expressions
• Lambda expressions introduced with #– Signal to the JVM to defer execution of the code– Body may be an expression
• Lambda expression are not syntactic sugar for anonymous inner class – Implemented with MethodHandle from JSR-292
double highestScore = students.filter(#{ Student s -> s.gradYear == 2010 }).map(#{ Student s -> s.score }).max();
![Page 48: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/48.jpg)
4848
Roadmaps Are Approved!
• JSRs approved by JCP– JSR 334: Small enhancements to the Java language– JSR 335: Lambda expressions for the Java language– JSR 336: Java SE 7 Release Contents– JSR 337: Java SE 8 Release Contents
• OpenJDK Releases in 2011 & 2012– Committed Features List for 2011:
• openjdk.java.net/projects/jdk7/features
![Page 49: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/49.jpg)
4949
Conclusions
• Java SE 7• Incremental changes• Evolutionary, not revolutionary• Good solid set of features to make developers life easier
• Java SE 8• Major new features: Modularisation and Closures• More smaller features to be defined
• Java Evolution Continues • Grow and adapt to the changing world of IT• Oracle and its partners are committed to a vibrant and
evolving Java ecosystem
![Page 50: Terence Barr - jdk7+8 - 24mai2011](https://reader031.vdocuments.us/reader031/viewer/2022020207/55658e26d8b42a2b6d8b4ee6/html5/thumbnails/50.jpg)
5050