I've installed LeJOS. Cool stuff - the first time I can actually use Java for something. The only thing that doesn't work on OS X 10.2 is direct communication between the host computer (OS X machine) and the target computer (RCX brick) via the IR tower - so you can't build distributed applications between these two systems. The reason appears to be an incompatibility with the JNI (Java Native Interface) used to integrate the communication routines (written in C) into the Java classes. Otherwise everything works quite well - even exotic sensors (I have the IR proximity sensor and the ultrasonic distance sensor from HiTechnicStuff) work flawlessly. And the VM is small enough at 16 KB that you still have plenty of space for your own Java programs.

There's also an emulator included with which you can test your RCX programs on the host computer. Very practical for debugging - the RCX is a bit too primitive for that anyway. Even though the emulator is very primitive - it just spits out traces of what happened. No graphical display, no sensor simulation, etc. But still better than nothing.

Important constraints of the Java VM:

  • no garbage collection. So you have to make sure you don't constantly instantiate new objects and that memory is allocated statically if possible - otherwise the RCX will eventually run out of memory (does that sound familiar from the Mars robots?)
  • some language restrictions like no switch, no long data types, arrays with a maximum of 511 elements, no interface safety (you can put objects into wrong slots without getting exceptions - some of Java's type safety is lost)
  • no introspection (so you can't look at your own classes). In a robot that's probably acceptable anyway - it should look at the world, not at itself
  • the entire JDK isn't there - logically, the whole thing is an extremely restricted environment. The RCX only has 32K of memory...
  • a very primitive toolchain - everything command line and so on. Maybe you could get a graphical Java environment to integrate everything correctly, because basically LeJOS uses the normal Java compiler. Something like Eclipse would probably be overkill in my opinion for programming a small RCX

I think I'll refresh my Java skills a bit during my pre-Christmas vacation and see if I can finally get my ideal freely moving robot working - one that doesn't bump into everything and at least builds up a rudimentary memory of its surroundings. After all, I have two RCX bricks - maybe I can finally realize my envisioned Lego truck with two brains (one for locomotion and basic collision avoidance sensing and one for spatial orientation). And as usual with Lego planning, you first realize that you simply don't have enough Lego bricks. I think that could go down in history as Hugo's first law: You never have enough Lego bricks.