EclipseCon Slides
I came across some great slides today, from a presentation done by Kevin Horowitz at EclipseCon 2006. Kevin is an IBM employee based out of Boca Raton in Florida. The slides are called ‘Taking it on the road – Developer tools for J2ME’
The slides answer six main questions, these are:
What is the J2ME™ environment?
What is the MTJ Project?
What are the plans?
What is out there already?
How is MTJ developing to meet the need?
Where can I get it and how can I help?
Profiles and Configurations
I know I talked about this a bit in a previous post, but I want to look into this a bit more. Profiles are at the core of J2ME – they define which types of device are supported and are built on top of configurations. The main type of configuration for J2ME (along the same lines, cell phones) is CLDC or Connected Limited Device Configuration. CLDC is comprised the small subset of Java classes needed to run the Java virtual machine. Built on top of CLDC is MIDP or Mobile Information Device Profile. There are two widely accepted types of MIDP, version 1.0 and 2.0. In general they provide an API for LCD GUI development, with 2.0 providing a two dimensional gaming API.
An interesting type of profile, designed for embedded (‘headless’) devices, is IMP or Information Module Profile. These devices have no LCD display and limited network connectivity (i.e. Vending machine). IMP is very similar to MIDP, just without the lcdui.* Java package. As all profiles, these are developed through open JSRs, for more information read them.
A feature rich version of CLDC is CDC or Connected Device Configuration. CDC includes most of Java SE, essentially all which is not UI related. The Foundation Profile, Personal Basis Profile and Personal Profile are profiles utilizing a more complete Java SE framework with a subset of AWT support.
Easiest Way to Upload Apps
Uploading games or applications to your device (phone) via USB cable is most likely disabled. This is really annoying since the other option is to download the apps and spend money on data transfer rates. There are ways to make your phone accept apps via USB cable, but these adventures would end up voiding warranty, etc. I found today a convenient and easy method of uploading apps – Bluetooth. This method assumes your laptop or computer has Bluetooth capabilities, but if it does, then do the following:
- Turn Bluetooth on, for your device and laptop. Find your Bluetooth passwords, most likely if you don’t know them, their 1234.
- Set your phone as ‘Discoverable’ by your mobile device. Most likely your phone will on be visible for 60 seconds.
- From your Bluetooth console on your computer, search for available devices. Once found, right click and ‘Pair’ the device. This creates a persistent connection between the two Bluetooth devices. You will be asked for the associated Bluetooth passwords.
- Double click the paired device in your Bluetooth console. Now, drag and drop the JAR file for your application to the ‘OBEX Object Push’ icon. Once transferred your phone will ask you to install the application.
J2ME UI Development
As shown in a previous post, J2ME MID programs must extend the MIDlet class, which controls the lifecycle of the application. This lifecycle is simple in nature, with 4 states. The figure below was taken from J2ME Application Development and shows the lifecycle:

MIDP user interfaces are divided into 2 parts, the high-level and low-level API. The low-level API extends the Canvas class and is mainly used to develop games or any UI were you must draw pixels yourself. A good example of the low-level API in action is the WormGame, packaged in the example application of the Sun Wireless Toolkit. The high-level API is used to create standard lists, textboxes and forms. It’s important to remember when developing with MID, you have no control precisely were widgets will appear on the screen — this power is given to individual devices (i.e. the device manufacturer). The form class has numerous children items, which can be attached, these include textfield, stringitem, etc. The figure below was taken from J2ME Application Development and shows structure of MIDP UI Classes.

All devices have a Display object, which manages the screen on the given device — most application will only have 1 instance of a display. Each new panel to be displayed to the user will be an instance of the Displayable class. Once this instance is populated with the desired UI widgets, the panel is made visible to the user, by calling the setCurrent method of the Display object.
Below is an example of a method to display a welcome message to a user:
Code:
private void displayWelcome() {
try {
form = new Form(applicationTitle);
image = Image.createImage(getClass().getResourceAsStream(
backgroundPath));
titleImage = new ImageItem("", image, ImageItem.LAYOUT_CENTER, "");
form.append(new Spacer(10, 10));
form.append(titleImage);
form.append(new Spacer(20, 20));
form.append(welcomeText);
form.addCommand(exitCmd);
form.addCommand(openWebURL);
form.addCommand(openLocalFeed);
form.setCommandListener(this);
display.setCurrent(form);
} catch (Exception e) {
System.out.println("NewsReader Error: " + e.getMessage());
}
}
General Comments
I’ve been begun playing around with MIDP 2.0 (CLDC 1.0), making some simple and more complicated programs. I’m using the book J2ME In A Nutshell as a reference when I don’t feel like Googling. The Sun website has JavaDocs for all their standardized JSRs. The Sun Wireless Toolkit comes with example applications you can use to better understand the J2ME world. There are three types of XML parsers available, push (SAX), model (DOM) and Pull (Incremental). XML parsing on resource restricted devices is something that literature says to do with care. On the same note, most of these articles, etc. were written in 2002/03 and since then, most mobile devices have probably quadrupled in power and memory. Right now, I’m using MinML, a SAX1 supported XML parser designed for devices with 512kB of RAM.