Thursday, February 25, 2010

Back to Java

After writing a small Pygame game for my son, I was left disappointed with the deployment possibilities. I had to deploy python+pygame on any computer before we could play the game.
I was left thinking that web deployment would be nice. So I thought of Flash and HTML5. That's the natural cool and modern solutions.
But I don't have that many machines that can actually handle those. My older Blackberry in particular doesn't. I thought I might want to target Android too.
Then I had a shock. I could write it in Java! Something I thought was a bit passe actually.
But after a quick check the Blackberry 8700 has MIDP 2.0 which is pretty ok for 2D games. And I found a couple libraries to run MIDP code on J2SE and even Android. So turning the MIDlet into an applet that can run in a browser seems easy enough and I even get Android for free.
Better yet, I can get old BlackBerries with a broken radio from work, so I could actually give those to my kids, nephews and friends... I guess old-fashioned software has its advantages ;-)

I have now started to look into Java Micro Edition and some things are pretty nice:
  • simple APIs
  • the Java Wireless Toolkit from Sun runs fine on my EEE PC on Linux
  • the phone emulator even works fine on my EEE PC
There are a few things that are really odd.
First, Netbeans requires an emulator and does not provide one through a simple emulation of the libraries in Java. For some reason it does not automatically offer to get the Java Wireless Toolkit for you. I would really have expected that this would have been made into a Netbeans plugin.

Second, the J2ME classes have not been added to the Standard Edition. This seems crazy to me.
It would probably not have made SE noticeably bigger and the cost of implementation would have been really low. That would also have provided a reference implementation for all ME classes. Also, it would mean that J2ME is a plain and simple subset of SE. Defining related libraries in terms of subset or superset is really the best way as it's simple to understand provides the best interoperability. It would make development of ME apps simpler : no emulation, you just run your program with SE.

Another issue is that most handsets have partial or buggy implementations and only have some of the JSRs or only this or that version. There are databases that describe the various handsets and what is available but you have to pay for most of the information. This really goes against "run anywhere" part of the Java promise. The only good point is that if you have the device you can easily go to a version information screen that lists the available APIs, which is probably ok for a hobbyist.

Another platform that does Java is the kindle. My wife has one and I really like the screen so I find myself thinking of ways to deal with the slow and monochrome display.