Want to program Java apps for the Palm? A great way to develop and test them is to set up a Palm environment on Windows. Find out how to use the KVM to run and test these applications.
By Barb Seewer
The search is on for application developers for handheld devices. Given the direction technology is going, the demand will keep growing. If you know Java, you can use the Connected Limited Device Configuration (CLDC) and the K (“kilo”) virtual machine (KVM) to start programming for a Palm OS device. The pieces you need are JDK 1.2.2 or later, the Palm OS Emulator (POSE), and the CLDC implementation that runs on KVM, which is available from Sun.
KVM AND CLDC
KVM is a portable Java machine designed for devices with limited resources, such as pagers, cell phones, and PDAs. It’s part of an implementation of the Java 2 Platform, Micro Edition (J2ME) architecture. J2ME is a specification that defines the minimum set of Java virtual machine features and Java class libraries available.
There are two J2ME configurations currently defined—one for handheld items and one for larger devices. CLDC is the configuration for small devices, such as the Palm, with limited resources (16- or 32-bit processors and less than 512K memory). The other configuration, Connected Device Configuration, or CDC, is used for higher-end devices (32-bit processor and 2 megabytes or more memory).
It’s important to note that the configurations are dependent on profiles. Profiles define a complete set of UI classes. For instance, the PDA profile will define the user interface and data storage APIs for the Palm OS device and other handheld devices. The official PDA profile is currently under review and should be available to the general public sometime this year. In the meantime, Sun has provided UI classes in com.sun.kjava to help you get started. These classes are unsupported and unofficial.
Where to get CLDC
The CLDC for Windows, Solaris, and Palm OS is available for download from the Sun community source page. You must register with Sun and agree to a license agreement in order to download it.
You’ll need to download two parts: j2me_cldc-1_0-winsol.zip and j2me_cldc-1_0-src-palm_overlay.zip. The first part is for the implementation on Win32 and Solaris platforms. The second part is an overlay for the Palm.
Once you’ve downloaded the files, unzip part 1 (j2me_cldc-1_0-winsol.zip) into the desired location. This will create directory j2me_cldc and subdirectories. Next, unzip the second zip file, j2me_cldc-1_0-src-palm_overlay.zip, in the same location. Some files from the first part will be overwritten; either unzip the files in overwrite mode or answer yes when asked if it is okay to overwrite file(s).
To begin the installation process, create a directory named classes under c:\j2me_cldc\tools\palm. Next, you need to compile the classes for the tools. In a DOS window, go to the c:\j2me_cldc\tools\palm directory and invoke the Java compiler as follows:
javac –d classes –classpath classes src\palm\database\*.java
After the compile is complete, copy two files, Wrapper.prc and DefaultTiny.bmp, to the classes directory:
Copy src\palm\database\Wrapper.prc classes\palm\database\Wrapper.prc
Copy ..\..\samples\icons\DefaultTiny.bmp classes\palm\database\DefaultTiny.bmp
The final step is to install KVM on the Palm OS device. You need to load two Palm executable files—c:\j2me_cldc\bin\KVM.prc and c:\j2me_cldc\bin\KVMutil.prc. Put the Palm OS device in the cradle; run the Palm Desktop Install Tool, and then HotSync your Palm with the PC. You will see the two Duke icons (one for each file installed) on the Palm OS device once the install is complete.
Running KVM samples
If you want to run the samples that are included with the download, run this.
You may also want to try running one of the other sample programs that come with the download: Pong, StarCruiser, ThreeDLogo, UITest, dots.DotGame, missles.Missles, and Dragon. (Note: The names are case-sensitive.)
To run the samples on the Palm OS device, install the sample(s) via the Palm Desktop Install Tool and then HotSync your Palm with the PC. If done correctly, you will see the icon for the sample application in the applications list. Tap the sample application icon with the stylus to start it.
Palm OS Emulator (POSE)
POSE is a program that emulates the hardware for most Palm devices. This allows you to develop and run applications for the Palm on Windows (also supported on some UNIX platforms). The benefit is that you can see how your application runs and deals with the limited resources on the Palm OS without actually downloading it onto the device.
You can download POSE from the Palm Web site. Once downloaded, unzip emulator-win.zip in the desired location. All files are placed in a directory named POSE.
Getting a ROM image
Once you’ve unzipped the Emulator files, your next step is to get a ROM image for the Emulator. The ROM image provides all the information for the specific version of the Palm OS you are using. You can get a ROM image directly from your Palm OS device or from the Palm Web site.
To get a ROM image from a Palm OS device, first place the device in its cradle. Install the file ROM Transfer.prc (found in the POSE directory) via the Palm Desktop Install tool. Once this file is HotSync’d to the Palm, exit the HotSync manager. Start emulator.exe (found in the POSE directory) on the PC and select the Download button. At the same time, start the ROM Transfer application on the Palm OS device. On the PC, select the port the cradle is connected to. You can also change the speed of the transfer, but it isn’t necessary. However, if you do change the speed for the transfer, it must match the speed on the Palm OS device. Select Begin on the PC and tap Begin on the Palm. A Progress window will appear on the PC while status updates are given on the Palm OS device. If you receive the error number 773, the COM port is in use by another application and the transfer cannot take place. Verify that you selected the correct port on the download screen and that the HotSync manager is not running.
The advantage of getting ROM images from the Web is that you can test your applications on models of the Palm you don’t have access to, as well as debug versions. In order to get these from the Web, you must be a part of Palm Alliance Program. To join, go to www.palmos.com/alliance/guide/. Once you receive your password, go to www.palmos.com/alliance/resources/ to sign in. Proceed to the ROM Image Clickwrap Area. (You must live in the United States.) There are debug and nondebug ROM images available for download. ROM images are also available under the Development Seeding Area. This requires a signed agreement. (The ROM Image Clickwrap Area does not.)
Running the Emulator for the first time
After you’ve gotten a ROM image, you can start running emulator.exe (found in the POSE directory). Select New and then the ROM image you either uploaded from your Palm or downloaded from the Web. Once you select the ROM file, you’ll see an image on the screen that looks like a Palm OS device. Use the mouse as you would the stylus to navigate around.
Running KVM files on the Emulator
The next step is to install KVM files on the Emulator. Right-click on the emulator, select Install Application/Database, and then add KVM.prc and KVMUtil.prc. The icons will not appear in the Emulator image until the screen is refreshed (right-click on the screen and select Reset). If you want to run one of the sample programs mentioned earlier (Pong, StarCruiser, etc.), install it the same way, refresh the screen to see the icon, and then click the icon to run the application.
When you’re finished, exit the Emulator and save your updated ROM. To exit, right-click on the Emulator and select Exit from the menu. You will be asked if you want to save the changes to the ROM image. If you choose Yes, it’s a good idea to use a different name from the original. This allows you to have a baseline image to start from when trying different applications.
Ready to develop
The development environment is now complete. See CLDCAPI.pdf and KJavaAPI.pdf in c:\j2me_cldc\docs for a listing of the APIs available.