What will Java 7 mean for you?
Oracle released Java 7 on July 28, 2011. This is nearly 5 years after the release of Java 6 in December 2006. The release received a lot of bad press, both because it is very meager on features, and because it shipped with a severe bug. Nevertheless, once the most serious bugs have been fixed, you might think about starting to use Java 7. What will this mean?
New language features
Java 7 has a few new language features. Sadly, the most exciting ones have been postponed until Java 8. The following 3 features may show up in your pretty quickly, though:
try ( BufferedReader reader = new BufferedReader(new FileReader(...))) {
String line = reader.readLine();
process(line);
}
This is the try-with-resources or Automatic Resource Management block. If you declare a variable in the try()
statement, Java automatically calls close
on it, like you would in a finally block. This is a small improvement, but nice. You can use try-with-resources on your own object by implementing the new interface java.lang.AutoCloseable
.
try {
clazz.getConstructor(List.class).newInstance(list);
} catch (InstantiationException|IllegalAccessException|InvocationTargetException|NoSuchMethodException e) {
throw new RuntimeException("I really don't care", e);
}
This is the multi-catch statement. It’s useful because of the load of checked exceptions on the sanity of your average Java-developer. It’s nice, but hardly revolutionary. It makes me really wish we got rid of checked exceptions, though.
Map<> ordersPerCustomer = new HashMap\>();
This is type inference for Generic Instance Creation. Saves a few keystrokes without removing any type safety. Again, a nice, but very small improvement.
There are a few more language features, but I expect they will see very little use.
JVM changes
The Java virtual machine gets a new instruction: invokedynamic
. Using invokedynamic, the JVM can invoke a method on an object without having to know on which class or interface the method is declared. If it walks like a duck and talks like a duck…
Invokedynamic will be very helpful for implementors of dynamic languages in the JVM, so it’s great. But the average developer will never encounter it in the wild.
Library changes
Looking at the release notes for Java 7, you may first suspect that there are some interesting library changes here. However, when examining the list more thoroughly, I couldn’t find a single change that I expect I will actually use. The library changes are mostly low-level, behind the scenes fixes of small problems.
Conclusions
So there it is: try-with-resources, multi-catch and a very limited type inference. Hopefully, Java 8 will be released as planned in late 2012 with all the stuff we’ve been waiting for. If so, I expect most shops will skip Java 7. But if Java 8 follows the pattern of delays from Java 7, these slim pickings may be all the crumbs the Java community gets for another five years.
Comments:
[Jarle Hansen] - Aug 8, 2011
Small typo, Java 6 released 2006 (not 2016)
Johannes Brodwall - Aug 15, 2011
I’ve not been able to see that the new file I/O really brings anything to the table for the average developer.
Strings in switches is something that I should’ve included. I’m monumentally unexcited about it myself, but I’ve gotten the impression that there are people who care about it.
Johannes Brodwall - Aug 17, 2011
Wow. That’s actually pretty nice. Here’s a link for others that might be interested:Â http://java.sun.com/developer/technicalArticles/javase/nio/#6
[Trond Arve Wasskog] - Aug 17, 2011
A nice new feature of NIO2 is the Watch Service API.
[SoboLAN] - Aug 15, 2011
You forgot about the possibility of having strings in switches and the new file I/O library.