Tải bản đầy đủ (.pdf) (504 trang)

Java 2 micro edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.1 MB, 504 trang )

WH_Java2.book Page i Monday, March 4, 2002 9:59 AM

Java 2 Micro Edition

www.it-ebooks.info


WH_Java2.book Page ii Monday, March 4, 2002 9:59 AM

www.it-ebooks.info


WH_Java2.book Page iii Monday, March 4, 2002 9:59 AM

Java 2
Micro Edition
Java in Small Things
JAMES WHITE
DAVID HEMPHILL

MANNING
Greenwich
(74° w. long.)

www.it-ebooks.info


WH_Java2.book Page iv Monday, March 4, 2002 9:59 AM

For online information and ordering of this and other Manning books,
go to www.manning.com. The publisher offers discounts on this book


when ordered in quantity. For more information, please contact:
Special Sales Department
Manning Publications Co.
209 Bruce Park Avenue
Greenwich, CT 06830

Fax: (203) 661-9018
email:

©2002 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form or by means electronic, mechanical, photocopying, or otherwise, without prior
written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial
caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.

Manning Publications Co.
209 Bruce Park Avenue
Greenwich, CT 06830

Copyeditor: Lois Patterson
Typesetter: Martine Maguire-Weltecke
Cover designer: Leslie Haimes

ISBN 1-930110-33-2
Printed in the United States of America

1 2 3 4 5 6 7 8 9 10 – VHG – 06 05 04 03 02

www.it-ebooks.info


WH_Java2.book Page v Monday, March 4, 2002 9:59 AM

To my wife, Kelly
J.W.

To my wife, Amy Votava and my daughter, Olivia Hemphill
D.H.

www.it-ebooks.info


WH_Java2.book Page vi Monday, March 4, 2002 9:59 AM

www.it-ebooks.info


WH_Java2.book Page vii Monday, March 4, 2002 9:59 AM

contents
preface xv
acknowledgments xviii
about this book xx
about the cover illustration

Part 1


xxiii

Developing with J2ME 1
1 Introduction 3
1.1 So what is J2ME anyway? 3
Where is J2ME being applied? 4
1.2 What is a small device? 5
The vast consumer space 5
Consumer electronic and embedded devices 6
1.3 J2ME’s role in wireless and mobile applications 7
Is J2ME mobile? 7 ✦ Is J2ME wireless? 8
Wireless vs. mobile 9
1.4 The Java 2 edition trilogy 9
J2SE 10 ✦ J2EE 10
J2ME 11 ✦ Why we need J2ME 11
1.5 The case for Java 12
Is Java right for small devices? 12 ✦ Java’s beneficial features 13
1.6 Origins of J2ME 15
Java’s origins 15 ✦ The return of Java in small devices 16
1.7 The J2ME community 16
J2ME’s guiding light, the Java Community Process 16
1.8 J2ME products and alternatives 17
1.9 Summary 18

vii

www.it-ebooks.info



WH_Java2.book Page viii Monday, March 4, 2002 9:59 AM

2 J2ME architecture 19
2.1 Goals of the J2ME architecture 19
Support for multiple devices 20
Support for device-specific functionality 20
Maintaining a common architecture 21
2.2 Accommodating opposing needs 21
Configurations and profiles 22 ✦ A high-level view of J2ME 23
2.3 Configurations: a closer look 24
Connected Limited Device Configuration (CLDC) 25
The Kilobyte Virtual Machine (KVM) 27
Connected Device Configuration (CDC) 28
C-Virtual Machine (CVM) 29
2.4 Profiles: a closer look 29
Two types of profiles 30 ✦ Profiles are modular 30
J2ME profiles extend J2ME configurations 31
2.5 Choosing a J2ME profile 31
Mobile Information Device Profile (MIDP) 32
PDA Profile (PDAP) 32 ✦ Foundation Profile 32
Personal Profile 32 ✦ RMI Profile 33 ✦ Personal Basis Profile 33
Multimedia Profile 33 ✦ Gaming Profile 34
Wireless Telephony Communications API (WTCA) 34 ✦ KJava 34
2.6 Write once, run anywhere issues 35
Varied device needs 35 ✦ J2ME architecture increases WORA 36
2.7 Runtime environment 36
2.8 Designing J2ME applications 36
2.9 Summary 38

3 Developing a J2ME application


39

3.1 Investment quote application requirements 40
The investment quote application customer 40
Requirements analysis 41
3.2 Designing the investment quote application 42
Application control 42 ✦ User interface design 43
Persistent storage 45 ✦ Networking and input/output 46
3.3 Developing J2ME applications 48
Obtaining the development environment 48
Creating the applications 49 ✦ Runtime environment 49
3.4 Investment quote application tour guide 50
3.5 Summary 51

viii

C ONTENTS

www.it-ebooks.info


WH_Java2.book Page ix Monday, March 4, 2002 9:59 AM

Part 2

Developing for cellular phones and pagers 53
4 A simple MIDP application 55
4.1 Questions about the MIDP development environment 56
Can I do this without an actual device? 56

What device do I start with? 56
Do I have to use the command line tools? 56
The example: what are we going to do? 56
4.2 Developing MIDP applications 56
Getting started 57 ✦ What is a MIDlet? 58
Compiling the application 60 ✦ Preverifying the application 61
Running the application 61 ✦ Troubleshooting 62
JARing MIDlets 63 ✦ Developing MIDlet suites 64
Running MIDlet suites from a web server 67
Installing MIDlet suites locally 67
4.3 Summary 68

5 MIDP user interface 69
5.1 MIDP application control 70
5.2 The investment quote application control in MIDP 71
5.3 Two types of MIDP user interface and event handling 75
High-level API 76 ✦ Low-level API 76
5.4 The MIDP user interface API 77
MIDP display control 77 ✦ MIDP high-level user interface API 78
MIDP low-level user interface API 87
The investment quote application’s user interface in MIDP 91
5.5 Handling user interactions in MIDP 105
High-level event handling 107 ✦ Low-level event handling 110
Handling the events of the Investment Quote Application 114
5.6 MIDlets on other devices 130
5.7 Summary 133

6 MIDP data storage 134
6.1 JDBC parallel 135
6.2 Storage structure 136

Record store 136 ✦ Records in the record store 137
6.3 RMS API 138
Record store construction and access 138 ✦ Record store exceptions 141
Record store listener 142 ✦ Comparing records 144
Filtering records 145 ✦ Enumerating through records 146

ix

CONTENTS

www.it-ebooks.info


WH_Java2.book Page x Monday, March 4, 2002 9:59 AM

6.4 Persistent storage in the investment quote application
Defining the stock/mutual fund record 149
Storing quotes 150 ✦ Retrieving quotes 156
6.5 Summary 166

7 Connecting to the Internet

167

7.1 Micro edition package connectivity 168
Using the Connector class to open a channel 168
7.2 Similar but smaller I/O package 169
Streams 170 ✦ Readers/Writers 170
7.3 Implementing the Internet investment quote service
Getting a quote service connection 172

Extracting the price quote from the HTML 177
The MIDlet’s handling of quote data 180
7.4 Summary 186

Part 3

149

171

Developing for PDAs 187
8 J2ME on a PDA, a KJava introduction 189
8.1 PDA profile alternatives 190
Java PDA development environments 190
What is KJava? 191 ✦ What is MIDP for Palm OS? 192
8.2 HiSmallWorld in KJava 192
Getting Started 192 ✦ What is a Spotlet? 193
Compiling HiSmallWorld 194 ✦ Preverifying KJava applications 197
Creating the Palm OS application 198 ✦ Running the application 202
8.3 Deploying to the actual device 211
8.4 HiSmallWorld revisited using MIDP for Palm OS 213
MIDP application code 214 ✦ Converting the JAR file to PRC 215
Deploying the MIDP for Palm OS applications 216
8.5 Summary 217

9 KJava user interface

218

9.1 KJava application control 219

9.2 The investment quote application control in KJava 220
9.3 KJava user interface 225
Drawing to the display with the graphics object 225 ✦ Components 231
Custom components 239 ✦ KJava collection classes 239

x

C ONTENTS

www.it-ebooks.info


WH_Java2.book Page xi Monday, March 4, 2002 9:59 AM

9.4 The investment quote application’s user interface in KJava 240
Creating and displaying components 240 ✦ Drawing with graphics 244
9.5 Handling user interactions in KJava 248
Spotlet event-processing methods 248 ✦ Handling beaming events 250
9.6 Handling the events of the investment quote application in KJava 250
Handling key entry events 250 ✦ Handling pen taps 252
Handling pen movement 255
9.7 Summary 261

10 KJava data storage 262
10.1 Palm OS databases 263
Different types of Palm OS databases 263
Palm OS record database 263
10.2 KJava database API 265
Opening and creating databases 265 ✦ Accessing the database 267
10.3 Implementing the investment quote persistent storage in KJava 268

The stock/mutual fund record 268
Storing investment quotes 269 ✦ Retrieving records 273
10.4 Revisiting the connection to the Internet 275
10.5 Accessing Palm OS application databases 285
10.6 Summary 287

Part 4 Developing for the enterprise:
beyond the specifications 289
11 Real-world design 291
11.1 Dealing with stakeholders 292
Get them familiar with the devices early 292 ✦ Set expectations 293
Gathering requirements 293 ✦ State of the organization 293
11.2 A development scenario 294
Analysis 295 ✦ Options 296
11.3 Guidelines for building J2ME applications 298
The user interface 298 ✦ The network 304
Data exchange formats 306 ✦ Data synchronization 312
Data storage 317 ✦ Memory 319
Portability between profiles 320
Security 322 ✦ Internationalization 323

xi

CONTENTS

www.it-ebooks.info


WH_Java2.book Page xii Monday, March 4, 2002 9:59 AM


11.4 Architectural tools and techniques 325
Questionnaire: assessing if mobile and wireless is a good fit 325
Mobile application models 326 ✦ Architect’s checklist 329
11.5 Summary 331

12 Integrating the server

332

12.1 Examining server integration 333
Avoid monolithic applications 333
12.2 What technology to connect to? 334
12.3 Servlet example 334
12.4 XML 347
Using XML 348 ✦ Open standards of XML 350
Consequences of XML in J2ME 351 ✦ Small-footprint parsers 351
12.5 XML using JSPs example 353
How JavaServer Pages work 353 ✦ Creating the JSPHelper 355
Creating the JSP 357 ✦ Creating the J2ME Client 358
12.6 Summary 364

13 The network connection 365
13.1 About the Generic Connection Framework 366
Where the Generic Connection Framework lives 367
Working with the Connector class 368 ✦ The Connector is a factory 370
How the Connector finds the correct class 370
13.2 Using the Generic Connection Framework 372
13.3 HTTP-based connections 372
Establishing a connection 372 ✦ Using the connection 373
Compiling and running the application 376

13.4 Socket-based connections 377
Writing to sockets 378 ✦ Reading from sockets 380
When to use sockets 381 ✦ Client-server socket example 381
13.5 Datagram-based connections 394
Datagram example 397
13.6 Summary 406

14 J2ME runtime environment

407

14.1 The Java runtime environment 408
Lifecycle of the Java Virtual Machine 408
Java Virtual Machine responsibilities 411
14.2 The J2ME runtime environment 415

xii

C ONTENTS

www.it-ebooks.info


WH_Java2.book Page xiii Monday, March 4, 2002 9:59 AM

14.3 CLDC-compliant virtual machines (the KVM) 415
KVM lifecycle 416 ✦ Preverification 416
In-device verification 417 ✦ Security 417
Unsupported Java features 419 ✦ Multithreading 421
Garbage collection 421 ✦ Internationalization 422

Application management (JAM) 422 ✦ Java Code Compact (JCC) 423
Deployed classes 424 ✦ Debug support 424
14.4 CDC-compliant virtual machines (the CVM) 425
Garbage collection and the CVM 426
Memory references in the CVM 426
14.5 Summary 427

15 Related technologies

428

15.1 J2ME implementations 429
esmertec’s Jbed 429
Motorola’s Embedded Reference Implementation (MERI) 430
15.2 The other Sun specifications 430
PersonalJava 430 ✦ EmbeddedJava 434
15.3 Non-J2ME alternatives 435
ChaiVM by Hewlett-Packard 435 ✦ IBM’s VisualAge Micro Edition 435
Waba by Wabasoft 438
15.4 Related Java technologies 438
Java Card 438 ✦ Java Native Interface 439
Jini 441 ✦ JavaPhone and Java TV APIs 442
15.5 Non-Java alternatives 442
WAP/WML 443 ✦ Other languages 443
15.6 Data storage and synchronization 444
Data storage 444 ✦ A data synchronization standard, SyncML 445
XML 446
15.7 J2ME supplementary technology 448
GUI, kAWT 448 ✦ Web browsing, Kbrowser 449
Encryption, Bouncy Castle 449

15.8 Summary 449

A J2ME development tools

451

B J2ME resources 453

xiii

CONTENTS

www.it-ebooks.info


WH_Java2.book Page xiv Monday, March 4, 2002 9:59 AM

C Java and J2ME history 456
C.1 Oak and the Green Project 456
C.2 Java and the Internet 457
C.3 Evolution of Java 458
Java 1.02 459 ✦ Java 1.1 459
Java 2 459 ✦ SDK 1.3 460
Java 3 coming soon? 460 ✦ Java today 460
C.4 Origins of J2ME 460
Micro-Java rebirth 461 ✦ Early access versions of J2ME 461
J2ME’s continuing evolution 462 ✦ J2ME today 463

D J2ME Wireless Toolkit


464

D.1 Downloading the Wireless Toolkit 464
D.2 Installing the J2ME Wireless Toolkit 465
D.3 Hello World project revisited 466
Starting the toolkit 466 ✦ Creating a project 467
Editing the project settings 469 ✦ Entering the Java code 470
Building a project 470 ✦ Running a project 470
Palm OS Emulator 471 ✦ Operating from the command line 472
D.4 Summary 472

index 473

xiv

C ONTENTS

www.it-ebooks.info


WH_Java2.book Page xv Monday, March 4, 2002 9:59 AM

preface
Fifteen to twenty years ago, anyone familiar with the computer industry did not
question the impact personal computers would have on our society. The only question was how quickly could PCs be made available at a reasonable price in order to
begin this new age. Today, with personal computers in three of every four United
States households and with the ubiquity of the Internet associated with all those PCs,
the Information Age has arrived. Nearly everyone is connecting to and using information resources in ways exceeding the wildest dreams of early PC visionaries.
Our personal computers are on the same path of technical
progression. They are getting smaller while at the same

time doing more for us. This should not surprise us since
small computers and microchips are already assisting and
controlling more of our daily lives. Our cars, home appliances, and entertainment systems probably already have
mini-computers that help their associated products give
RCA 8TS30 (1943)
Courtesy of
you better service. Now, personal digital assistants (PDA),
www.harryposter.com
such as those from Palm Inc. or Compaq, allow you to
download your electronic calendar, address book and other personal information from
your PC and take them with you when you are away. Is a Palm a
personal computer? Many PDAs have more memory storage and
processing power than PC’s of a few years ago.
Simultaneously, our communications devices have been getting more powerful. When is the last time you used a rotary-dial
telephone? More likely, you have been using a cellular digital telephone. This little device can not only place your call from virtually
anywhere, but it can also help you remember whom you have to
call and provide their home or office telephone numbers. In fact,
you have probably programmed it so that you no longer have to
know the telephone numbers any more. You simply tell your little
phone to ring the person with whom you want to have a conversation. The cell phone contains an electronic address book
Sony Watchman
Color TV (2001)
and other personal information just like your PC.
Courtesy of Sony Electronics, Inc.

xv

www.it-ebooks.info



WH_Java2.book Page xvi Monday, March 4, 2002 9:59 AM

If you are fortunate enough to have a two-way pager, you
may have it set up to receive and send your email messages among
its other duties. In many ways, the numerous communication
and information devices such as cell phones and two-way pagers are taking over for your PC when you are away from it.
So, if you have not been paying attention
lately, you may want to take a closer look at the
Western Electric’s
electronic devices around you. Your PC, digital
202 Desk Phone (circa 1927)
assistants, and communication devices are
Courtesy of Play Things of Past, Cleveland OH
starting to look and behave more and more
alike, at least in terms of the conveniences they provide. Again, the
natural progression is for technology to do more with less. What is
interesting is that the technologies are migrating toward each
other. Computers are shrinking and doing more communicating,
while other information and communication devices are growing more powerful and providing more personal computerrelated services. How soon before everyday appliances like our Motorola’s StarTAC
(circa 2000)
automobiles, televisions, microwaves, and other appliances start
Courtesy of
Motorola, Inc.
to become a highly connected and powerful network of computing devices that help us live our lives?

The merging of technologies

While the make and type of these systems are still quite diverse, we want the same
conveniences and capabilities that these information devices provide us anywhere and
at anytime. Providing these capabilities and conveniences is at the heart of any computer system, no matter how large or small the software. This is making the software

engineer’s job most difficult. How does one provide many of the same capabilities
like email, calendaring, address tracking and scheduling across a very diverse, and
seemingly growing, set of products? These software capabilities are just the start.
xvi

PREFACE

www.it-ebooks.info


WH_Java2.book Page xvii Monday, March 4, 2002 9:59 AM

How soon until we have invoicing and
billing capability on our cellular tele90
phones? How soon will our refrigerator
80
be able to tell our PDAs that we are out
# of households
with computers
70
of milk (the inventory is low) and we get
a restocking reminder on the way home
60
from work? Is there a write once, run any50
where software solution that allows the
40
software engineer to simply and easily
provide many of the same capabilities to
30
this diverse set of devices? We contend

20
that there is a solution, or at least the
10
makings of a solution, in Java and in
particular the Java 2 Micro Edition.
0
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
If you thought the diversity in the
Year
number and type of computer systems
Census Bureau statistics and FCC estimates on
was challenging, imagine trying to write
number of household PCs and cellular phone
software that operates in the “inforsubscribers in the United States.1
mation appliance” arena that includes
pagers, cellular phones, PDA’s, television set-top boxes, point-of-sale terminals, and
other consumer electronics. There are over a dozen cell phone manufactures alone.
Each has different characteristics and interfaces.
As we will explore, the Java programming language has generally fulfilled the wish
of software engineers looking for a means to write a single application that runs over
all types of computer systems. Writing a single code base application that works on
an Apple PC, Intel-based PC, Sun Microsystems Workstation, IBM mainframe, etc.
is now possible. As you might imagine, the portability of a Java application across an
even deeper and more diverse set of information appliances has attracted many to the
possibility of running a once-written application on multiple types of systems.
What’s more, there are an estimated 100 million cellular telephone users in the
United States, with an estimated 530 million cellular telephone users worldwide by
2002. That compares to an estimated 50 million households with personal computers
today. The exchange of information and ideas across this number of platforms is truly
staggering. Imagine having some of the application capabilities of the Internet and our

personal computers on a platform the size of a small cell phone. Imagine further that
this transfer of capabilities is relatively seamless!1
Of course, the challenge is to compact enough of Java’s essentials into a very small
package. This is the world of the Java 2 Micro Edition (J2ME). While it is still in its
infancy, the convergence of the many technologies and resources surrounding these
devices makes the advancement of J2ME as likely as it is necessary.

100

Owners in millions

# of cell phone
subscribers

1

/>
xvii

PREFACE

www.it-ebooks.info


WH_Java2.book Page xviii Monday, March 4, 2002 9:59 AM

acknowledgments
Books do not write themselves, and, as we have come to understand all that is
involved in putting one on the shelf, we now know that it takes much more than just
the authors.

We would like to extend a special thank you to our publisher, Marjan Bace, and to the
staff at Manning Publications who have contributed to this effort, as well as to the many
people who took time out of their schedules to provide peer reviews, suggestions, and
assistance. The reviewers included Carl Baldys, Mike Chan, Perry Dillard, Jon Eaves,
Boran Gogetap, Lee Miles, Peter Mortier, Bryan Nehl and Tim Panton. Your work has
not gone unnoticed and the final result is a reflection of this combined effort. Thank you.
JAMES WHITE
A lot of energy and time goes into writing a book, and a great number of people have
influence on its outcome. Some are directly responsible for its delivery. To this end, I
would like to first and foremost thank my co-author David Hemphill. His dedication
and loyalty go beyond this single endeavor. He is a quiet yet steady friend that I have
come to rely on for guidance on the roughest of days, not to mention, he’s pretty
darned smart. Thank you David. I would also like to thank the folks who spent hours
reviewing the manuscripts in various stages and forms. In particular, I would like to
thank Jan Emter and Carl Baldys for their evaluations and assistance. It’s not a fun
job, but they did it very well. We also owe a special thanks to the folks at esmertec
who supported us with the use of their product and the reviews of the material on
their product. A big thanks to Jon Eaves for his meticulous technical review. Finally, I
would like to thank the editors and staff at Manning (Lianna Wlasiuk and Lois
Patterson in particular) for allowing this dream to become a reality.
There are a number of other people who are indirectly responsible for this book’s
delivery. These are the people who have and will continue to shape my life on a daily
basis, sometimes without knowing how much they do so. First, I would like to thank
my parents, Ann and Jim White. Both teachers by profession, they have raised the
eternal student. They have given me three gifts: life, enjoyment and satisfaction in
hard work, and the unquenchable thirst to learn more. Thank you Mom and Dad.
Second, I would like to thank my family, good friends, co-workers and colleagues who
xviii

www.it-ebooks.info



WH_Java2.book Page xix Monday, March 4, 2002 9:59 AM

supported me in the efforts of this book, and in all else as well. In particular, I would
like to thank Mike (my brother), Angie and Laura (sisters), Jim St. Aubin, Mike Carson, Phil and Kelly Davis, Todd Lauinger, and Larry Marchman. I would also like to
thank Scott King. Forever the optimist, Scott would never let me say die, on this project
or in any professional endeavor. Thank you Scott for your friendship and belief in me.
Last, but by all the laws that govern everything that is good and just, not least, I
owe my deepest appreciation and devotion to my wife Kelly. I have never met a person
so giving and caring in all my life. To say that she has carried me through this book,
my career and adult life would be a vast understatement. Without her, this book and
everything I do would hold no meaning. Thank you and I love you Kelly.
DAVID HEMPHILL
When starting out on this project to co-author a book, I was concerned about the
amount of time it would take and what life would be like during the months of writing the book. Well, as to how much time it takes, the answer is a rather simple one:
all of it. As to what life is like, let’s just say that if I did not have such a loving, supporting, caring and understanding family, this could have been painful. That said, I
owe my deepest appreciation and gratitude to my wife, Amy Votava. Amy, thank you
so much for all of your love and support during this last year. You mean a great deal
to me and this last year has shown me the power and strength of our partnership.
I truly appreciate how you have stood by me and helped me to see this dream to the
end. Thank you. I love you.
I would also like to thank my daughter, Olivia, who, at age two, was unable to assist
with editing and reviewing the book, but provided me with an ample supply of hugs
and kisses as well as necessary distractions such as make-believe tea breaks with fresh
“yellow” pie, spontaneous dancing and daily readings of The Lorax and other nontechnical literature.
A list of acknowledgments would not be complete without a word or two directed
toward the guy who started all of this in the first place. This would be my co-author,
friend, business partner and fellow software engineer Jim White. This project has been
as enjoyable as it has been challenging and I am glad for the opportunity to have

undertaken it with someone I have come to trust and respect more than just about
anyone I have worked with. Jim, thank you for all of your hard work and dedication
to this project.
I would also like to extend a special thank you to my parents Karen Stewart and
Gary Hemphill. Dad, throughout the writing of this book I often heard your voice in
my head saying, “Go the last mile and see it through.” and Mom, thank you for driving up to Minnesota to help me find more time to write and to allow Amy and me
to get reacquainted from time to time.
In addition, I owe thanks to the rest of my family: my sister, Julia Helbach, my
stepparents John Stewart and Carol Hemphill and my in-laws James and Kathryn
Votava. You have all provided me with love and inspiration during this last year, Amy
and Olivia directly and indirectly many times over.
xix

www.it-ebooks.info


WH_Java2.book Page xx Monday, March 4, 2002 9:59 AM

about this book
Java 2 Micro Edition was written with the developer in mind. It is meant to be a guide
that will serve as an introduction to J2ME technology, as well as a reference to more
complex issues surrounding mobile/wireless computing. Our intent is to provide a
practical overview of the J2ME programming environment by guiding the reader
through detailed programming examples and tutorials. A basic understanding of Java
programming is all that is required, in addition to a need for or interest in developing
applications for mobile and wireless devices.

INTENDED AUDIENCE
This book is intended, largely, for software engineers interested in writing Java applications. It turns out that if you know Java, you know enough to start writing applications for consumer electronics and embedded devices with a little help.


ASSUMPTIONS
Throughout this book, applications will be developed in the Microsoft Windows
environment. This will not affect the outcome of the product. However, if you
choose to develop on another J2ME development platform, such as Solaris, Macintosh, or Linux, you will have to translate all applicable development instructions.
Readers of this text should have a fundamental knowledge of Java. The basic Java
syntax is the same for J2ME as it is for other Java environments, including the familiar
Java 2 Standard Edition (J2SE). However, the API for many Java classes, even those
as basic as String, is diminished relative to the J2SE API. For those familiar with J2SE,
we will explain our use of certain types and methods in code examples where a more
common J2SE type or method would ordinarily be utilized.
We will also use the Unified Modeling Language (UML) to depict some of the
application design. If you are not an object-oriented analyst, you should not be concerned. Our diagrams are pretty simple and merely help provide a picture of some of
the structure in the application and how they relate to the classes and interfaces J2ME
provides.

xx

www.it-ebooks.info


WH_Java2.book Page xxi Monday, March 4, 2002 9:59 AM

ORGANIZATION
The book has fifteen chapters organized into four parts, followed by four appendices.
We begin the book with an introduction to J2ME tools and technologies and then
guide the reader through the development of a tutorial application.
PART 1 Developing with J2ME
The first part of this book focuses on introducing the Java 2 Micro Edition.
Chapter 1 describes how J2ME fits into the larger picture of the Java 2 platform.
The case for why J2ME is necessary and useful is discussed as well as the origins from

which J2ME has sprung. Chapter 2 describes how J2ME is put together. This provides
a context for how J2ME might be used to develop applications for consumer electronics and Internet appliances. This chapter provides a comprehensive, yet high-level tour
of J2ME. Finally, before delving into the particulars of developing J2ME applications,
chapter 3 offers a quick introduction to development environments, covering the particulars of how to obtain various J2ME development tools and technologies, as well
as describing the example application that will be used throughout the book.
PART 2 Developing for cellular phones and pagers
In chapters 4 through 7, we explore the CLDC and MIDP APIs in a tutorial application that was initially described in chapter 3. The tutorial application allows a customer
to use a cell phone or two-way pager to obtain and view stock or mutual fund quotes.
The tutorial allows us to see the major aspects of a J2ME application, namely the user
interface, event handling, data storage, input/output, and network connectivity.
PART 3 Developing for PDAs
In chapters 8 through 10, we explore using KJava with the CLDC API. KJava was
originally created as a test and demonstration API by Sun for demonstrating the
CLDC and KVM on Palm OS devices. Lacking a profile for PDA devices, companies, such as esmertec, have provided commercial implementations with their IDEs
for developing Palm OS applications using KJava. Part 3 explores PDA development
using the now familiar stock quote application. As in part 2, the tutorial application
allows us to examine the major aspects of building a Palm OS application using
KJava. This part of the book covers PDA features such as user interface, event handling, data storage, input/output, and network connectivity.
PART 4 Developing for the enterprise: beyond the specifications
In chapters 11 through 15, we explore the more complex issues of putting together
mobile and wireless applications. Chapter 11 leads off by examining the characteristics
of a mobile and wireless architecture, focusing on using mobile and wireless devices
in conjunction with enterprise technologies. The following chapters explore mobile
and wireless computing for the enterprise, paying special attention to integrating the
ability to communicate with servlets, JSPs and XML data sources. A more thorough
xxi

www.it-ebooks.info



WH_Java2.book Page xxii Monday, March 4, 2002 9:59 AM

