Java SE 7 Released: First Major Update Since December 2006
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:
- Augmenting the switch statement to include Strings.
- Support for binary literals and underscore separators in numbers to aid readability - for example long creditCardNumber = 1234_5678_9012_3456L
- 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.
- 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.
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.
Cameron Purdy | Oracle
Chris Mattmann Apr 15, 2014