What's new in Java 5 & 6 (Experience programming coming back)

All -

I've been away from Java for a year in the wonderful world of dynamic languages (ruby and python) but I've had 6+ years of Java coding experience. I've heard that Java 5 & 6 have added some pretty cool features like better for loops, block like structures, etc. I've been told that Java is starting to introduce features which give it a more "flexible" feel, similar to a dynamic language.

Anyway, for someone coming back, can anyone give me a quick list of the new WOW features in Java 5 & 6 that I should be looking to use?

Thanks,

Drew

[587 byte] By [dfg59a] at [2007-11-26 16:07:38]
# 1
Have you been away for so long that you've forgotten about the "new features and enhancements" page in the documentation? http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html http://java.sun.com/javase/6/webnotes/features.html
DrLaszloJamfa at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 2
Right, understood, but often I find it helpful to hear from experienced programmers on what has been most helpful/influential on the the way they code in Java.Or, I could probably learn tons from a sarcastic response.And yes, I already read the changes in each version.
dfg59a at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 3
> Or, I could probably learn tons from a sarcastic> response.Wow, you are new here, aren't you? :)
kevjavaa at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 4
Heh, not new but was a bit hopeful the the forum environment had changed in the last year..oh well, don't feed the trolls, right :)
dfg59a at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 5

> Heh, not new but was a bit hopeful the the forum

> environment had changed in the last year

Maybe if less people came and posted open-ended vague questions that they should have started looking with Google for information about so they could ask more specific questions.....

I mean I don't know. It was a dream I had once. Everyone was very nice here. People used google. Nobody pleaded for "teh codes". People used PreparedStatement. People stopped crossposting. Lazy students stopped lying.

It was amazing.

cotton.ma at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 6

</sarcasm>

A good place to start would be with generics: type-safe collections are generally useful, and generics play well with the enhanced for loop and auto-boxing/unboxing:

static int sum(Collection<Integer> col) {

int sum =0;

for(int n : col) {

sum += n;

}

return sum;

}

DrLaszloJamfa at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 7

> > static int sum(Collection<Integer> col) {

>int sum =0;

> for(int n : col) {

> sum += n;

>return sum;

>

Now that's what I'm talking about. Awesome new syntax there and I find generics very interesting and helpful. Java code reminding me of dynamic code? It can't be...

dfg59a at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 8
> ... It was a dream I had once...Funny. I my dreams I tend to divide my time between the international beach volleyball circuit and espionage.
DrLaszloJamfa at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 9
> Java code reminding me of dynamic code? It can't be...It's still statically typed.
DrLaszloJamfa at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 10
> It's still statically typed.Understood, but the new for syntax, abstracting away the Iterator, and the generics make it feel "cleaner", which is what I was trying to get at.
dfg59a at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 11

My opinion about autoboxing, FWIW, is to avoid it like the plague. I think I have Eclipse set up so that autoboxing gives errors. Otherwise it's a source of unexpected NPEs.

Generics are very influential; foreach is nice, although it's a shame they didn't take it slightly further. Annotations sound great until you look into the details and discover that most of the cool things you were going to do with them don't actually work because you can't use them to insert code autogeneration into javac.

YAT_Archivista at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...
# 12

> I mean I don't know. It was a dream I had once.

> Everyone was very nice here. People used google.

> Nobody pleaded for "teh codes". People used

> PreparedStatement. People stopped crossposting. Lazy

> students stopped lying.

You know you spend too much time in this forum when you start dreaming about it. ;-)

CaptainMorgan08a at 2007-7-8 22:29:56 > top of Java-index,Java Essentials,Java Programming...