Java Programming for Palm OS

by Matthew E. Ferris

The landscape for coding Palm OS applications with Java is far from uniform or level. There are several different APIs currently available, each of which gives a different degree of access to the underlying Palm OS API. Perhaps the most well known of these is the one from Sun Microsystems; it is not the only one. This article is not a tutorial on Palm programming with Java -- each solution discussed has its own challenges and quirks -- but, rather, an overview of what tools are available for developers. We will survey the landscape to discover what you can expect when developing Palm OS applications with Java.

The Sun Solution: KVM, Configurations, and Profiles

The KVM is the Kilobyte Virtual Machine, so named because its memory footprint is measured in kilobytes rather than the megabytes that the Java Virtual Machine requires. Because of these stringent memory requirements, the functionality of the KVM is but a subset of the full JVM. You can get a full breakdown of what is and is not supported from the Javasoft site, but notable omissions include reflection, JNI, custom classloaders, as well as an altered security mechanism.

Sun has formulated a game plan of providing both configurations and profiles to meet the needs of device programming. A configuration is an API that is designed to provide a basis for a broad and general category of devices, all sharing similar characteristics, such as limited memory, occasional network connectivity, and low power consumption, probably running on batteries. A configuration defines a "lowest common denominator," in terms of Java libraries, for these devices. As such, it is, by design, general and abstract. There are currently two configurations available for the Java 2 Micro Edition, the CLDC and the CDC. The latter is for devices a bit more powerful than a Palm and is outside of our scope. The former, which stands for Connected Limited Device Configuration, addresses devices like PDAs, two-way pagers, and even cellular phones. The CLDC includes a subset of classes found in the J2SE but with some important differences. For example, the CLDC's java.lang.Object contains no finalize method because of the garbage collection mechanism employed by the VM on small devices. You should remember that a particular class may be present in the API, but particular methods may be absent.. Refer to the documentation to ensure that what you're counting on is actually there.

A surprise for many developers upon beginning to develop with the CLDC is that it does not include support for floating point numbers. This is the default implementation of the KVM; the KVM is written in C and can be ported to many platforms. It lacks floating point support because of the underlying hardware often used for smaller devices, including 8-bit processors that do not support floating point arithmetic.

A profile is specific, concrete, and targets a more specific class of device than a configuration, including user interface and event handling elements, which are not present in the configuration. Currently there are no publicly available profiles for the Palm OS or PDAs.

The Java Community Process has a PDA Profile that has been in progress for some time now. The developer community is still waiting for an early access release of the PDA profile. If traffic on the KVM interest mailing list is any indication, there is some frustration owing to the elusiveness of this early access release.

In the meantime, what can a developer who wants to follow the KVM/Sun solution do? The release of the CLDC included a minimal set of classes which one could think of as an extremely primitive profile for the Palm OS. Be warned that Sun does not endorse using these classes for any commercial development, nor do they plan any updates to this API. But in the absence of the PDA profile, developers are using the classes. Commonly known as Kjava, it includes a number of GUI classes: CheckBox, RadioButton, TextBox, List, etc. In addition to these, there is the Spotlet class, which is used for event handling and includes callbacks to the Palm OS for trapping stylus taps, "hard" key presses, and so on.

A class that uses kjava to display a simple string of text and a Button might look like the following.:

import com.sun.kjava.*;

public class HelloKjava  extends Spotlet
private static Button OKButton;
public static Graphics g = Graphics.getGraphics();

public static void main(String args[])
        HelloKjava hk = new HelloKjava();
