java 7 whats next
TRANSCRIPT
-
8/3/2019 Java 7 Whats Next
1/41
Java 7:
Whats Next?
Alex Miller, BEA Systems
-
8/3/2019 Java 7 Whats Next
2/41
http://tech.puredanger.com/java7
Java 7 Proposals Java Modularity
Superpackages
Java Module System
Java Kernel Swing
Swing App Framework
Bean Binding
Bean Validation
Generics and Types Generic Reification
Type Annotations
Short instance creation
NIO 2
XML Support
Property Support
Closures
invokedynamic
Date & Time API
Units & Quantities
JMX
JMX 2.0 Remote API Connector
Javadoc
-
8/3/2019 Java 7 Whats Next
3/41
http://tech.puredanger.com/java7
Java Modularity Superpackages (JSR 294)
Java Module System (JSR 277)
Java Kernel (no JSR)
-
8/3/2019 Java 7 Whats Next
4/41
http://tech.puredanger.com/java7
Superpackages (JSR 294)src/com/foo/super-package.java:
superpackage com.foo {
member package com.foo.api, com.foo.model,com.foo.util;
export com.foo.api; // Make api package public
}
-
8/3/2019 Java 7 Whats Next
5/41
http://tech.puredanger.com/java7
Java Module System (JSR 277)
-
8/3/2019 Java 7 Whats Next
6/41
http://tech.puredanger.com/java7
Module Definition Metadata/MODULE-INF/METADATA.module:
name=com.wombat.webservice
extensible-metadata=[@Version(1.0)]
members=[com.wombat.webservice.MainApp,
com.wombat.webservice.PrivateClassA,
com.wombat.webservice.PrivateInterfaceB]
imports=[ImportModule(org.foo.xml,@VersionConstraint(1.3.0)),
ImportModule(org.foo.soap,
@VersionConstraint(2.0.0+))]
class-exports=[com.wombat.webservice.MainApp]
-
8/3/2019 Java 7 Whats Next
7/41
http://tech.puredanger.com/java7
Java Kernel Reorganize JRE into kernel + optional
modules, load dynamically
Compete with Flex, Silverlight
-
8/3/2019 Java 7 Whats Next
8/41
http://tech.puredanger.com/java7
Swing Enhancements Swing Application Framework (JSR 296)
Bean Binding Framework (JSR 295)
Bean Validation Framework (JSR 303)
-
8/3/2019 Java 7 Whats Next
9/41
http://tech.puredanger.com/java7
Swing Application Framework
JSR 296
SingleFrame
Appliction
Application
initialize(String[] args)startup()shutdown()
exit()
ApplicationContext
getInstance()
Action
Manager
Resource
Manager
Session
Storage
Task
SwingWorker
Application
ActionMap
Task
MonitorTaskService
*
@Action
Local
Storage
Resource
Map
Resource
Converter
-
8/3/2019 Java 7 Whats Next
10/41
http://tech.puredanger.com/java7
Swing App Framework Demo
-
8/3/2019 Java 7 Whats Next
11/41
http://tech.puredanger.com/java7
Bean Binding Framework
JSR 295 Use a Binding to bind properties of two beans together:Binding binding = new Binding(source, "sourcePath",
target, "targetPath");
binding.bind();
Once bound, changes on either source or target arereflected on the other
Changes go through a BindingConverter and aBindingValidator along the way
The JSP expression language (EL) is used to specifyconversions
-
8/3/2019 Java 7 Whats Next
12/41
http://tech.puredanger.com/java7
Bean Validation
JSR 303 Heres an example from Hibnerate Validator that may be evocative (although I have
no idea what JSR 303 will actually look like:
public class Address {
@NotNullprivate String line1;
private String line2;
private String zip;
private String state;
@Length(max = 20)
@NotNullprivate String country;
@Range(min = -2, max = 50, message = "Floor out of range")
public int floor;
}
-
8/3/2019 Java 7 Whats Next
13/41
http://tech.puredanger.com/java7
Reification of Genericsclass NewCollection extends
Collection { ... }
class NewList extends
NewCollection, List { ... }
-
8/3/2019 Java 7 Whats Next
14/41
http://tech.puredanger.com/java7
Annotations on Java Types
JSR 308 for generic type arguments to parameterized classes:
Map files;
for generic type arguments in a generic method or constructor invocation:o.m("...");
for type parameter bounds and wildcards:class Folder { ... }Collection
-
8/3/2019 Java 7 Whats Next
15/41
http://tech.puredanger.com/java7
Short instance creationpublic static void main(String[] args) {
map := new HashMap();
for(word : args) {
freq := map.get(word);
map.put(word, (freq==null) ? 1 : freq+1);
}
System.out.println(map); }
public static void main(String[] args) {
final map = new HashMap();
for(final word : args) {final freq = map.get(word);
map.put(word, (freq==null) ? 1 : freq+1);
}
System.out.println(map); }
-
8/3/2019 Java 7 Whats Next
16/41
http://tech.puredanger.com/java7
NIO 2 (JSR 203) Major features:
New filesystem interface
Permissions File attributes
Pluggable implementations
Escape to filesystem-specific APIs
API for asynchronous I/O on sockets and files
Completion of socket channels (multicast, options,
etc)
-
8/3/2019 Java 7 Whats Next
17/41
http://tech.puredanger.com/java7
NIO 2 File System API
FileSystems FileSystem
FileReference
FileSystem
Provider
Watchable
WatchServiceCloseable
PathReference
BackingFile
System Path
FileSystem
AttributeViewFile
DiskSpace
AttributeView
Directory
WatchKey
FileId
WatchEvent
Files
-
8/3/2019 Java 7 Whats Next
18/41
http://tech.puredanger.com/java7
NIO 2: Copying a FilePathReference source =
PathReference.from(spongebob.jpg);
PathReference target =
PathReference.from(squarepants.jpg);int flags = CopyFlag.COPY_ATTRIBUTES |
CopyFlag.REPLACE_EXISTING;
source.copyTo(target, flags);
-
8/3/2019 Java 7 Whats Next
19/41
http://tech.puredanger.com/java7
NIO 2 Accessing file permissions
PathReference ref = PathReference.from("foo.txt");
PosixFileAttributeView view =ref.newFileAttributeView(PosixFileAttributeView.class);
PosixFileAttributes attrs = view.readAttributes();
int perms = attrs.getPermissions();
// prints "-rw-r--r-- alice bandits"System.out.format("%s\t%s\t%s%n",
PosixFilePermission.toString(perms), attrs.getOwner(),attrs.getGroup());
// deny others
perms &= ~OTHERS_READ & ~OTHERS_WRITE & ~OTHERS_EXECUTE;
view.updatePermissions(perms);
// change groupUserPrincipal cops = view.lookupPrincipalByGroupName("cops");
view.updateOwners(null, cops);
-
8/3/2019 Java 7 Whats Next
20/41
http://tech.puredanger.com/java7
XML Support: Constructionvoid addReviewer(XML feature,
String reviewer,
String time) {
feature.add(
{ reviewer }
{ time }
);
}
-
8/3/2019 Java 7 Whats Next
21/41
http://tech.puredanger.com/java7
XML Support: Data Coderpackage java.xml;
abstract class DataCoder {
String encode(Object o);
String encode(Object o, String type); T decode(String data, Class c);
T decode(String data, Class c, String type);
boolean supports(Class c);
boolean supports(Class c, String type);
static final DataCoder JAVA;static final DataCoder XSD;
}
-
8/3/2019 Java 7 Whats Next
22/41
http://tech.puredanger.com/java7
XML Support: Datacoder example
void addReviewer(XML feature,
String reviewer,
Timestamp time) {
DataCoder dc = DataCoder.XSD;
feature.add(
{ reviewer }
{ dc.encode(time) }
);}
-
8/3/2019 Java 7 Whats Next
23/41
http://tech.puredanger.com/java7
XML Support: Navigationvoid rejectOpenFeatures(XML featureList) {
List fs = featureList.findAll(feature[state!=approved]);
for(XML f : fs) {
f.get(state).set(rejected);
}
}
-
8/3/2019 Java 7 Whats Next
24/41
http://tech.puredanger.com/java7
Property SupportNew keyword proposal:public class Point {
property double x;
property double y;
}Point p = new Point(1, 2);
System.out.println(p.x + " " + p.y);
New accessor syntax proposal:Point p = new Point();
p->X = 56;
p->Y = 87;int z = p->X;
Also ideas around annotations, code gen, and various other syntaxes
-
8/3/2019 Java 7 Whats Next
25/41
http://tech.puredanger.com/java7
Closures - Abstractionvoid validateWithMax(Stat[] stats, final int max) throws InvalidStatException {
for(Stat stat : stats) {
if(! (stat.value() = min)) {
thrownew InvalidStatException();}
}
}
-
8/3/2019 Java 7 Whats Next
26/41
http://tech.puredanger.com/java7
Closures Inner Classesvoid validateWithMax(Stat[] stats, final int max) throws InvalidStatException {
validate( stats, new Validator() {
public boolean isValid(Stat stat) { return stat.value() = min; }
} ); }
interface Validator { boolean isValid(Stat stat); }
void validate(Stat[] stats, Validator validator) {for(Stat stat : stats) {
if(! validator.isValid(stat)) { throw new InvalidStatException(); }
}
}
-
8/3/2019 Java 7 Whats Next
27/41
http://tech.puredanger.com/java7
Closure Proposals BGGA Gilad Bracha, Neal Gafter, James
Gosling, Peter von der Ahe
CICE Concise Instance Creation Expressions Josh Bloch, Bob Lee, Doug Lea
FCM First Class Methods / JCA Java
Control Abstraction
Stephen Colebourne, Stefan Schulz, Ricky Clarkson
-
8/3/2019 Java 7 Whats Next
28/41
http://tech.puredanger.com/java7
Closures - CICEvoid validateWithMax(Stat[] stats, int max) throws InvalidStatException
{
validate( stats,
Validator(Stat stat) {
return stat.value()
-
8/3/2019 Java 7 Whats Next
29/41
http://tech.puredanger.com/java7
Closures - BGGAvoid validateWithMax(Stat[] stats, int max) throws InvalidStatException {
validate(stats, {Stat stat =>
stat.value() boolean} block) {
for(Stat stat : stats) {
if(! block.invoke(stat)) {
throw new InvalidStatException();
}}
}
-
8/3/2019 Java 7 Whats Next
30/41
http://tech.puredanger.com/java7
Closures - FCM
void validateWithMax(Stat[] stats, final int max) throws InvalidStatException {
validate( stats,
#(boolean(Stat stat)) {
return stat.value()
-
8/3/2019 Java 7 Whats Next
31/41
http://tech.puredanger.com/java7
Closures Control Constructs
File file = ...;
FileReader reader = null;
try {
reader = new FileReader(file);
reader.read
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {// ignore
}
}
-
8/3/2019 Java 7 Whats Next
32/41
http://tech.puredanger.com/java7
Closures - JCA
File file = ...;
usingFileReader(FileReader reader : file) {
reader.read
}
public static void usingFileReader(#(void(FileReader)) block : File file) throwsIOException {
FileReader reader = null;
try {
reader = new FileReader(file);
block.invoke(reader);
} finally {if (reader != null) {
try {
reader.close();
} catch (IOException e) { }
}
}
-
8/3/2019 Java 7 Whats Next
33/41
http://tech.puredanger.com/java7
Closures - BGGA
File file = ...;
usingFileReader(FileReader reader : file) {
reader.read
}
public static
T usingFileReader(File file, {=>T throws E} block) throws E {
FileReader reader = null;
try {
reader = new FileReader(file);
return block.invoke(reader);
} finally {if (reader != null) {
try {
reader.close();
} catch (IOException e) { }
}
}
-
8/3/2019 Java 7 Whats Next
34/41
http://tech.puredanger.com/java7
invokedynamic
-
8/3/2019 Java 7 Whats Next
35/41
http://tech.puredanger.com/java7
Date / Time API
-
8/3/2019 Java 7 Whats Next
36/41
http://tech.puredanger.com/java7
Units and Quantities (JSR 275)Unit
DerivedUnit
ProductUnit
SI
BaseUnit
AlternateUnit TransformedUnit
UnitFormatter
NonSI
Converter
MultiplyConverter AddConverter LogConverter
Dimension
-
8/3/2019 Java 7 Whats Next
37/41
http://tech.puredanger.com/java7
Units Example
// Conversion between units.
KILO(METER).getConverterTo(MILE).convert(10)
6.2137119223733395
// Retrieval of system unit (identifies the measurement type).REVOLUTION.divide(MINUTE).getSystemUnit()
rad/s
// Dimension checking (allows/disallows conversions)
ELECTRON_VOLT.isCompatible(WATT.times(HOUR))
true
// Retrieval of unit dimension (depends upon the current model).ELECTRON_VOLT.getDimension()
[L][M]/[T]
-
8/3/2019 Java 7 Whats Next
38/41
http://tech.puredanger.com/java7
JMX
JMX 2.0 (JSR 255)
Retrofit with generics
Use annotations Make Open MBeans easier to use
Generalize monitors to support non-simpletypes
Cascaded/federated MBean servers
Web services connector (JSR 262)
-
8/3/2019 Java 7 Whats Next
39/41
http://tech.puredanger.com/java7
Javadoc (JSR 260)
New tags for examples, etc
New categorizations of method types,
bean properties, etc
Update the old school look
-
8/3/2019 Java 7 Whats Next
40/41
http://tech.puredanger.com/java7
Miscellaneous
BigDecimal operator supportBigDecimal a =
BigDecimal b =
BigDecimal s = a + b;
Allow String literals in switch case blocksswitch(stooge) {
case Moe:
Comparison support for enums
JACK < QUEEN
-
8/3/2019 Java 7 Whats Next
41/41
http://tech.puredanger.com/java7
Thanks!
My blog: http://tech.puredanger.com
Java 7: http://tech.puredanger.com/java7