First published by IBM developerWorks at http://www.ibm.com/developerWorks. Visit ibm.com/ developerWorks for more tutorials on open standard technologies , IBM products, and more.
Cross-platform programming with Java technology and the IBM Web Services Toolkit for Mobile
Make sure your Java apps run on as many platforms as possible without modification
Peter Haggar (email@example.com), Senior Software Engineer, IBM
18 Feb 2003
When you’re writing a Java application for the server or desktop, you can be reasonably sure that
the Java platform will fulfill its “Write Once, Run Anywhere” promise. But when you’re dealing with
code that will run under the J2ME Mobile Information Device Profile (MIDP), things get a little trickier.
If you’ve downloaded the Web Services Tool Kit for Mobile Devices (WSTKMD) and are eager to
write mobile Java Web services, you’ll need to check out the warnings in this article(see Resources).
Peter Haggar describes some of the pitfalls he encountered in making sure that the WSTKMD’s
sample applications ran on all the target platforms.
The IBM Web Services Tool Kit for Mobile Devices (see the Resources section below for a link)
supports the Java programming language on BlackBerry ™ devices, PocketPC™, and
Palm OS4™ mobile devices; on the Palm OS4 platform, it also supports the C programming
language. The Java language is touted as a cross-platform environment, with which code can be
written once and run on a variety of operating systems without modification. While this is largely
true in desktop and server environments, writing Java applications for mobile devices utilizing MIDP
(the Mobile Information Device Profile) is not as straightforward.
The sample Java applications that ship with the toolkit run unmodified on all supported devices.
However, there the devices have different user interfaces (UIs), and the apps thus have different
UIs on the different devices. We took great care to ensure that each Java application would run
unmodified on each supported device. This proved more difficult than we first imagined, due to the
lack of consistency among the various MIDP implementations, along with differences in the various
devices’ user interfaces.
In this article, I’ll outline the issues that you need to consider, and the programming constructs and
style you should use, to ensure that your Java programs can run, unmodified, on each device
supported by the IBM Web Services Tool Kit for Mobile Devices.
The MIDP programming environment offers a very limited amount of functionality to the programmer.
In addition, MIDP has been implemented differently on different devices. Therefore, you cannot
program to MIDP and assume that your application will look and behave consistently in varying
environments. For example, the MIDP GUI library does not support a single class for buttons. You
can draw buttons natively, or you can rely on each individual MIDP implementation for each device to
provide buttons for your menu items.
When creating the sample applications for the Web Services Tool Kit for Mobile Devices, we avoided
certain user interface classes in order to ensure that each program would run on each device. When
you are preparing your own code for this purpose, you need to accept the fact that your application
will have a different interface on different devices. Furthermore, the user of the application will
interact with it differently depending on the device on which the program is run.