views:

198

answers:

4

I was looking through a code tutorial just now, and found something interesting -- the import static feature introduced in JDK 5:

import static org.junit.Assert.assertEquals;

public class AdditionTest {

  private int x = 1;
  private int y = 1;

  @Test public void addition() {
    int z = x + y;
    assertEquals(2, z);
    /* ^ this is a static method, normally called by Assert.assertEquals */
  }

}

It got me wondering, what other features were introduced in JDK 5 and 6 that I don't know about? Are there other new keyword usages like this? Any noteworthy new library classes or functions?

I know that release notes or changelogs are out there, I'm not looking for an "RTFM" answer. I want to know a short list of, in your opinion, what features you think are most game-changing in JDK 5 or 6.

+2  A: 

I'll go ahead and put one out there: Java Web Start applet support.

I like to play around with JOGL, and it's so nice to be able to just use a short jnlp file and not have to write classloaders, code to download native library code, etc. to handle getting JOGL through the browser. (yes I know about JOGL's appletloader thing)

Just one line of my JNLP file loads the JOGL jars, its dependencies (gluegen, nativewindow, newt), and the appropriate native libraries for the current system.

<extension name="JOGL"
    href="http://download.java.net/media/jogl/builds/archive/jsr-231-2.0-beta10/webstart/jogl-all-awt.jnlp" />

The rest of my jnlp file is just for the title of my application and the URL of its JAR file, and that's about it.

By the way, this was introduced in JDK 6u10.

Ricket
+8  A: 

Java 5 had a lot of syntactic changes: the most significant (that I remember) are:

  • Generics
  • Enums
  • For-each loops
  • Auto-boxing and auto-unboxing
  • Covariant returns
  • Variadic functions

(And of course, as noted in the question, static imports and annotations.)

As Zwei's answer mentioned, java.util.concurrent is a major Java 5 feature too, and also, JSR-133 and its memory model changes (that allowed volatile to work in a sane way, so you could implement double-checked locking safely if you wanted to).

Java 6 didn't feature any syntax changes (that I remember); many of its high-impact changes were performance-related. Library-wise, my favourite "new to Java 6" library was the scripting support (javax.script).

Chris Jester-Young
(And varargs...)
Tom Hawtin - tackline
@Annotations too
Tom Hawtin - tackline
@Tom (I'd say @tackline but that wouldn't highlight your name): Yes, how could I forget those. Adding them now. :-)
Chris Jester-Young
+4  A: 

Absolutely, java.util.concurrent!!!

In Java6, ConcurrentSkipListMap was added as a new data structure to this package, and it practically saved our project :)

Enno Shioji
+1 Oh yes, totally agree. I should have added that to my list too. :-)
Chris Jester-Young
+2  A: 

To Chris Jester-Young's list add

  • varargs
  • annotations

But what I'm really looking forward to is functional programming constructs.

Steve B.
+1 I added those to my list too. :-)
Chris Jester-Young
I was going to say you grabbed this from the comments in his answer but looks like you answered just after one and before the other comment was posted, so +1 for you! :)
Ricket