BT

Java SE 7 Released: First Major Update Since December 2006

by Charles Humble on Jul 28, 2011 |

Java 7 is generally available from today, the first release of the Java platform since Oracle's acquisition of Sun. The release includes a number of small but welcome changes to the language, incorporates a new file API and the Fork/Join Framework, and improves dynamic language support on the JVM.

For Java 7 language changes have been managed as part of Project Coin (JSR 334), a successor to JSR 201, designed to enhance the Java language with an assortment of small changes to improve productivity. Of particular note is the introduction of "try-with-resources". This is analogous to C#'s using statement but based on a form of the try statement. As a result, whilst the using statement only takes a single resource, try-with-resources is able to handle multiple resources within the scope of a given block.

Two changes have been made to exception handling. First, multiple exception types can be named as being handled by a single catch block. The grammar of a catch clause of a try statement is extended to allow a series of exception types, separated by the "OR" operator symbol, "|", to be used in the declaration of the exception parameter. Second, if an exception parameter is not modified and if it is rethrown inside the catch block, you don't now have to add the exception to the method signature.

Other language changes include:

  1. Augmenting the switch statement to include Strings.
  2. Support for binary literals and underscore separators in numbers to aid readability - for example long creditCardNumber = 1234_5678_9012_3456L
  3. Simplified Varargs method invocation: A compiler change for warnings which are issued when a method combines varargs with non-reifiable array types. The change moves the warning from the call site to the method declaration.
  4. Improved type inference for generic instance creation (< > or diamond): Uses limited type inference for class instance creation so that where parameter types need to be explicitly declared for a constructor, but they could be ascertained from the context, then they can be replaced with an empty set of type parameters. Thus instead of writing:
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    You can write:
    Map<String, List<String>> anagrams = new HashMap<>();

Two major new APIs have been introduced. The first is JSR 203, which adds new APIs for file system access, scalable asynchronous I/O operations, socket-channel binding and configuration, and multicast datagrams. Of particular interest to enterprise developers is the addition of a true asynchronous IO API, important for high-end server applications that need low latency and high throughput across many connections. 203 also finally adds a real file system API to Java, providing support for some OS specific functions. You can, for example, create symbolic links on systems that support them. As such, it can be argued, 203 isn't strictly "write-once-run-anywhere", although it does provide a common API that works on all platforms, as well as the platform specific features.

The second new API is the Fork/Join Framework (part of JSR 166), originally planned for Java 5. This provides a mechanism for developers to decompose problems into tasks that can then be executed in parallel across arbitrary numbers of processor cores.

Elsewhere the platform sees new networking and security features, and expanded support for internationalisation including Unicode 6.0 support.

Finally, Java SE 7 marks the first new bytecode instruction since the beginning of Java, with the InvokeDynamic keyword. InvokeDynamic adds one more invocation mode, and one more linking mode, which can be programmed to user-definable specifications. It is specifically intended to support efficient and flexible execution of method invocations in the absence of static type information, which results in substantial performance improvements for dynamic languages, such as JRuby and Jython, which target the JVM.

Whilst the new features are welcome, in many ways the most important thing about this release is that fact that it has been shipped at all. The long-running disagreement between Sun and the Apache Software Foundation, as well perhaps as leadership and resourcing problems in the final days of Sun, resulted in an unusually long hiatus between releases. As Mark Reinhold remarked in a recent interview

... for both business and political reasons Java kind of went into hibernation mode for a little while there. But we're back, and we're going to ship 7. It's not a revolutionary release, it's an evolutionary release, but it's got some really good stuff in it.

Developers interested in getting started with the Java SE 7 release can leverage the NetBeans IDE 7.0, or IntelliJ IDEA 10.5, which support the latest features of the Java SE 7 platform. Eclipse Indigo also has beta level support for Java 7 available, and Oracle JDeveloper support for JDK 7 is intended for a release later this year.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Awesome! by Cameron Purdy

I was out to Santa Clara a week ago for the JVM language summit, and there's a great deal of excitement around the improvements both in Java 7 and coming in Java 8 and beyond. Oracle has been heavily investing in Java, and the results are just now starting to appear.

BTW - from our benchmarking, Java 7 is showing a 1-6% performance gain vis-a-vis Java 6 on our application server benchmarks with GlassFish.

Peace,

Cameron Purdy | Oracle

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT