Java7

advertisement
Busy Java Developer's Guide
to Java7
Ted Neward
Neward & Associates
http://www.tedneward.com | ted@tedneward.com
Credentials
Who is this guy?
– Principal, Architect, Consultant and Mentor
ask me how I can help your project or your team
– Microsoft MVP (F#, C#, Architect)
– JSR 175, 277 Expert Group Member
– Author
Professional F# 2.0 (w/Erickson, et al; Wrox, 2010)
Effective Enterprise Java (Addison-Wesley, 2004)
C# In a Nutshell (w/Drayton, et all; OReilly, 2003)
SSCLI Essentials (w/Stutz, et al; OReilly, 2003)
Server-Based Java Programming (Manning, 2000)
– Blog: http://blogs.tedneward.com
– Papers: http://www.tedneward.com/writings
– Twitter: @tedneward
Objectives
Peer into the crystal ball with me...
– what will be in Java SE 7?
Peer into the Way-Back machine with me...
– what the h*ll took so long?
Peer into the microscope with me...
– what's in this thing?
Caveat

Raise your right hand...
– you swear not to hold me, the conference, Sun, Mark
Reinhold, Alex Miller (from whom much of this info was
mined), my parents, my kids, or your pet tarantula
responsible for anything that's said in the rest of this talk

None of this is guaranteed
– JavaSE7 has a JSR, but last-second changes to JSR are
always possible due to slips, deadlines, ...
– the final word is in the OpenJDK source base, available for
download at http://jdk7.dev.java.net or via the Mercurial
repositories
– we do have the "JDK7 page"...
– but Oracle has said it is now "feature complete"

You have been warned!
Release

And now, a bit of the politics...
– (this is one man's interpretation--not authoritative!)
– most of the "yes" votes in the JCP were "qualified" ones
•in short, most of the JCP members were "disappointed in the
licensing model" but didn't want to hold back Java7
•Oracle basically declared it didn't care; it would ship Java7
regardless of how everybody voted

Is this the end of the Java Community Process?!?
– (would anybody miss it if it were gone?)
Release

JSR 336: Java SE 7 Release Contents
– JSR 203: More NIO ("NIO2")
– JSR 292: Dynamic Language support
– JSR 334: Minor Java language enhancements ("Coin")
– JSR 166y: Collections and concurrency improvements
– Other non-JSR contents:
•JDBC 4.1
•Unicode 6.0
•Translucent and shaped windows
•Swing Nimbus look-and-feel
•Heavyweight/lightweight (GUI) component mixing
•Thread-safe concurrent classloaders
•Elliptic-curve cryptography
List

VM:
– Compressed 64-bit object pointers
– JSR 292: VM support for non-Java languages
(InvokeDynamic)

Lang:
– JSR 334: Small language enhancements (Project Coin)
List

Core:
– Modularization (Project Jigsaw)
– Upgrade class-loader architecture
– Method to close a URLClassLoader
– Unicode 6.0
– Concurrency and collections updates (jsr166y)
– JSR 203: More new I/O APIs for the Java platform (NIO.2)
– SCTP (Stream Control Transmission Protocol)
– SDP (Sockets Direct Protocol)
– Elliptic-curve cryptography (ECC)
List

Client:
– XRender pipeline for Java 2D
– Forward-port 6u10 features
– Create new platform APIs for forward-ported 6u10
features
– Swing updates

EE:
– Update the XML stack
Project Coin Language Changes

Project COIN/JSR 334:
– Binary integral literals and underscores in numeric literals
– Strings in switch
– Improved type inference for generic instance creation
– Multi-catch and more precise rethrow
– try-with-resources statement
Project Coin Language Changes
Binary integral literals and underscores in numeric literals
int thirdBitSet = 0b00000100;
System.out.println(thirdBitSet);
int bigNumber = 1_000_000_000;
System.out.println(bigNumber);
Project Coin Language Changes
Strings in switch
String data = "Howdy, all";
switch (data)
{
case "Howdy, all": System.out.println("It works!");
default: System.out.println("No love");
}
Project Coin Language Changes
Improved type inference
Map<String, List<Integer>> anagrams = new HashMap<>();
Project Coin Language Changes
Multi-catch
try
{
Class c = Example.class;
Field f = c.getDeclaredField("field");
f.set(null, 12);
}
catch (NoSuchFieldException | IllegalAccessException x)
{
x.printStackTrace();
}
Project Coin Language Changes
try-with-resources
try (FileReader fr = new FileReader("App.java");
BufferedReader br = new BufferedReader(fr))
{
String line = null;
while ((line = br.readLine()) != null)
System.out.println(">> " + line);
}
catch (IOException ioEx)
{
ioEx.printStackTrace();
}
JSR 292
JSR 292: "Invokedynamic"
– adds "exotic identifiers"
– more importantly, adds significant VM-level support for
dynamic languages
such as MethodHandles
– WARNING: ignore any literature referring to
InvokeDynamic
this was dropped right before feature-freeze
– WARNING: This will not compile in the latest builds (b141)
not sure if this is being officially dropped or not
(292) Language Changes
"Exotic identifiers"
public class #"Wow, this is different" {
public static void main(String... args) {
int #"This is a local variable" = 12;
System.out.println("Using the local " +
#"This is a local variable");
#"Strange method name"();
}
public static int #"Field #1" = 12;
public static void #"Strange method name" {
System.out.println("Wow...");
}
}
Library
NIO2 (a.k.a. "New New I/O")
– Filesystem API
– Asynchronous I/O API
– WatchService & notifications
Summary
All of this is subject to change!
– ... but probably won't
– still, don't make any life-altering business decisions based
on what you see here; until it ships, it's still malleable
– caveat emptor!
(remember, you swore an oath!)
Questions
Download