Painting stripes on a cat

This week, Java released the final version of J2SE 1.5, codename “tiger”. With this name, Sun wants to suggest that this version makes Java a real powerful and mighty language.

On the first view on the list of new features introduced, you are impressed by the large set of enhancements and improvements. So let’s have a closer look.

On the first view on the list of new features introduced, you are impressed by the large set of enhancements and improvements. So let’s have a closer look.

The first thing that the list of new features points out in bold
letters is the support for 64 bit processors. Unfortunately, this does not mean that Java overcomes one of the worse mistakes in its language design: The decision to fix all data types to 32 bit. This implies that you have to emulate all 32 bit operations using 64 bit operations, which involves a lot of conditional jumps and masking, especially to provide the same overflow behaviour on basic types. So the performance boost of a 64 bit processor is blown for backwards compatibility.

Now, the language enhancements.

First of all, Java finally includes enumerations. Sun claims, that their enumarations has many advantages over the enum facilities in C, C++, C# and Pascal. If you take C++, than many is 3:

  • Typesafe constants aren’t compiled into clients, so you can add, reorder or even remove constants without the need to recompile clients. (If you remove a constant that a client is using, you’ll fail fast with an informative error message.) That means that to access an enumeration value, you have to resolve its symbol on the owning class. This is a significant performance penalty compared to the usage of an integer constant, not to talk about that it prevents the compiler to do optimizations.
  • You can add arbitrary fields and methods to an enum class.
    Why the hell should I want this? I can put the enumeration in an ordinary class and have the same effect? So why does Java repeats the stupidity in C++ that you have two keywords for the same purpose (class and enum in Java, class and struct in C++).
  • Printed values are informative. (Which would you rather see in a stack trace: “Indigo” or “6?”)
    If you like stoneage technology debugging, and run on the command line, granted. On my (C++) IDE, enum values are replaces by their symbolic names anyway.

Why did Sun implement such dubious features, instead of introducing real powerful subtypes, so that you can not only define enumerations in a typesafe way but also (continous and discontinous) subsets of data types?

Next. Java introduces Generics. These (as the C++ templates) provide you a way to reuse the same code on different data types, especially on basic types. This is most often used for container classes. This feature, too, is very similar to the way it is implemented in C++: Unfortunately, Java imported not only the feature but also the problems from C++; the excessive code bloat: As on C++, the compiler creates a seperate byte code for each instantiation of the generic with a type. Here too, Java reaches the state of the art in language design, but
they miss the possibility to be ahead the other languages: There are research papers which show how to provide generics which avoid code blow without introducing reasonable performance losses

Enhanced for loop. This is one of the worse examples of language design ever seen and at the same time one of the most useless. It is really bad, cause it introduces a handling for a special case into the language: It provides a shorted syntax to iterate with a for
loop through a data collection, and therefore expects a specific interface to be available at the class to iterate on. So this feature mixes up language syntax (the for loop) with an object oriented
implementation scheme (generic functionality via interfaces). It is useless, because a good editor can generate you the loop head to iterate through a collection on a simple key shortcut, which is even more efficient than having a shorter syntax, and, in my opinion, more readable cause it does the iteration in an explicit way. Next will be a language extension to simplify the access of classes implementing the Hashable interface?

There are more language extension: Metadata, Static Import, Autoboxing and varargs. These extensions are not especially bad, but they only provide the possibility to shortcut some expressions in the language. In times of automatic completion in the editor, and if you consider the time needed to write the source code compared to the time to debug and test, these extensions are not really needed, and may, since they make explicit things implicit, decrease the readability of the code.

So when you only consider the language extensions, Sun missed the chance to have a real step forward and make a modern and cutting edge language. Instead of introducing innovating language feature like delegation, run time generics, subtypes and similar features, they painted some stripes on their cat to pretend it is a tiger. Missed the courage?


Comments are closed.

Create a free website or blog at

Up ↑

%d bloggers like this: