Learning Wireless Java By Qusay Mahmoud Publisher : O'Reilly Pub Date : December 2001 ISBN : 0-59600-243-2 Table of Pages : 262 Contents Learning Wireless Java is for Java developers who want to create applications for the Micro Edition audience using the Connected, Limited Device Configuration and the Mobile Information Device Profile (MIDP). These APIs specifically for devices such as mobile phones and pagers, allowing programmers to create MIDlet applications. This book offers a solid introduction to J2ME and MIDP, including the javax.microedition classes, as well as classes surrounding the features of the various platforms that the J2ME supports. Brought to you by ownSky!! Table of Content Table of Content.
vii Contents of This Book. vii Comments and Questions. x Part I: Introducing Java 2 Platform, Micro Edition (J2ME). Overview of J2ME.1 What Is J2ME?.2 Downloading the J2ME Wireless Toolkit.
The Connected Limited Device Configuration (CLDC) .1 Examining the CLDC in Detail.2 Using the Standalone CLDC and KVM .3 CLDC Next Generation. The Mobile InformationDevice Profile (MIDP).1 Mobile Information Devices.2 More About MIDlets. 28 Part II: Programming with the CLDCand the MIDP. Working with MIDlets .1 The Application Manager.
MIDP GUI Programming.1 Why Not Reuse the AWT?.2 The MIDP GUI APIs.3 The High-Level MIDP APIs .4 Creating Low-Level GUI Components .2 Handling Low-Level Events .3 The HTTP Programming Model .4 Invoking Remote Applications from MIDlets .5 Wireless Session Tracking.6 MIDlet Networking Security.1 The Record Management System .2 Programming with the RMS. The MIDP for Palm OS .1 Installing the MIDP for Palm OSon the Windows Platform .2 Developing New Applications .3 PRC Command-Line Conversion.4 Advanced Java Applications. 140 Part III: API Quick Reference. 202 v Copyright © 2001 O'Reilly & Associates, Inc.
All rights reserved. Printed in the United States of America. Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly & Associates books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safari. For more information contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries.
O'Reilly & Associates, Inc. is independent of Sun Microsystems. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly & Associates, Inc.
was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of a galago lemur and the topic of wireless Java is a trademark of O'Reilly & Associates, Inc. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. vi Preface Most Internet technologies are designed for desktop computers or enterprise servers running on reliable networks with relatively high bandwidth.
Handheld wireless devices, on the other hand, have a more constrained computing environment. They tend to have less memory, less powerful CPUs, different input devices, and smaller displays. Since the mid-1990s, various architectures and protocols have been introduced to deal with these constraints. The Wireless Application Protocol (or WAP), which is a specification developed by the WAP Forum (http://www.org), takes advantage of several data-handling approaches already in use.
Developing wireless applications using WAP technologies is similar to developing Web pages with a markup language (e., HTML or XML) because WAP technologies are browser-based. Another approach to developing wireless applications is to use the Java 2 Platform, Micro Edition (J2ME ). The Java programming language already plays an important role in modern programming. With WAP, you can use Java servlets and JavaServer Pages to generate Wireless Markup Language (WML) pages dynamically.
However, with J2ME, you can now write applications in Java and store them directly on a cell phone. This adds a whole new dimension to wireless programming. Audience This book is about programming with J2ME on wireless devices. If you're already familiar with the architecture, you probably noticed that the Connected Limited Device Configuration (CLDC) and the Mobile Information Device Profile (MIDP) classes are not large.
Therefore, this book is correspondingly compact in size. The book acts as a quick guide for programmers who are familiar with the Java 2 Standard Edition (J2SE ) and want to get up to speed quickly with the J2ME. We assume that you are familiar with Java programming and have worked with the J2SE classes. In addition, we assume that you are familiar with setting up Java to work under various environments (Windows or Unix platforms), as well as compiling and running Java applications.
The book also serves as a quick reference for Java programmers who are interested in developing wireless software applications. The examples presented throughout the book are a good starting point for working with all the MIDP features, including user interface, networking, and databases. However, we should point out that this book is not a rehash of the entire J2SE class library. Several of the classes of java.lang, and java.net are included in the CLDC and MIDP libraries, but are less bulky than their J2SE counterparts.
We assume that you already know how to use these classes, although we have included them in the API reference for completeness. Contents of This Book This book is divided into three parts. Part I gives an overview of the J2ME and includes information about its architectural components: namely, configurations and profiles. Part I also presents detailed coverage of the CLDC and the MIDP.
Chapter 1 vii This chapter introduces the J2ME environment and also explains configurations and profiles. In addition, it shows you how to set up the J2ME Wireless Toolkit to compile, preverify, and run a simple MIDlet using the command line with the Wireless Toolkit emulator. Chapter 2 This chapter discusses the CLDC, including its requirements, limitations, and the differences between its classes and the classes of the J2SE. In addition, it looks briefly at the standalone CLDC and KVM distribution.
Chapter 3 This chapter introduces the requirements, limitations, and classes of the MIDP, as well as introducing MIDlets and their associated Java Application Descriptor (JAD) files. Part II contains programming details of the MIDP. It shows you how to program the phone interface, handle events, make network connections, and work with databases. Chapter 4 This chapter picks up where Chapter 3 left off, explaining the MIDlet lifecycle methods, the Java application manager, and showing how to use the KToolbar application inside the J2ME Wireless Toolkit to simplify MIDlet development.
We also discuss how to deploy MIDlets and include step-by-step instructions on how to download a MIDlet into a Motorola i85s or i50x J2ME-enabled phone. Chapter 5 This chapter introduces the MIDP GUI model and its associated classes. In addition, it gives detailed coverage of both the high-level and low-level MIDP GUI APIs. Chapter 6 This chapter continues the discussion of the MIDP GUI APIs by describing how various events take place surrounding the graphical components and commands.
In addition, we cover the CommandListener and ItemStateListener interfaces, as well as low- level event handling. Chapter 7 This chapter discusses the Generic Connection Framework provided by the CLDC and shows how to implement an HTTP connection across the Internet, using a MIDlet. The chapter also includes examples of how to send data to CGI scripts and Java servlets across a network. Finally, the chapter briefly discusses wireless session tracking and security for MIDlet data traveling across the airwaves.
Chapter 8 This chapter introduces the concept of data stores, which are simple databases that MIDP applications can use to store persistent data beyond the lifetime of the MIDlet that created them. In addition, the chapter includes a MIDlet that can be used to download stock information from a remote web site. Chapter 9 viii This chapter gives a quick introduction to the MIDP implementation on the Palm Connected Organizers, including step-by-step instructions on how to deploy MIDlets to a PalmPilot. Part III contains several chapters that are quick references for the J2ME CLDC and MIDP APIs.
There is also an appendix that contains bibliographic information and URLs to J2ME specifications, white papers, wireless software development kits, and other information that is important to developers. Conventions Used in This Book This book uses the following typographical conventions: A Constant Width font is used for: • Anything that might appear in a Java program, including keywords, data types, constants, method names, objects, variables, class names, and interface names • All Java code examples • Attributes that might appear in a manifest or JAD file An italic font is used for: • New terms where they are defined • Pathnames, filenames, directory names, and program names (unless the program name is the name of a Java class; then it appears in constant width, like other class names) • Internet addresses, such as domain names, URLs, and email addresses A boldface font is used for: • Example lines of Java code to which we wish to draw attention Comments and Questions The information in this book has been tested and verified, but you may find that features or libraries have changed, or you may even find mistakes. You can send any errors you find, as well as suggestions for future editions, to: O'Reilly and Associates, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 (800) 998-9938 (in the United States or Canada) (707) 829-0515 (international/local) (707) 829-0104 (fax) You can also send electronic messages.
To be put on the mailing list or to request a catalog, send email to: info@oreilly.com To ask technical questions or comment on the book, send email to: ix bookquestions@oreilly.com I would be pleased to receive feedback on this book. You can contact me by email at: qmahmoud@javacourses.com The O'Reilly web site for this book is located at http://www.com/catalog/wirelessjava and contains all the source examples for this book. In addition, we have created another web site, http://www.com/wireless, that includes links to material that supports the use of this book for training and personal study. This web site provides the following supplements: • Additional source code for new applications • Links to online J2ME material, and information on other related books • J2ME tips and tricks • A set of overhead projector transparencies for instructors interested in using the book in their training courses • Up-to-date information on topics presented in the book Acknowledgments I am deeply grateful to my editor, Robert Eckstein, for all his comments, suggestions, and guidelines throughout the development of this book.
I did not know about all the contributions an editor can make to a book until I worked with Bob. Thanks, Bob! Thanks also to the production team at O'Reilly for their hard work on this book. Special thanks also to Monica Pawlan, Jenny Pratt, Dana Nouri, and Laureen Hudson of the Java Developer Connection (JDC), who either provided comments or edited some of the examples used in this book when they first appeared on the JDC. Also, thanks to the thousands of JDC members who sent in comments and suggestions regarding my articles.
Thanks also to the following people who reviewed the contents of this book for accuracy: Ben Griffin, Marc Loy, and Jeff Cunningham. I would also like to thank my family for their support during my studies, especially my brother, Dr. Hamdan, for teaching me the value of hard work. Finally, thanks to my wife, Reema, for her love, support, tolerance, and coffee, and my baby son Yusef, who was born on October 14, 2001, for providing a fun home environment while I finished this book.
x Part I: Introducing Java 2 Platform, Micro Edition (J2ME) Part I is an introduction to the Java 2 Micro Edition (J2ME) and J2ME programming.