Contents of This Book
The first nine chapters of this book describe the J2ME platform, the command-line tools that are provided with Sun's J2ME reference implementations, and some of the visual development environments that you can use when writing J2ME applications:
Chapter 1
This chapter introduces the J2ME platform and the concepts of configuration and profile, and it compares J2ME to a number of other Java platforms for small devices.
Chapter 2
This chapter covers the Connected Limited Device Configuration (CLDC), which is the basic building block for the J2ME profiles for wireless devices and PDAs. It begins by outlining the differences between CLDC and the core libraries of the J2SE platform. Then it takes a close look at KVM, the small-footprint virtual machine that is used in Sun's reference implementation of CLDC.
Chapter 3
This chapter introduces MIDlets, the wireless Java equivalent of applets. MIDlets are part of the Mobile Information Device Profile (MIDP), which is the subject of this and the following three chapters. This chapter looks at the lifecycle of a MIDlet and illustrates it with a simple example. It concludes with a discussion of the facilities that a typical mobile device would provide to allow the user to download, install, manage, and remove MIDlets.
Chapter 4
The devices that MIDlets run on range from cell phones with a small two-color
display and room for only a few lines of text to PDAs with larger, multicolor screens. In order to isolate MIDlets from the specifics of the devices on which they are running, MIDP includes a high-level API that provides simple input and output controls and the ability to combine these controls to create form-like screens. This chapter takes a detailed look at the high-level API and provides sample MIDlets that can be run on cell phones or PDAs.
Chapter 5
This chapter looks at an alternative user interface API that provides lower-level access to a mobile device's screen and input devices. This chapter looks at the details of this API and shows how to avoid writing code that may not be portable between devices with different user interface capabilities.
Chapter 6
Networking is a key feature of a mobile device. The first part of this chapter looks at the Generic Connection Framework (GCF), which provides the basis for access to various networking APIs, including optional protocols (such as sockets and datagrams) and HTTP, which all MIDP implementations are required to support. A simple example that involves fetching information from a web site is used to illustrate the use of HTTP on a mobile device and shows how to avoid problems that arise when working in an environment with limited memory. The second part of this chapter looks at the facilities available for storing information on a mobile device and illustrates them by extending the HTTP example to include persistence of information retrieved from the web site.
Chapter 7
This chapter looks at the Connected Device Configuration (CDC) and its profiles, which are designed for use on devices that have more than 2 MB of memory to devote to the Java platform. It begins by looking at Sun's reference implementation of CDC and the CVM, the virtual machine for CDC devices, then briefly covers the content of the CDC-based profiles that are currently defined.
Chapter 8
This chapter contains reference material for the command-line tools that are provided with the CLDC and CDC reference implementations and the MIDP for the PalmOS product.
Chapter 9
This chapter covers the J2ME wireless toolkit, a development environment provided by Sun that allows you to create and test MIDlets using a cell-phone emulator that can be customized to resemble a number of different cell phones and PalmOS-based handhelds. It also looks at how to use the wireless toolkit in conjunction with Sun's Forte for Java IDE to create a complete development environment, and it investigates a number of alternative third-party products that provide similar functionality.
These first nine chapters provide a tutorial introduction to J2ME, with particular emphasis on wireless devices, which are currently the most popular application of J2ME technology. The core of this book, however, is the API quick reference, Chapter 10 through Class, Method, and Field Index, which is a succinct but detailed API reference formatted for optimum ease of use. Please be sure to read "How To Use This Quick Reference," which appears at the beginning of the reference section; it explains how to get the most out of this
section.
Related Books
O'Reilly & Associates, Inc., publishes an entire series of books on Java programming. These books include Java in a Nutshell and Java Enterprise in a Nutshell, which, as mentioned earlier, are companions to this book.
You can find a complete list of Java books from O'Reilly at http://java.oreilly.com/. Books that are of particular interest to J2ME programmers include:
Java in a Nutshell, by David Flanagan
A Java language tutorial and complete API reference for the core Java classes. This book is of particular interest if you intend to work with the CDC-based profiles, since the APIs very closely match those of J2SE.
Java Enterprise in a Nutshell, by Jim Farley and William Crawford, with David Flanagan
A tutorial and API reference for Java's enterprise APIs, including Remote Method Invocation (RMI). This book will be of interest to you if you intend to use the RMI profile.
Java Network Programming, by Elliotte Rusty Harold
A book that describes the J2SE networking APIs.
Java I/O, by Elliotte Rusty Harold
A book that describes the input/output architecture of the Java platform, a proper understanding of which is essential if you intend to use the networking and persistent storage features of MIDP.
Java Threads, by Scott Oaks and Henry Wong
A book that describes how to make use of Java's built-in multithreading features, which are also available in the J2ME platform.
Learning Wireless Java, by Qusay Mahmoud
An introduction to Wireless Java, this book also shows how to install MIDlets in some of the Java-enabled cell phones that are currently available.
J2ME Programming Resources Online
This book is a quick reference designed for speedy access to frequently needed information. It does not, and cannot, tell you everything you need to know about J2ME. In addition to the books listed earlier, there are several valuable (and free) electronic sources of information about J2ME.
Sun's web site for all things related to Java is http://java.sun.com/. This web site includes home pages for many of the products that make up the J2ME platform, including the following:
http://java.sun.com/j2me/
General information on the J2ME platform
http://java.sun.com/products/cldc/
The CLDC specification and to download the reference implementation
http://java.sun.com/products/midp/
The MIDP specification
http://java.sun.com/products/cdc/
The specification and reference implementation of the CDC
The following page is useful as a starting point for finding the latest documentation:
http://java.sun.com/j2me/docs/
The web site specifically for Java developers is http://developer.java.sun.com/. Much of the content on this developer site is password-protected, and access to it requires (free) registration. This site includes a forum for the K Virtual Machine (KVM), which also discusses wider issues related to wireless development and J2ME in general. Once you have registered, you can reach this forum at the following URL:
http://forum.java.sun.com/forum.jsp?forum=50
Sun also has a web site dedicated to Wireless Java development:
http://wireless.java.sun.com/
There is also a mailing list for discussion of KVM and MIDP; you can subscribe to it or just browse the archives at:
http://archives.java.sun.com/archives/kvm-interest.html
Bill Day's J2ME site is very useful for up-to-date documentation and for links to other sources of J2ME-related information and development tools:
http://www.billday.com/j2me/
J2ME implementations currently do not have XML or cryptography support included. In many applications, one or both of these is vital. You can find an open-source XML product suitable for J2ME at http://www.kxml.org/ and an open-source, lightweight crytography product at http://www.bouncycastle.org/.
Information on cell phones and PDAs that support J2ME can be obtained from:
http://www.javamobiles.com/
Examples Online
The examples in this book are available online and can be downloaded from the home page for the book at http://www.oreilly.com/catalog/j2meanut/. You may also want to visit this site to see if any important notes or errata about the book have been published there.
The example code is held in two separate directory structures, which contain exactly the same source code, but organized differently. The directory src has the source code arranged in a hierarchy that is convenient if you intend to build and run the examples using an integrated development environment such as Sun's Forte for Java. If, on the other hand, you plan to use the J2ME Wireless Toolkit, which expects its source files to be arranged differently, you
should use the examples in the wtksrc directory. The J2ME Wireless Toolkit is available for free download from Sun's web site at http://java.sun.com/products/j2mewtoolkit/.
Some of the descriptions of the examples in this book assume that you are using the J2ME Wireless Toolkit. You'll find information on how to use the example source code with the wireless toolkit in Chapter 3 and how to use it with Forte for Java in Chapter 9.
|