JavaEnterprise JavaJava programming for the Palm OS using Jump

Java programming for the Palm OS using Jump

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


If you’re a Java programmer itching to code for a new platform, Jump is for you. Now you can write Java applications for the ubiquitous Palm OS.

Jump gives a Java programmer — without knowing a lick of assembly language — the ability to write applications that will run on any Palm device. If you’re a Java programmer who knows assembly code, you can extend Jump’s functionality even further by using its support for the native interface. Although this cutting-edge technology is still in development, and so is limited in its capabilities, Jump offers enough features to allow you to do some really cool stuff and make you the toast of the programming world.

What is Jump?

Jump is a Java-to-assembly compiler. Jump converts Java class files into 68000 assembly language, producing .asm files. These files are then converted into Pilot-friendly files with Pila (a Pilot assembler) to produce a .prc file that can be loaded into your Palm device. Once compiled into a .prc file, your application will not need a Java Virtual Machine (JVM) in order to run on the Palm OS. And since the Java code is converted to assembly, your programs will be lightning fast.

Installation

Because Jump’s documentation can be confusing, what follows is a detailed, step-by-step breakdown of how to get Jump running on your PC. First, you need to gather the proper materials: Sun’s JDK 1.1, Pila, and Jump itself.

Configure JDK1.1

If you don’t have JDK1.1, download and install it. Make sure to set your PATH and CLASSPATH by opening the file called autoexec.bat in a text editor like Notepad. (Autoexec.bat is in your C drive at root level.) You’ll find a line that reads something like:

SET PATH=C:MSOFFICEOFFICE;%PATH%
.

Add a semicolon and then the path to your BIN directory of JDK — this path should contain no spaces. For example, the new path statement could read:

SET PATH=C:MSOFFICEOFFICE;%PATH%;C:JDK1.1.4BIN
. This will tell your OS where to look for the Java executables.

After that is done, on a new line, add the CLASS PATH to your JDK directory. For example:

SET CLASSPATH=C:JDK1.1.4;./
. This will tell your OS where to look for classes — in the JDK directory and in the current directory, respectively. Save the file and restart your computer.

Next, you have to unzip the classes.zip into the same directory where classes.zip resides (e.g., C:JDK1.1.4lib). Currently, Jump doesn’t know how to look in zipped files. For this operation use a 32-bit unzip program like WinZip (not PKUNZIP).

Install the Palm Compiler, Pila

Pila is part of the Alternative Software Development Kit (ASDK) — a resource that contains many good tools to help a Palm OS software developer. Pila takes assembly files (.asm) and compiles them to Palm executable files (.prc). PRC files can then be installed to your Palm device using the Palm Desktop.

Download the ASDK, including Pila. The “readme” file contains installation information. Just remember to add the ASDK bin directory to your PATH, because Jump needs to run Pila.

Note: You don’t need to get your ROM from your PalmPilot (which would be illegal). The people at 3Com provide one free for developers. Download the Palm OS ROM and place it in the BIN directory of ASDK. You can also download a Palm OS emulator, so you don’t have to test your buggy applications on your Palm device. After restarting your computer, you can make sure everything’s properly installed by typing in

pila
at a DOS prompt. You should see “No input file specified Usage: pila” etc.

Install Jump

You’re almost there. The only thing left is to download and install Jump and write a “Hello World” application.

Download Jump and its accompanying notes. Unzip Jump, using a 32-bit unzip program, into a directory called “Jump.” Unzip palmos.zip into that directory as well, so that the files are in C:/Jump/palmos. Unzip Jump.zip into the C:/Jump directory. Add Jump to your PATH and your CLASSPATH. Restart your computer and test by going to a DOS prompt and typing in:

java Jump
.

You should see copyright info, usage, and options. If Jump fails to start, check Jump’s documentation. (If you have problems, make sure you have the latest Microsoft JVM installed.)

Coding “Hello World”

You’re now ready to start coding. When you program for the Palm OS using Jump, you need to go through a three-step process: write Java code and use the JDK to create .class files; run Jump to convert to assembly, which automatically runs Pila to create .prc files; load the .prc file into the Palm device.

The “Hello World” example that comes with Jump relies on assembly language, but this undermines the beauty of the Java-to-PRC concept. Therefore, I have written an application entirely in Java to enable you to extend your programming prowess to this latest platform.

Using your favorite Java IDE, type the following code:


//import Jump’s Palm OS package
import palmos.*;

class Hi {
static final int idfMain = 1000;

/* All Java applications written for a Palm device must
contain the following line of code:
public static int PilotMain(int cmd, int cmdPBP,
int launchFlags){ }
This method will replace the main method of a normal
Java application and will be the first method called by
the Palm OS. Therefore, you should put your application’s
main code in between these braces.
*/
public static int PilotMain(int cmd, int cmdBPB,
int launchFlags){
//if improperly launched, exit
if (cmd != 0) {
return 0;
}

String message = “Hello Palm OS World!”;
Event e = new Event();
Short err = new Short((short)0);

//Continue until system tells this application to stop
while (e.eType != Event.appStopEvent) {

//palmos package’s version of drawString
Palm.WinDrawChars(message, 20,35,35);
// (String, length, x-coordinate, y-coordinate)

//check for user event
Palm.EvtGetEvent(e, 10);

//if user taps on screen, exit
if(e.eType == Event.penDownEvent){
//exit returning no errors
return 0;
}

}

//exit returning no errors
return 0;

}

}

Save the file as Hi.java in the Hello directory in the Jump folder.

Go to a DOS prompt and go to the C:/Jump/Hello directory. Type in the DOS window:

javac Hi.java
. This will produce a Java class file: Hi.class.

Next, at the DOS prompt type:

java Jump Hi
.

This should create Hi.asm and Hi.prc in the C:/Jump/Hello directory. If there is no .prc file, your PATH is probably not set properly for Pila (see above).

From here, you can use your Palm Desktop to add the Hi.prc file to your Palm device. Don’t forget to back up all of your Palm’s data onto your PC.

Launch the program by tapping on “Hi” in the applications listing. The program will quit when you tap on the screen. Cool, huh?

Troubleshooting

Warning: Don’t forget that your programs are not running within the protective sandbox of a JVM. You always need to code a way to exit your application. Before adding a new application to your Palm device, always HotSync.

If you’ve installed a runaway application on your machine, try the following. Unscrew the top of your Palm stylus and use the secret tool to push through the secret hole on the back of your Palm device — this will cause you to loose all of your data. Don’t say I didn’t tell you to HotSync.

Conclusion

Check the documentation for a list of not yet implemented features. To write more-exciting programs than “Hello World,” become familiar with the palmos package that is provided with Jump. There’s scant documentation, but the methods and data members are pretty self-explanatory so you shouldn’t have any problem figuring out what they do.

In no time, you should be writing applications for the Palm OS that will wow friends and win over enemies.

Resources

Michael Glavin is a freelance Java programmer, and co-founder of Info Lighthouse Corp., the first company to create user-defined downloadable information for Windows CE Mobile Channels.

Java is a trademark of Sun Microsystems, Inc.
Palm OS and 3Com are registered trademarks of 3Com Corp.



Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories