Java Reference
In-Depth Information
CHAPTER 2
■ ■ ■
Building MIDlets
M IDP applications are piquantly called MIDlets, a continuation of the naming theme begun
by applets and servlets. Writing MIDlets is relatively easy for a moderately experienced Java
programmer. After all, the programming language is still Java. Furthermore, many of the
fundamental APIs from java.lang and java.io are basically the same in the MIDP as they are
in J2SE. Learning the new APIs (in the javax.microedition hierarchy) is not terribly difficult, as
you'll see in the remainder of this topic.
The actual development process, however, is a little more complicated for MIDlets than it
is for J2SE applications. Beyond a basic compile-and-run cycle, MIDlets require some additional
tweaking and packaging. The complete build cycle looks like this: Edit Source Code
Compile
Preverify
Test or Deploy.
To show how things work, and to give you a taste of MIDlet development, this chapter is
dedicated to building and running a simple MIDlet. In later chapters, we'll delve into the details
of the MIDP APIs. In this chapter, you'll get a feel for the big picture of MIDlet development.
Package
Tooling Up
MIDlets are developed on regular desktop computers, although the MIDlet itself is designed to
run on a small device. To develop MIDlets, you'll need some kind of development kit, either
from Sun or another vendor. Remember, MIDP is only a specification; vendors are free to
develop their own implementations.
The world is full of MIDlet development tools if you know where to look. Furthermore,
many of these tools are freely available.
The bare bones set of tools is Sun's MIDP reference implementation. This includes the
preverify tool (more on this later), a MIDP device emulator, source code, and documentation.
You can download the MIDP reference implementation by following the links from http://
java.sun.com/products/midp/ . However, we don't recommend using the reference implemen-
tation unless you really enjoy being in the middle of the gritty details of building and packaging
MIDlets. (You should also investigate the reference implementation if you are interested in
porting the MIDP runtime to a new device or platform.)
A much better tool for beginners is Sun's J2ME Wireless Toolkit, available from http://
java.sun.com/products/j2mewtoolkit/ . The J2ME Wireless Toolkit (or J2MEWTK, as it's affec-
tionately known) includes a GUI tool that automates some of the tedious details of building
and packaging MIDlets, providing a simple path from source code to running MIDlets. At the
same time, the J2ME Wireless Toolkit is a relatively lightweight solution, almost a miniature
IDE, not something that will choke your machine.
11
Search WWH ::




Custom Search