examination of the network communication protocols is provided along with an indepth look at the J2ME virtual machines and how they differ from the J2SE virtual
machine. Finally, we spend some time reviewing related technologies, such as commercial, third-party J2ME solutions as well as non-J2ME solutions.
Appendices
In the back of the book, four appendices offer an overview of J2ME tools, resources,
history, and the J2ME Wireless Toolkit provided by Sun Microsystems.

SOURCE CODE
Source code for all the programming examples in this book, including the examples in the tutorials, is available for download from the publisher’s web site,
www.manning.com/white.
Code conventions
Courier typeface is used to denote code, as well as methods, objects, variable names,
and class names. Code annotations accompany many segments of code. Certain annotations are marked with chronologically ordered bullets, such as q. These annotations
have further explanations that follow the code. Code line continuations are indented.

AUTHOR ONLINE
Purchase of Java 2 Micro Edition includes free access to a private web forum run by
Manning Publications where you can make comments about the book, ask technical
questions, and receive help from the authors and from other users. To access the forum
and subscribe to it, point your web browser to www.manning.com/white. This page
provides information on how to get on the forum once you are registered, what kind
of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialog between individual readers and between readers and the authors can take place.
It is not a commitment to any specific amount of participation on the part of the
authors, whose contribution to the AO remains voluntary (and unpaid). We suggest
you try asking the authors some challenging questions lest their interest stray!
The Author Online forum and the archives of previous discussions will be accessible from the publisher’s web site as long as the book is in print.


xxii

ABOUT THIS BOOK

www.it-ebooks.info


WH_Java2.book Page xxiii Monday, March 4, 2002 9:59 AM

about the cover illustration
The figure on the cover of Java 2 Micro Edition is a "Muger Arabe Azanaghi,” an
Azanaghi Arab Woman from a region in the northernmost section of present-day
Mauritania. The illustration is taken from a Spanish compendium of regional dress
customs first published in Madrid in 1799. The book’s title page states:
Coleccion general de los Trages que usan actualmente todas las Nacionas del Mundo
desubierto, dibujados y grabados con la mayor exactitud por R.M.V.A.R. Obra muy
util y en special para los que tienen la del viajero universal
Which we translate, as literally as possible, thus:
General collection of costumes currently used in the nations of the known world,
designed and printed with great exactitude by R.M.V.A.R. This work is very useful
especially for those who hold themselves to be universal travelers
Although nothing is known of the designers, engravers, and workers who colored this
illustration by hand, the “exactitude” of their execution is evident in this drawing.
The Azanaghi Arab Woman is of course just one of many figures in this colorful collection. Their diversity speaks vividly of the uniqueness and individuality of the
world’s towns and regions just 200 years ago. This was a time when the dress codes of
two regions separated by a few dozen miles identified people uniquely as belonging to
one or the other. The collection brings to life a sense of isolation and distance of that
period—and of every other historic period except our own hyperkinetic present.
Dress codes have changed since then and the diversity by region, so rich at the time,
has faded away. It is now often hard to tell the inhabitant of one continent from

another. Perhaps, trying to view it optimistically, we have traded a cultural and visual
diversity for a more varied personal life. Or a more varied and interesting intellectual
and technical life.
We at Manning celebrate the inventiveness, the initiative and the fun of the computer business with book covers based on the rich diversity of regional life of two centuries ago‚ brought back to life by the pictures from this collection.

xxiii

www.it-ebooks.info


WH_Java2.book Page xxiv Monday, March 4, 2002 9:59 AM

www.it-ebooks.info


WH_Java2.book Page 1 Monday, March 4, 2002 9:59 AM

P A

R T

1

Developing with J2ME
T

he first part of this book focuses on introducing the Java 2 Micro Edition.
Chapter 1 describes how J2ME fits into the larger picture of the Java 2 platform. The
case for why J2ME is necessary and useful is discussed as well as the origins from
which J2ME has sprung. The second chapter describes how J2ME is put together.

This provides a context for how J2ME might be used to develop applications for consumer electronics and Internet appliances. Chapter 2 also provides a comprehensive,
yet high-level tour of J2ME. Finally, before delving into the particulars of developing
J2ME applications, chapter 3 provides a quick introduction to the development environments, covering the particulars of how to obtain various J2ME development tools
and technologies as well as describing the example application that will be used
throughout the book.

www.it-ebooks.info


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×