website stat

Java 6 Mustang - What’s new

I'm yet to see a thorough and detailed page containing the most proeminent news about the release of Java 6 that took place a month ago. So I've decided to dig a little bit, give it a try and check out what's new. Is it worth the hassle of upgrading? Absolutely

Annotations

Actually this is not new. It emerged on Java 5 but it's a very useful and handy syntax sugar. Abstractly they are useless. Let's take a look at some concrete examples Java 6 provides

Web Services

Well, C# started as a copycat of Java so I guess Java is in position to also steal some ideas from Microsoft. This is how you make a method accessible through an Web Service in C#/.NET

C#:
  1. [WebService(Namespace="http://...")]
  2. public class MyWebService {
  3.   [WebMethod(Description="something goes here")]
  4.   public int MyMethod() { ... }
  5. }

Yes, it's that simple. Here's how you can declare a Web Service in Java 6

JAVA:
  1. @WebService
  2. public class MyJavaWebService { ... }

Neat, uh? :-)

JDBC

Java 6 comes shipped with JDBC 4.0 (actually, Java 6 SE comes bundled with a lot of typical components that were not part of SE, namely some of EE) and I guess the major improvement is the SQL query annotations. Here's an example:

JAVA:
  1. @Select("SELECT * FROM users")
  2. public DataSet<users> getAllUsers();

Definitely, a nice replacement for a Template Method on a parent class. It hides a lot of noisy code.

Also, now you don't need to use Reflection to load a driver. That's now handled by the new DriverManager.

Scripting

It's now much easier to use a scripting language like JavaScript inside of Java. More technical, low-level details are available here.

Performance

Garbage Collector has been improved and the overall performance has most definitely increased. I've not run any benchmarks so take this as anecdotal evidence.

What's missing

IMHO, AspectJ should be finally incorporated into J2SE. It's getting mature enough and it's a very interesting tool for the Middleware (ie, it would finally discard the need to have Log4j code in the middle of an object that has nothing to do with logging but should be logged or separate security mechanisms from the logic of the application itself).

Also, they should give a burst to Swing and actually make it fast or using a more subtile solution like SWT, ie, using the native widgets whenever available.


No Responses to “Java 6 Mustang - What’s new”

Comments are closed.