devxlogo

Running J2ME Applications on Palm-powered Devices

Running J2ME Applications on Palm-powered Devices

he Palm Treo platform has gained wide appeal as a communications device for mobile professionals, enjoying several launches in the enterprise over the last few months. With the wide use of Java in business and the capabilities of these devices (including a large screen and keyboard), it only makes sense to explore using the Palm Treo (or related devices including the LifeDrive) to run legacy and new Java MIDP applications. Fortunately, the IBM WebSphere Everyplace Micro Environment for Palm OS Garnet (WEME) provides a MIDP2.0/CLDC 1.1 compliant run-time with support for file and personal information manager (PIM) integration (via JSR-75) as well as Web services development with JSR-172. This article shows you how to migrate your J2ME applications to Palm OS using the WEME, assuming you have some previous experience with Java MIDP development. If you need an introduction to J2ME, see one of the many other articles on J2ME from DevX (a full list can be found here).

Setting Out with the Developer Tools
In order to run J2ME applications, a target device must have a Java runtime consisting of the Java Virtual Machine (JVM) and the libraries that implement the J2ME classes. Java on Palm-powered handhelds is not new: Sun itself released a runtime for Java in the late nineties, which later became the basis for the first J2ME runtime. However, until recently it was difficult to obtain a Java runtime for Palm-powered devices appropriate for end-user application execution?most were fraught with stability, performance, and licensing issues. The IBM WEME changed this, providing a state-of-the-art stable runtime for many Palm-powered devices, including the Treo, LifeDrive, and select Tungsten and Zire devices.

The WEME consists of several components for Palm OS, including:

  • The Java MIDP runtime itself.
  • Localization overlays for the Java MIDP runtime for languages including Spanish, French, Italian, German, and Japanese.
  • An implementation of FileConnect and PIM integration classes specified in JSR-75.
  • An implementation of the Web Services API specified in JSR-172.
  • A preferences panel for Palm OS that lets users specify the degree of access Java applications have to PIM data, and localization overlays for this preferences panel.

You can get these components from one of two sources. If you’re just casually interested in running J2ME applications on your handheld?say, a Verizon Treo 650?you can simply install the handheld-required packages here. Installing these components is easy?simply use the Palm Desktop Install Tool?but time-consuming, because there are so many PRCs; if you miss installing a PRC, you won’t have the functionality you need to run some Java applications. As with all such things, it’s best to read the documentation that accompanies the WEME carefully.

On the other hand, if you’re planning on developing J2ME applications and want to test more thoroughly during development, you should obtain these components directly from IBM here. These components are built as Windows DLLs that work in conjunction with the Palm Simulator, letting you test and run your J2ME applications on your desktop workstation.

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);    tbox.addCommand(exitCommand);    tbox.setCommandListener(this);  }  protected void startApp() {    Display.getDisplay(this).setCurrent(tbox);  }  protected void pauseApp() {}  protected void destroyApp(boolean bool) {}  public void commandAction(Command cmd, Displayable disp) {    if (cmd == exitCommand) {      destroyApp(false);      notifyDestroyed();    }  }}

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.0MIDlet-Vendor: Ray Rischpater KF6GPEMIDlet-Jar-URL: helloworld.jarMicroEdition-Configuration: CLDC-1.0MicroEdition-Profile: MIDP-1.0MIDlet-1: HelloWorld,,HelloWorldMIDlet-Jar-Size: 3201MIDlet-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.

Running Your Application on a Palm-powered Handheld
To run your application on your Palm-powered device, you must deliver the JAD and JAR files to the WEME runtime. There are two ways to do this: via a network connection and by creating a Palm PRC file containing the JAD and JAR files.

My personal preference is to simply use the WEME runtime to download the JAD and JAR files over the network. If you’re installing a third-party application, you can use the device’s built-in Web browser to select a link to the application, or follow these steps:

  • From the application launcher, run the IBM WEME application manager by touching “IBM Java VM.”
  • Press the Install Button.
  • Enter the URL to your jad file in the URL field (for example, http://www.myhost.com/j2me/helloworld.jad). You can use the various shortcuts available from the triangle menu to speed input of common URL components such as the protocol and domain bits of the URL.
  • Touch “OK.”
  • The application manager may prompt you to confirm that you wish to install an application from an untrusted source. Confirm the installation if you feel you’ve entered the URL correctly.
  • The application manager will inform you that the application has been installed successfully.

The other way to install your application is to create a Palm PRC database from the class file and JAD file using the JarToPrc file included with the IBM WEME from IBM. This tool, described in the documentation that accompanies the IBM WEME, takes either the URL to a JAD file on the Internet or can have a JAD file dropped on its main window, and will download the associated JAR file and create a Palm PRC database you can HotSync to your Palm device. (It can also be run from the command line, letting you automate the process of creating a Palm PRC in your build environment.) It’s probably best to create a Palm PRC file for your application if you’re going to be distributing the J2ME file exclusively to Palm-powered handheld users, or if you want to include it as part of a larger installation package.

Regardless of how you install the J2ME applications, you will be able to execute them in two ways: either from the list of applications in the IBM Java VM’s list of applications, or as icons in the Palm application launcher. Simply tapping the icon for the J2ME application in the Palm application launcher will start up the IBM WEME Java virtual machine and seamlessly launch your J2ME application just as if it were a native Palm application.

An Excellent Bridge
The IBM WEME is the most mature and stable Java runtime for Palm Powered devices, and compares favorably with the Java MIDP 2.0 runtimes available on commercially available wireless handsets from Nokia, Motorola, Samsung, and other major vendors. Whether you’re a Java developer looking to bring your enterprise or consumer application to Palm Powered handhelds, or simply an owner of a Palm Powered device looking to run a specific J2ME application, it’s an excellent bridge between Palm OS and Java applications.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist