Welcome Java 6

December 13, 2006 - 4 minute read -
scripting_languages

With great fanfare, Java 6 was released to the world. Ok, that was a joke. Sun has the ability to make a major release without any fanfare or hullabaloo. Even Spring had a countdown to their 2.0 release. Oh well.

Java 5 was the really big release and added a lot of new functionality to the core language. Back in October of 2005 I wrote about the new features in Java 5 and did a little bit of prognostication about what might be next for Java. Well, if you look at it, you will soon realize that I was totally wrong. It turned into more of a "what I like in scripting languages that I wish I had in Java". Oh well, I won't quit my day job to try and predict the future. Java 5 added number of new language constructs like Generics, foreach loops, and enums. Java 6 on the other hand doesn't seem to add any new language constructs, but is all about extending the APIs. Where Java 5 almost had a theme of catching up to .NET 2.0, Java 6 seems like a relatively random collection of new things.

Scripting

The Scripting API is one of the bigger and more talked about features. It's definitely the thing that I'm most excited about. We've had Jython for years, Groovy for a while and more recently JRuby which allowed us to use more scripting languages on top of the JVM. Java 6 has really extended support for using these languages on the JVM. Java 6 comes with support for using JavaScript built in. This support is built on top of the Rhino engine originally from Mozilla.

The API seems to offer everything you could want. It allows you to access Java APIs from the scripting language (this is likely implementation dependent, but is done in the built in JavaScript implementation), it allows you to execute the scripting language methods in Java. It even allows you to mold dynamic languages to Java by forcing them into implementing specific interfaces.

As with most Java APIs, it has an extension mechanism to support various languages. There are already implementations of a lot of different languages available for download, so you can start trying your favorite scripting language.

Check out the Java 6 Scripting Guide for some great examples on various pieces of the API.

Database and JDBC 4.0

JDBC 4.0 offers a number of improvements to database access in Java. One of the bigger changes is that Java now comes with a 100% Java database implementation based on Apache Derby. That makes it really easy to get started with an application. You can graduate to a standalone database if you need to later. JDBC 4 makes some improvements to loading of database drivers. It can now use meta-data in a file under META-INF. This means that you don't have to add the old Class.forName("some.db.Driver") in your code. It also means that changing the database is no longer a code-recompile, but just a simple file change (ok, so any serious application would have that string externalized already, but this is a nice thing to standardize).

Check out this article for a good overview of the changes in JDBC 4.0.

Desktop Integration

The Java 6 release has seen a number of improvements in terms of desktop integration so that Java Swing applications won't feel like aliens. They've added support for splash screens so that users can get immediate feedback that your application is starting. They've also added APIs for dealing with Tray Icons and the System Tray which are really handy for a lot of applications.

Monitoring, Instrumentation and Tools Interface

I haven't looked at a lot of the details of what's been added, but it seems like they've put a lot of work into the monitoring and instrumentation side of a running VM. JConsole, a great tool for looking at the various memory areas in your JVM, is now officially supported.

One of the more interesting areas is the ability to transform already loaded Classes. The new classes in java.lang.instrumentation seem like they will be a great boon for a number of different uses. AOP and other Proxy implementations could make use of this. It also seems like this could be a very useful feature in conjunction with the new Scripting support. Languages like Ruby and JavaScript support dynamically adding methods and changing method definitions at runtime. Will this new code allow Script plugin developers to introduce that dynamic functionality into Java?

These are the things that seem most interesting to me. Check out all of the new features in Java 6 for yourself. What are you excited about?