public HelloKjava()
{   OKButton = new Button("OK", 84, 140);

public void penDown(int x, int y) {
                 if (OKButton.pressed(x,y)) {
public void drawScreen()
         g.drawString("Hello KJava",20, 10);

There's also a com.sun.kjava.Database class, which is a way to get at the Palm Database (pdb) API. That said, it's extremely primitive and doesn't give full access to everything in a pdb. It only allows the setting and getting of byte arrays; it doesn't allow keyed access other than by record id (an integer). Since the Database only understands byte arrays, to give your data meaning you will need to parse the byte array into meaningful fields.

The Kawt Solution

Kawt is an implementation of the Abstract Window Toolkit for the KVM and is the work of Michael Kroll and Stefan Haustein, both of whom serve on the expert committee for the PDA Profile. Kawt offers an API set more familiar to the Java programmer. For example, it uses the common layout managers (with the exception of GridBag) for placing components on the screen, and then it allows you to set listeners for those components. In other words, the Spotlet mechanism is not involved. Button, Panel, Label, TextField, and other AWT classes are all available. In addition, there are custom classes: FtpShel, TabbedPane, and GifLoader. There is also a class which is an abstraction of a directory and file structure that uses a standard pdb (Palm Database File) to store the data.

Using Kawt, we can say hello in the following way:

import java.awt.*;
import java.awt.event.*;

public class HelloKawt extends Frame implements ActionListener
   Button OKBtn = new Button("OK");
   Label lbl = new Label("Hello Palm");

   public static void main(String args[])
      new HelloKawt();
public HelloKawt()
   this.add("South", OKBtn);
   this.add("Center", lbl);

public void actionPerformed(ActionEvent ae)


While Kawt gives you a better set of classes than kjava, it's actually based on kjava and, therefore, lacks a database class other than kjava's.

This is a problem for serious Palm development. In general, any commercial application will require the data stored on the device to later be synchronized with the desktop. Synchronization of a kjava.Database is problematic because it does not contain the categories that the HotSync software expects, nor does it allow access to the attribute bits that each "native" palm database file contains at the start of each record. Even with the release of the PDA Profile, this is unlikely to be addressed, since the profile targets PDAs in general and not the Palm OS in particular. Nevertheless, the Kawt team has done a great job at making it easy for a neophyte Palm programmer to get started with Java. You can obtain a copy of Kawt at

The IBM Solution

IBM has its own virtual machine, called J9, which in many ways is superior to the KVM. J9 is supported by the Visual Age Micro Edition, an IDE from Object Technology International, a wholly-owned subsidiary of IBM. VAME is a full-featured development tool that gives you full access to the Palm OS API. This comes at some cost, however. While VAME is a Java tool, what it provides is a wrapping of all the native C methods of the Palm API in Java. As such, the method calls in VAME are exactly the same as you would find in C. Therefore, you need to have some understanding of the structure of the Palm API and the arguments to each method. While it is never a bad thing to understand the OS that your application will run under, the need to be familiar with the method signatures of the C API for the Palm is a problem if you are a Java-only developer. This is a drawback that the engineers at OTI seem aware of and are intent on improving.

The following is a simple example written under VAME:


public class HelloJ9 implements OSConsts {

public static void main(String[] args) {

   CharPtr title = new CharPtr("IBM Vame Demo");
   EventType event = new EventType();

   try {
      FormType form = OS.FrmNewForm(0, title, 0, 0, 160, 160, 0, 0, 0, 0);

      OSX.WinDrawChars("Hello J9!", 5, 30);

      while(true) {
         OS.EvtGetEvent( event, -1 );
         if (OS.SysHandleEvent( event )==0) {
            if (event.getEType() == appStopEvent) {

      } finally {

As you can see, it looks a bit different than the previous examples. If you can get past this hurdle, your application performance will be far superior to a KVM-based app. The other distinct advantage of VAME is that since it accesses all of the native API calls, any Palm Database you create can be synchronized with a conduit. The distribution of VAME comes with some nice examples which can get you through some of the difficulties. You can obtain a copy of VAME from


Waba is yet another VM that's the work of several individuals. In style, Waba is somewhat between Kjava and Kawt. While it includes many more GUI components than kjava, it uses coordinate position to place components on the screen, rather than kawt's layout manager approach

The advantage of Waba is speed. It is indeed faster than the KVM. If you think your application may target more than just the Palm OS, Waba also runs under Windows CE. There are extensions to Waba as well, called Superwaba, which provide even more functionality.

Here is the same small app written with Waba. It uses an additional class (not shown) to set the title:

import waba.ui.*;
import waba.fx.*;

public class HelloWaba extends MainWindow

Button closeButton;

public HelloWaba()
   Title title = new Title("HelloWaba");
   title.setRect(0, 0, this.width, 15);

   closeButton = new Button("Close");
   closeButton.setRect(0, this.height - 15, 44, 15);

public void onEvent(Event event)
   if (event.type == ControlEvent.PRESSED)
      if ( == closeButton)

Waba has some nice perks, including; the ability to copy and paste using the clipboard, and access to the System keyboard for easier text entry. In addition there is a class which encapsulates some of the VM details, allowing you to determine which platform that the VM is running under and which ROM version.

Waba is available from SuperWaba is available from


The choice of Java solutions for writing Palm OS applications depends on several factors: whether you are targeting the Palm OS only; whether speed or ease of development is more important. And this is far from the last word on Palm programming with Java. The landscape is bound to change even more in the future.

Matthew E. Ferris is President, Chicagoland Java User Group, a Sun Certified Java Programmer, and a contributing Author for Professional Java Server Programming, Wrox Press.

Return to

Copyright © 2017 O'Reilly Media, Inc.