Java on Cell Phones
Almost all cell phones today are programmable in Java (the notable exception being Apple's iPhone). Cell phones have slower processors, and often much less memory that desktop computers. The folks at Sun Microsystems (the creators of Java) created a stripped-down version of Java specifically for use on constrained devices (like cell phones). The desktop version of Java is J2SE (Java 2 Standard Edition). The stripped-down version is called J2ME (Java 2 Micro Edition). Recently, Sun began referring to J2ME as Java ME. Java programs for cell phones is developed using J2ME.
Java syntax is identical for J2SE and J2ME, except that J2ME does not include the new language features introduced in Java 1.5, so J2ME does not include:
- generic types
- autoboxing and auto un-boxing
- enhanced for loops
- enumerated types
- static imports
- varargs
(No big deal for me, I never used those features, because I didn't want to introduce any backward incompatibilities)
So, Java syntax is Java syntax, whether in J2SE or J2ME. The bigger difference is in the Java platform, rather than the Java language. That is, there are:
- far fewer packages in J2ME than J2SE
- all of the J2ME packages contain fewer classes than the corresponding J2SE package
- many of the J2ME classes (that also exist in J2SE) contain fewer methods
Still, to me, programming J2ME feels just like programming J2SE.
J2ME Graphics
Neither the AWT nor Swing are part of J2ME. Instead, J2ME introduces new and somewhat different packages for creating graphical user interfaces. There are 2D and 3D graphics packages for J2ME, and good support for programming games (including sprites and tiled backgrounds).
So, presenting graphics and managing user interactions are a bit different in J2ME, but that shouldn't be too suprising. After all, cell phones have small (sometimes tiny) screens, no mouse, and pretty crummy keyboards. But that's half the fun!
Some Bad Decisions We Don't Have to Live With
Overall, I like J2ME, but I don't like all of it. For example, the Observable class and the Observer interface exist in java.util on J2SE, but are missing in J2ME. The Observer pattern is so fundmentally important in decoupling the domain from the interface that I can't imagine why Sun left them out of J2SE.
No big deal, I simply wrote my own Observable class (including all methods from the J2SE Observable class). I also wrote the Observer interface (it's only one abstract method). So there! Just because J2ME doesn't include something I want from J2SE doesn't mean I can't have it.
I also love writing reusable utility classes. In J2ME I get plenty of opportunities to think about exactly what I want, how it might be made reusable (if possible), and then implement it. Often, I find there is a J2ME capability (e.g. storing data in the cell phone's 'Record Store,' or playing .wav files, or estabilishing Bluetooth connections between two or more phones), and then I develop a class (or classes) to encapsulate that functionality, hide the gory details, and present it through a simple interface. It's fun for me, and of great pedagogical value in class.
If you like programming in Java, you'll be right at home in J2ME, and there are countless opportunities to build useful, reusable classes.