in

ASP.NET Weblogs

Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

java 1.5 new features

I'm not generally one to really care what java is doing. Nor do I generally chat about stuff I saw on slashdot. However, after reading over the big-new-features for java 1.5, I just wanted to collect my thoughts in one place.

Here's the new stuff in 1.5, and my take on it.

Generics - Provides compile-time type safety for collections and eliminates the drudgery of casting.

While I think that generics are a great feature, and i'm really looking forward to them in .net v2, I think that this is a feature that is against what java was originally designed/marketed for. My understanding is that java was intended as a KISS, OO language/platform. A generics feature is not keeping it simple. It's a powerful, complex feature, and adding it to java seems more like a compromise by the java developers to stop advanced developers from leaving the platform, against the design goals of the platform.

Enhanced for loop - Eliminates the drudgery and error-proneness of iterators.

this is c++'s/vb's/c#'s foreach. I had an interesting talk with a java developer one time where he said that he was disappointed that the c# developers would tie the language to a class-library feature. He thought that wrapping the IEnumerable interface with a language keyword violates some flexibility design goal in the java language. While I like foreach (auto generated code is always nice), and i never had a problem with it myself, I'm wondering what those kinds of java devs think about the change. Is it a Good Thing now that java does it too?

Autoboxing/unboxing - Eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer).

This is one of those obvious things that i was surprised to find out that java didn't already have.

Typesafe enums - Provides all the well-known benefits of the Typesafe Enum pattern (Effective Java, Item 21) without the verbosity and the error-proneness.

From the sparse article, it looks like java's enums are not only finally there, but are cooler than .net's enums. It looks like the TypeSafe Enums is a shortcut to the "enum class pattern", which, while probably not as performant as a .net enum, is definitely more flexible. In my own .net code, I find myself using the enum class pattern more often than the built-in enum, because it seems I always want to do a bit more than just have a nice name to an int.

Static import - Lets you avoid qualifying static members with class names, without the shortcomings of the Constant Interface antipattern (Effective Java, Item 17).

I'm sorry, but I completely fail to see how this is cool, or even good. What's the big deal about including the classname of the static "constant"? How does it deal with clashing names?

Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it.

Attributes are a great tool, and it's good to see java didn't snub the feature just because .net was first-to-market with the idea. Hopefully it's as extensible as the .net version. Also, on a purely stylistic level... I like the c# syntax better than the java version, but whatever.

Well there you go. If I've made any glaring errors about knowledge of language history, feel free to let me know. But please, keep the anger and/or elitism to a minimum. I'm no java developer, and I only know enough about the little things in it to generally be able to read the code.

Published May 09 2003, 02:38 PM by Andy Smith
Filed under:

Comments

 

Eljay said:

Generics is an important and useful enhancement to the language -- lacking this facility is one of the few things that has kept me away from Java.

Enhanced for loop is a Very Good Thing. For the Java developer who didn't understand why reducing the cyclical complexity is a Good Thing in general -- I'm glad he's not on my team.

Autoboxing/unboxing -- I, too, was flabbergasted that Java didn't already have this facility.

Typesafe enums will be a god send! Java's forthcoming implementation of enums puts all other implementations I've seen to shame.

Static import resolves a "pain in the backside" issue. It does treat static methods as akin to being within a namespace. And you have the same issue about identifier collisions that you do with any other identifier collision when you introduce them into your current namespace -- it's not a big deal (compile time error).

Metadata ... hmm, shades of the C/C++ preprocessor!
August 8, 2003 3:44 PM
 

Mohammad Musleh said:

For more info about Java 1.5, read [GENERICS IN JAVA J2SE 1.5 "Tiger"] pdf file from my site http://mosleh.8k.com/papers.htm.
August 3, 2004 12:13 PM

Leave a Comment

(required)  
(optional)
(required)  
Add