Introduction
There are several programming languages compatible with Palm OS, such as C, C++, Pascal, VB, Java, and others. Among these languages, the Java programming language can be highlighted, because it is considered a very powerful language, object oriented, simple, robust and efficient, and has been increasingly used in the development of commercial applications.
The Java applications are interpreted by a virtual machine, the Java Virtual Machine (JVM). The JVM available for Palm OS only supports the Java 2 Micro Edition (J2ME), a reduced version of Java 2 Standard Edition (J2SE). Currently, most PDAs have many resources, both as processing capacity or amount of memory, and thus, could run programs written for J2SE calmly, if there were a J2SE virtual machine for Palm OS.
Thus, in order to remedy the lack of a J2SE JVM for Palm OS, I started the development of a J2SE 5.0 compiler that generates native executable, it means not interpreted and no runtime libraries. The fact that generate native executable can be seen at the same time as an advantage and a disadvantage. The advantage is that the programs can be distributed without the need of a virtual machine, and run with better performance. The disadvantage is that the programs fail to be portable and are slightly larger. However, the portability can be achieved, I explain details ahead.
Case Study
To test the compiler during its development, I have implemented a small game in Java, known as ColorJunction. The objective of the game is to clear the screen erasing the blocks that are united to others of the same color.

Initially, the goal of the compiler was fully compile this game for Palm OS, leaving it fully functional and with the same characteristics of the game running on Windows. The game uses several components of Java, such as:
- Buttons
- Labels
- Dialogs
- Layouts
- Menus
- Graphics
- MouseEvent
The compiler
The compiler aims to transform a Java program into a native program for Palm OS. For this it has as input Java source files (*.java). The process of compilation can be summarized three steps:
- a) Compilation: Read the Java source files and check for compilation errors;
- b) Intermediate code generation of: Generate C++ code from Java source files;
- c) Object code generation: Compile the C++ source code generated into Palm OS native binary files.
Compilation
In this stage are executed the default steps of compilation:
- Lexical analysis;
- Syntactic analysis;
- Semantic analysis (Only for academical purposes).
These steps are responsible for reading the Java program, check for compilation errors, and perform some pre-processing for generation of code in the next step. For lexical and syntactic analysis was used the JavaCC parser generator, well known among Java developers. The nodes of the syntactic tree (AST) were written manually, and semantic analysis runs over the tree using the visitor pattern and adding information to the AST nodes.
Intermediate code generation
The intermediate code is what comes closest to the executable program, however, it passes through more steps to turn the final executable. The generation of code uses the visitor pattern, and generates C++ code as intermediate code. The justification for this choice is that both languages, Java and C + +, are object oriented and the syntax of the two are very similar. This facilitates the transition from Java to C++ and accelerates the development of the compiler that I am implementing because there is no need to worry about in memory addressing and low level instructions.
Meanwhile, Java has a library full of components and data structures to accelerate the development of applications (API). This compiler does not prevent the use of these resources of the Java. However, each API class used in the program to be compiled must be implemented in C++, because the intermediate code will has references to these classes. Currently I have implemented only classes of the API that are needed to compile the game ColorJunction and thus demonstrate a "proof of concept".
At this stage it is possible to make the compiler portable to other platforms, for this, it would be necessary to implement the Java libraries for devices that want to port. For example, to make this compiler generates native executable for Windows Mobile, it would necessary only to implement in C++ the libraries using the resources of this platform, and use the compiler eMbedded Visual C++. This is because the Palm OS native API, used to design a button for example, is not the same in Windows Mobile.
Currently, experienced developers may be asking: "And the Java garbage collector (GC)?" The Java Garbage Collector has not been forgotten. To make the Java programs runs natively on Palm OS was necessary an implementation in C++ simulate the same behavior of the Java GC. This was done by using a well known feature by the C++ developers called "Smart Pointer", which destroys the objects once they cease to be used, in other words, there is no thread tracking the memory in search of garbage as in Java, but the same functionality can be achieved.
Object code generation
This step creates the native executable for Palm OS. Thus, it is necessary to compile the C++ source code generated in the previous step with the used classes of the Java API. This can be done with the C++ compilers available for Palm OS, the best known are:
- Palm OS Developer Suite
- CodeWarrior for Palm OS
- PRC-Tools
The C++ compiler tranforms the C++ source code into a Palm OS native program (. prc). This program can run on any Palm OS compatible PDA, without the need of a virtual machine or runtime libraries.
Conclusion
To implement the game ColorJunction in Java has needed little work and a few lines of source code, because the facilities of the Java language, while natively implement it in C++ for the Palm OS would be much more laborious.
The following images show the result obtained with the compilation of the game. The comparison is made with the game running on a computer with the Windows XP operating system on a Palm T | X with the Palm OS Garnet 5.4.9 operating system. The visual was very similar, and the biggest difference is the size of the text, which in the Palm OS is greater.
The images show that it is entirely possible to run a Java program natively on Palm OS. The challenge is to implement the Java libraries in C++ so that they can be used in the programs. I want to gradually implement the libraries, or as my needs.
Windows XP Palm OS 







Where can I download this compiler?
For now it is not available for download, it is just a proof of concept. In the future the project will be downloadable for interested people that can contribute in the implementation of new libraries, and also use it in their own projects.
Where can I download the game ColorJunction?
The compiled game, the generated C++ source code and the Java source code can be downloaded in the downloads section.
Note: The game has been tested only in a Palm TX, it may not work properly in other Palm devices.
Downloads
- Compiled game ColorJunction (.prc file)
- Java source code
- C++ generated source code generated by this compiler
About the autor:
Júlio Vilmar Gesser holds a BS in Computer Science since 2007. Currently works with Java, compilers and Oracle database in the development of a platform for implementation of J2EE applications.
Has experience in Java, C++, Delphi, Oracle, Palm OS, and is holder of the following certifications:
- SCJP - Sun Certified Programmer for Java 2 Platform, Standard Edition 5.0;
