Martin @ Blog

software development and life.

Flower

Java 7: new coffee

Last week, I wrote an article for our corporate weblog on the development of Java 7. Since the article was in Dutch, I didn’t post it on my personal blog. But I wanted to post some follow ups, and since it is not very easy to do this on the weblog of Finalist, I decided to translate the article to English and post it here. The translation is done pretty quickly, and thus very likely a bit rough on the edges. I think it is also interesting for non-Dutch readers.

While Java is already in the game for several years, development on new features and improvements for the language are still going on to ensure that Java will be useful in the future. Java 6 has been released more than two years ago, and is slowly becoming old caffee. Most people prefer freshly cooked caffee, and therefore a large number of developers are working on Java 7. The planned release for this newly brewed Java is stated for March 2010. In this article, I will try to provide an overview on the current state of Java 7 and what we can expect in the final release.

Big changes

While it is far from sure which will eventually be part of Java 7, some big changes are defined of which it will be very likely that it will be part of the new release. The most important change is modularization of the JDK. This project, which is currently knonw by the name ‘Project Jigsaw’, aims to provide a more flexible platform and make it easier to distribute Java libraries and applications. In a nutshell, the idea is to extend the Java language with syntax to load modules and define to which module a particular Java class, interface or package belongs. A module is a top level grouping of Java packages on a language level and jar files on a file system level. Java modules can be loaded dynamically – comparable to the way in which OSGi works – and it is possible to define dependencies within modules. Such a dependency can be optional, but it is also possible to prevent other modules to depend upon a given module. A new accessibily level will be added for classes and interfaces which makes it possible to restrict access to a certain class or interface from within the current module. As for now, the keyword which is proposed for this feature is ‘module’, but it will remain possible to call classes and other elements module (so, it will not become a reserved keyword).

The biggest advantages of the modularization will be the reduced amount of dependency problems within libraries, which is currently a major issue in larger Java applications. Project Jigsaw will make it possible to use multiple versions of the same module in a single application. Another advantages is that the JDK will be modularized as well, which makes it possible to reduce the core JDK significantly. Parts of the JDK which are not required for a certain application don’t have to be installed on the system, increasing the speed and reducing the size of the used JDK. Parts of Java which are not used anymore can be depricated more easily (because there are simply not installed anymore) and it will also be easier to add new parts to the JDK.

The modularization of the Java language is a very invasive operation. It requires changes to the syntax of the language, to the core libraries and the Java compiler. Sun Microsystems took the burden upon itself to implement this change, but also stated that it won’t be possible to make other large changes to the language. Victims of this decision are closures and the support for property fields.

Av few other changes which will be very likely to find their way into the JDK 7 is the NIO2 library. NIO2 uses operating system specific code to access files, directories and network resources, which leads to several speed improvements as well as extended capabilities which were not possible without NIO2. One of the notable improvements offered by NIO2 is the possibility of asynchronous access of (metadata) of files, enabling for example to execute code when a file is change without having to poll the file regularly for changes. There will also be changes to the concurrency framework, improvements in the other standard Java libraries and updates to the Swing framework, including the Swing Application framework and a multimedia component which makes it easier to implement video playing capabilities into Java applications.

JVM changes

Another big improvement, which will certainly be part of Java 7, is the so-called ‘invoke dynamic’ feature for the JVM. This is not a change to the Java programming language, but will only be cause changes in the virtual machine. Invoke dynamic will benefit the dynamic languages which are available for the JVM, including JRuby, Jython, Scala, Clojure, Groovy, JavaFX and Fan. A complete explanating of this feature would require a article in itself (apart from the fact I can’t really explain it completely and corretly at this moment). It will make it possible to execute individual methods which don’t necessarily belong to a particular object or class. This is especially relevant for languages which support closures or provide possibilities to add methods to an object after it has been instanciated.

The current development version of the JVM (under the OpenJDK umbrella) already contains a new garbage collector (called Garbage First) which will improve performance in comparison to the current garbage collector (which uses a concurrent mark sweep algorithm), but the most important improvement is that the GC time will be more predictable.

Project Coin

There is a lot to write on the new features which are considered for Java 7 inclusion. However, space is limited here, so I have to wrap it up. There is one item which I will discuss here, and that is Project Coin. Despite the fact that there will not be many large changes to the Java programming language with the Java 7 release, the developers would not want to skip the opportunity to do small languages changes with this new major release. These small language changes are selected using strict criteria: a language change should be relatively easiliy to implement and should give a significant productivity improvement for a Java programmer. An example of such a feature from the past is the ‘foreach’ construction added with Java 5.

Everyone who has a good idea for a small language improvement can submit his proposal to the Project Coin mailinglist. The proposal should be done using a standard proposal form and has to be submitted before the 30th of March 2009. At the moment of this writing, there were 21 proposal submitted. A few of them are seriously considered for implementation (eventually, about five proposals will be part of Java 7):

  • The possibility to use Strings in a switch statement.
  • Improved type inference for Generics, making it possible to write for example the following:
    Map<String , List<String>> myMap = new HashMap<>();.
    It would not be required anymore to repeat the types on the right side statement, which reduces the amount of typing by the programmer.
  • The ‘elvis’ operator and other operators which will make testing for null on variables unnecessairy. Example:

    MyObject myInstance = getMyInstance();
    MyInstance.?toString();
    


    In the current Java, the myInstance.toString() call should be preceded by a checn on null for myInstance in order to avoid a possible NullPointerException.

  • Improved exception handling, including the possibility to handle multiple exceptions within one catch block and safe rethrow of exceptions.

There are more interesting (and not-so-interesting) proposals, and there will definitaly be more new proposals submitted before the deadline will pass, but the list above will give a rough indication of which we can expect in Java 7. For developers who are interested in language development and in which way Java will evolve with the next release, it is certainly worthwhile to check out the Project Coin mailinglist. There are very intersting discussions on the proposed features and the huge implications which can come with (apparently) small changes.

Conclusion

Since it will take at least another year before Java 7 is released, at this moment the rough shape of this upcoming release is slowly revealed. Of course things will change over the next year and the described features are far from there eventual specification, it is safe to conclude that Java 7 will bring nice improvements. Not only for Java developers, but also for developers using alternative languages for the JVM.

The biggest difference compared to previous Java releases is the fact that all development is done in the open. Most of it will be part of the OpenJDK project, and otherwise as part of the Java 7 project. The OpenJDK development release, which already contains some improvements for Java 7, can be downloaded and installed at this very moment. So check it out if you want to try the new features!

I will try to give updates on this blog when there is something interesting to tell on the Java 7 development.

Tags: , , ,

3 Responses to “Java 7: new coffee”

  1. March 28th, 2009 at 12:21

    Wolkje.net Weblog » Blog Archive » JDK 7: new developments says:

    […] Wolkje.net Weblog Writing student and technology fan « Java 7: new coffee […]

  2. April 2nd, 2009 at 22:26

    Alexey says:

    It’s not Elvis operator (Elvis stands for ?: short ternary).

  3. April 21st, 2009 at 6:31

    Interview Questions - RBS | Tech BhaiGiri says: