 |

A Summertime Dive Into J2ME (Part 1)
by bryan morgan
Summer has definitely arrived at my home making it almost a requirement to spend most of your daytime hours in an
air-conditioned building or a large body of water. After Sun's annual
JavaOne conference in early June, it's clear now that Java 2 Micro Edition may be
just as hot in the wireless industry as a July day in Florida. Motorola has been a heavy supporter of J2ME for some time but JavaOne brought
a host of announcements from other industry heavyweights. Among important announcements to software developers were the following:
- Motorola, Nokia, Nextel, Openwave, Siemens, Symbian, and Sun jointly announced the Java Wireless Developer Initiative.
This initiative hopes to act as a clearinghouse for J2ME-related tools, training, events, and developer programs.
- Nokia announced plans to go after the mobile Java market in a big way. This
includes their participation in the Java Wireless Developer initiative, the upcoming release of the J2ME-enabled 9290 Communicator, and the joint
Nokia/Borland JBuilder MobileSet development tool.
- Metrowerks announced new J2ME development tools that will include target
hardware in the box. Initial releases include either the Motorola Accompli A6288 or the IDEN i85s phone.
I've discussed J2ME a bit before (here and here),
so now's as good a time as any to dive in and examine the basics of J2ME development. To get started with J2ME, I'd recommend you first download both the
Java 2 Standard Edition SDK and the Java Wireless Toolkit from Sun Microsystems. Once you
get past the basics and are ready to dive into a real-world project, check out the excellent tools from Borland (coming soon)
and Metrowerks. On a default installation, selecting "Open Project..." from within the Wireless Toolkit
will reveal two demo apps: example and UIDemo. Simply clicking the "Build" button will compile the selected app using
the Java compiler included with the J2SE SDK.
I should mention that the Wireless Toolkit is hiding a few details from you that may
not be readily apparent. J2ME applications undergo a multi-step build process, unlike their standard Java counterparts. Once applications
are compiled (and the appropriate .class files are generated), a process known as preverification
must be completed in order to verify that the compiled application will actually run on a J2ME-certified device. If you weren't
using a nice GUI tool like the Wireless Toolkit, you could preverify your application using the following command-line syntax:
preverify -classpath %CLASSPATH% classname
Following preverification, your application must be wrapped into a Java archive (JAR) file using the jar tool included with the Java 2 SDK.
As I mentioned before, all of these steps are completed for you using the Java 2 Wireless Toolkit; however, individual application descriptor
settings can still be modified within the toolkit by selecting the Project/Settings menu item.
Using the J2ME Wireless Toolkit, let's build a simple J2ME app that will demonstrate the use of the standard J2ME GUI components as well
as the handling of user-generated events such as list or navigation button selections. To begin, I selected the "New Project..." button
(see Figure 1 below), named the new project "J2METester", and gave the class a name of "J2METester". After selecting OK, the Toolkit
created a J2METester directory within the c:\J2MEWTK\apps directory (c:\j2mewtk is the default installation directory) and then created
\bin, \res, and \src subdirectories under J2METester. It then prompted me to place all source files in the \src directory and all resource files (images, icons, etc.) within the \res directory. These two directories are empty to begin with but you'll notice that the toolkit has created two application definition files (J2METester.jad and Manifest.mf) within the \bin subdirectory. Modifying your project settings will cause these files to be updated.

Creating A New Project Using The J2ME Wireless Toolkit
Hopefully, at this point your development environment is set up and ready to go. In Part 2 of this article, we'll
dive right in and build a simple J2ME app that can be deployed to a wide variety of devices.
Bryan Morgan is an independent writer and software developer. He is a columnist with Wireless Internet magazine and was the founder of WirelessDevNet.com in 1999.
|
 |