Friday, 23 November 2007

What does MIDP, CDC, CLDC etc mean?

What are MIDP, CDC, etc.

Someone posted a question as to what MIDP, CDC, CLDC etc are. At the cost of getting very technical we need elaborate on the java architecture to explain exactly what the differences are.

Java Virtual Machines
Java programs are compiled into a machine independent pseudo-code, that is called bytecode. To run this bytecode you need a so called virtual machine. A virtual machine is a device specific program that takes your bytecode and translates it to instructions the hardware understands. This seperation makes Java portable between operating systems and machine types. Most software developers only encounter the garden variety of Java Virtual Machine (JVM); the type you run on a PC or server. But this is where it gets nastier for mobile developers.

The three musketeers
There are three varieties of JVM:

  1. Regular Java Virual Machine (JVM).Used by Java Enterprise Edition (J2EE), Standard Edition ( J2SE) and Connected Device Configuration (CDC). Allows you to access native code on the machine it is running and does cool stuff like verifying your java bytecode to make sure it doesn't do anything it shouldn't (like format your hard drive). The Connected Device Configuratio (CDC) is intended for high end PDA's/smartphones and contains a fair amount of the standard Java packages.
  2. Kilobyte Virtual Machine (KVM). Intended for small devices with crappy processors and a pathetic amount of memory. To get the virtual machine to run on these devices they decided to rip a lot of stuff out: Most notably lots of useful packages and classes and the bytecode verifier. So programmers have to run a seperate verifier to make applications for this virtual machine. Also they removed the capacity to run native code. Java configurations that run on the KVM are called Connected LIMITED Device Configurations (CLDC). If you want to start programming for CLDC beware; programmers are left with a bare minimum of classes - its java in 1998 all over again.
  3. Card Virtual Machine (Card VM)They ripped so much out of this virtual machine that it can run on a smart card (i.e. in the chip on your credit card or on your SIM card). I've never tried it, and hope i never have to. Supposedly you can do really cool stuff with RSA encryption.

In summary: CDC refers to java that runs on one type of virtual machine (JVM) and CLDC refers java that runs on another type of virtual machine (KVM)

In the embedded and mobile arena they (the organisations that lumbered us with Java Micro Edition - i always envision them as committees sitting around formica tables drinking coffee from plastic cups) decided to make life easier by introducing profiles. A profile is aimed at applications of a specific type. The main profiles are:

  1. Mobile Information Device Profile (MIDP). Translates as Java for cellphones. Manages the lifecycle of programs on the cellphone: installation, security, startup, running, pausing, stopping etc. The main entity in this profile is called a MIDlet. A MIDlet is the thing that you install, run etc. Security is writ big in this profile. Anything remotely interesting (like doing an http request to a server) will result in the cellphone asking the user to verify they want this to happen.
  2. Personal Profile (PP). Translates as Java for Windows Mobile / Palm devices. The main entity in this profile is called an Xlet. An Xlet is the thing that you run etc. Installation and security are not managed much in this profile. You can copy across your class files and run them using the Personal Profile virtual machine.

Wednesday, 14 November 2007

Installing IBM J9 on windows mobile

This article is for people who want to run java software on their windows mobile devices.
Most java applications for mobile devices are so called 'MIDlets'. Midlets can run on most mobile phones and those Windows mobile devices that have java support. Your device does not have java support which is why you are reading this article :-). The IBM J9 WEME java runtime environment works on Windows Mobile 2003 and above. The smartphone version will work on smartphones and PDA's.
The documentation by IBM is aimed at intermediate level software developers and definitely not at beginners or end-users.

The following assumes you want to run MIDlets on your Windows mobile device:

Installation Steps
  1. Download IBM J9 WEME for windows mobile smartphone edition. The page is here:, you need to register and then get the download.
  2. If your are not sure which processor / windows version you have, choose this one: Windows Mobile 5.0 Smartphone Edition, ARM, CLDC 1.1, MIDP 2.0, iMate SP5m, Dopod 577w. Its the last entry in the first table on the page. I tried it succesfully on three devices (HTC/QTec/MDA, HP iPaq and MIO). Once you have registered and got to the download bit of IBM's site you will most likely get this file: ibm-weme-wm50-sp-arm-midp20_6.1.0.20060727-102926.exe. (If there is a newer version on the site, check that the first 27 characters are the same; ibm-weme-wm50-sp-arm-midp20....). The file is about 80MB but don't be alarmed, you only install about 3MB on your device. Why IBM chooses to include 77 MB of stuff you are not interested in is a mystery to me.
  3. Run the file, and let the installer do its stuff. It will install a directory structure on your PC.
  4. Go to the installed directory (on my PC it looks like this: C:\IBM\WEME\runtimes\61\wm50-arm-sp-midp20) and open the zip file: It contains the runtime for windows mobile. Extract the directories bin, lib and examples to somewhere on your PC.
  5. Create a directory J9 on your windows mobile device. It can be on the device itself or on a storage card. Copy the directories bin, lib and examples to the J9 directory on your windows mobile device.
  6. Open file explorer on your device and go to J9/bin. Run the file emulator.exe. If you get an empty screen with 'Install' and 'Action' menu's at the bottom of the screen the installation was succesful.

Now run your first MIDlet

Run emulator.exe on your windows mobile device (see above) and choose 'Install'. Enter a URL (a what? i hear you say) that refers to your MIDlet. The syntax for installing files that are on your windows mobile device is: file://[path to file]. So to install the example MIDlet included in the installation enter file:///Storage Card/J9/examples/GolfScoreTrackerSuite.jad (this assumes you have installed the java runtime in a directory J9 on your storage card).

Thats it for now. A couple of things i will be writing about later on are:

  • How to create shortcuts that run a midlet directly.
  • How to tweak the runtime environment to get rid of the annoying security questions i.e. "XYZ Midlet wants to connect to a website, do you want this to happen?".
  • How to get midlets to access the file system.