Java 5 Features Redux

Simon Brown has a post about his favorite features in Java 5 and it got me to thinking about this again. It’s a rainy Labor Day and I don’t have a lot to do.

Simon finds many of the new features pretty handy so I thought I’d give my opinions on his observances.

  • For each loop: Simon’s likes this feature because it is a real timesaver given that you can define a loop by typing fewer characters. To me, this is nothing but syntactic sugar. How much time does it save me? Not a second. In Eclipse I just type for, press Ctrl-Space, and select the type of loop I want. Eclipse is happy to write the loop using the pre-1.5 syntax and does it in the blink of an eye.
  • Generics: Like Simon I think this is a great feature but, unlike Simon, I think that the designers made the whole Generics implementation way too complex. As far as I was concerned we only needed Generics to specify the data types being used in Collections. Before Generics I used to define Collections as List /* <SomeObj> */ myList; and with Generics I code it exactly the same without the comment. To me, this is useful and all the complexity is just waste. I coded C++ for many years and in my opinion Java Generics have all the complexity of C++ templates with almost none of the benefits.
  • Autoboxing: Again I think this is just syntactic sugar and for every person that saves a few keystrokes because of this feature there are probably 10 that put a subtle bug in their code because they didn’t get a compiler warning. What we need in Java 6 is a compiler switch to turn Autoboxing off!
  • Concurrency: Yeah baby! To me this is one of the redeeming features of Java 5 and it is a huge one. As we enter an era where most systems will have at least 2 CPU cores (and probably many more in a few years) it becomes increasingly important for programmers to have a solid base for concurrent programs. One of the problems with the Java API is that it makes multi-threaded programming look easy. It isn’t and it is very easy to introduce hard to find bugs in a concurrent program. I’m not just talking about novices either. Look at the concurrency related bugs that have surfaced in the NIO SelectionKey class and I’ll bet the folks who wrote that are no slouches. Of course most of the Java 5 concurrency tools have been available for a long time from Doug Lea but having them built in to the language may encourage more people to learn how to use them.

So, do I like Java 5? Sure, it’s OK but I honestly don’t use most of the features. Maybe that will change over time.

Oh, and Simon – you left out what I believe will become the most used Java 5 feature – Annotations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: