Ask the Wireless Pro 10-Minute Solution

Writing Java for the Palm
By Daniel Savarese

Java continues to make inroads at all levels of computing. Most recently, Java has returned to its roots and found a home in the small devices for which it was originally designed. Java 2 Micro Edition and its K Virtual Machine (KVM) allow you to write Java applications for handheld devices, including ones that run Palm Computing's Palm OS. You can download an early version of the KVM from java.sun.com/products/kvm.

The KVM includes a reduced set of APIs from the Java 2 platform's java.io, java.lang, java.net, and java.util packages. It also includes a package called com.sun.kjava, which includes user interface and event handling classes for writing applications. At the moment, it only appears to support the Palm OS.

You can write a Palm application by subclassing com.sun.kjava.Spotlet, which provides callbacks for handling events. The KVM manages the event loop and forwards events to the Spotlet, which are handled by methods such as keyDown() and penDown(). A Spotlet first needs to register its event handlers with the register() method before it is able to receive events. This is very different from the traditional AWT/Swing event model. In fact, none of your AWT or Swing code will port to the current incarnation of the KVM. You unregister your event handlers with unregister().

You can compile your KVM apps for the Palm using your regular Java compiler, setting the classpath to use the KVM classes. But you'll need to use the utilities included with the KVM distribution in order to convert your programs into a format you can download to your Palm. These are the palm.database.MakePalmApp program and the palm.database.MakePalmDB program. MakePalmApp will convert a Java program into a Palm .prc file that will automatically load the KVM to run the program when invoked on the Palm. MakePalmDB allows you to add classes to the KVM's class database so that multiple KVM applications may share classes.

The downloadable code demonstrates a simple HelloWorld Spotlet which displays some text and an exit button.

This 10-Minute Solution originally appeared in Ask the Java Pro.

Return to Get Help with Wireless Dev Page

Return to Main Get Help Page

 
Other 10-Minute Solutions
 Anatomy of a WAP Site
 Writing Java for the Palm
 Configuration of IIS for WML MIME Content Types
 Making Dynamic Content Available via ASP
 Building a Web Clipping Application
 Examining the Wireless Telephony Application Interface
 Using XML Stylesheet Language Transformations
 Creating Banner Ads for Wireless Sites
 Taking a Look at the WAP Stack's Security Level
 Create Novel Wireless Features with Refresh and Timer Tag Combinations
 Visually Enhancing Wireless Web Sites
 Creating Controls by Hand in the .NET Compact Framework


Sponsored Links


Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers