<< Previous | Next >>

Black Hole

Like a proper tech blog, I haven't posted anything here for a while, people even started complaining that they have had it with the "replacing g_hash_table" post. They have to wait no longer. The silence was partly because I've changed country and job. I am no longer working for Nokia, instead I'm now working for a very small company called Avinity back in Holland. (The other part is just my own laziness, and four weeks without proper internet.)

So no more maemo development, no more c and gtk based stuff. Now my life is in Eclipse and Java code, sprinkled with XML and JavaScript. Auch, but I'm learning.

Java is actually a great language. As a breath of fresh air you can actually just write:

class A {}

And there you have a class. So much easier compared to gobjects. And no more .h files, only object files (classes).

But a large drawback of Java is the fact that public classes must live in their own file, named with the same name as the class. I really don't like that fact, and it is totally unnecessary.

Long time ago

Back at the university, I used to help teach Java to students. That was java 1.1. And a lot has changed since for the better!

Enum is great. Especially the valueOf (here) allows for some great tools for text (or XML) processing. Internally it uses a HashMap that is initialized if you ever use it. (Where is a public repository for the SDK source code so I can link to Enum.java? If it is not in google, I guess it doesn't exist.)

An even bigger change is Generics (here), which are really great! Funny corner cases though, like toArray (from the Collection interface), where you have to give a new array of a specific type as argument, to get back the type you want; straight from the documentation:

String[] y = x.toArray(new String[0]);

I would have expected something more in the lines of:

String[] y = x.toArray<String>();
String[] y = x.toArray(String);

And I've been reading all about the Java Memory Model which was way weaker defined back in the day. (Not that I every noticed back then.)

But now that I am inside this a bit, I really enjoyed Java puzzlers VI. As a little spoiler:

Set<Short> s = new HashSet<Short>();
for (short i = 0; i < 100; i++) {
    s.add(i);
    s.remove(i - 1);
}
System.out.println(s.size());

Why does that print a 100, and not 1, as expected? Answer in 5.6.1, Unary Numeric Promotion, combined with autoboxing and again a Generics corner case: remove allows to remove types other then Short.

A google video about the Java Memory Model, as a last recommendation.

Last modified: 2007-11-19 20:17 GMT