RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Running J2ME Applications on Palm-powered Devices : Page 2

Learn how to migrate your Enterprise J2ME applications to Palm-Powered devices including the Treo 650 and Palm LifeDrive.

Looking Inside a Simple Application
With the wide deployment of J2ME, there are many good resources for learning about J2ME development, and if you're new to Java and want to write your own applications, I suggest you consult one of them listed in the Related Resources section at the end of this article.

There are, however, a few basic concepts you should understand, even if your interest in the IBM WEME is simply to run other people's J2ME applications. First, J2ME applications are distributed as two pieces: a Java archive (ending in .jar) which contains the actual bytecodes for the Java application, and a description of the Java application, contained within a file ending in .jad. This split between your application's implementation and description makes it easy for J2ME-enabled devices to discover what capabilities are required to execute an application without using precious network resources, or cause a device to run out of room downloading a J2ME application which wouldn't fit on a device because it's too big.

All J2ME applications implement the MIDLet class, as you can see in the following listing:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet implements CommandListener {
  private Command exitCommand;
  private TextBox tbox;

  public HelloWorld() {
    exitCommand = new Command("Bye", Command.EXIT, 1);
    tbox = new TextBox("Hello World", "Hello World!", 25, 0);

  protected void startApp() {

  protected void pauseApp() {}
  protected void destroyApp(boolean bool) {}

  public void commandAction(Command cmd, Displayable disp) {
    if (cmd == exitCommand) {
This version of Hello World contains a single class, HelloWorld, which uses a J2ME TextBox to display the message "Hello World!" on a handheld. This class has five methods:
  • The application's constructor is named after the class itself. The J2ME runtime invokes it as it creates an instance of your application, and your constructor should do all pre-execution object creation and setup necessary for your application to launch.
  • The J2ME runtime invokes your application's startApp method to launch your application.
  • The J2ME runtime requires that you provide the pauseApp method, which the runtime will invoke if it needs to pause your application (say, to permit the user to answer an incoming phone call.)
  • The J2ME runtime requires that you provide the destroyApp method, which the runtime invokes when your application exits.
  • The commandAction method, required because the HelloWorld class implements the CommandListener interface. The commandAction method simply examines the incoming command and closes the application.
A JAD file describing the HelloWorld application must accompany the application. This file is simply a carriage-return delimited set of key/value pairs describing the application:

MIDlet-Version: 1.0.0
MIDlet-Vendor: Ray Rischpater KF6GPE
MIDlet-Jar-URL: helloworld.jar
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-1.0
MIDlet-1: HelloWorld,,HelloWorld
MIDlet-Jar-Size: 3201
MIDlet-Name: HelloWorld
As you can see from the listing, some of the fields describe the capabilities required by the application of the executing device, while others describe the application itself:
  • The MIDlet-Version field indicates the version of your application.
  • The MIDlet-Vendor field indicates the name of the application's author.
  • The MIDlet-Jar-URL field indicates the URL (fully qualified or partial) to the JAR file containing the application.
  • The MicroEdition-Configuration field indicates the version number of the J2ME configuration required by the application (the classes associated with the J2ME runtime).
  • The MicroEdition-Profile field indicates the version number of the J2ME virtual machine required by the application.
  • The MIDlet-n field indicates the class file and class to instantiate when the application is launched. It can also contain the name of an arbitrary icon to show the user in the application manager.
  • The MIDlet-Jar-Size indicates the size of the JAR file containing the application in bytes.
  • The MIDlet-Name field contains the user-readable name of the application.
Unless you're building your J2ME application from scratch, you will need to choose which development environment you will use to create your JAD file for your application. You should base this decision on the properties that you enter and the type of JAR file that will result when you build your application.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date