It’s interesting to put Java and .NET side by side. .NET has been described as Microsoft’s attempt to beat Java at its own game, and even as “Java done right”. The designers of the .NET framework and the Common Language Runtimes could look at Java and see what worked and what didn’t, and learn from it.

Something that I think Microsoft got right with .NET is making everything an Object.
It’s like whoever wrote Java thought that object-orientation is good, but didn’t quite dare to go all the way. Or perhaps (and more likely) it’s historical baggage again…. Java’s distinction between primitive types and their Object equivalents, such as int and Integer, is the most obvious example. ints are for simple maths but they cannot be put in Collections – you need an object for that. On the other hand, you cannot just add two Integers. And each boxing/unboxing requires an explicit instantiation of a new object. It all adds up to a whole lot of code that just juggles data types.

That’s being changed in Java 5, but they still appear to be doing some sort of halfway fix. Just reading the Immutable Objects section in this overview of boxing in J2SE 5.0 makes me nervous.

In .NET, on the other hand, the Int32 data type is a full and proper Object. It’s a value type and lives on the stack, but you can still treat it as an object. Boxing is still necessary, but is almost invisible. Very smooth, very elegant.

You could argue that this is just hiding the details from the user, and leads to less efficient code. An invisible boxing requires as much resources as a visible one. But for most apps, differences of 15 ms are really not important, and developer time costs more than processor time.