Sams Teach Yourself Wireless Java with J2ME in 21 Days with Cdrom

Sams Teach Yourself Wireless Java with J2ME in 21 Days with Cdrom

by Michael Morrison

Multimedia Set(BK&CD-ROM)


Product Details

ISBN-13: 9780672321429
Publisher: Pearson Education
Publication date: 07/10/2001
Series: Sams Teach Yourself Series
Edition description: BK&CD-ROM
Pages: 576
Product dimensions: 7.35(w) x 9.10(h) x 1.37(d)

About the Author

Michael Morrison is a writer, developer, toy inventor, and author of a variety of books including The Unauthorized Guide to Pocket PCs (Que Publishing, 2000), Java In Plain English 3rd Edition (IDG Books, 2000), XML Unleashed (Sams Publishing, 1999), and Complete Idiot's Guide to Java 2 (Que Publishing, 1999). Michael is the instructor of several Web-based courses including DigitalThink's Introduction to Java 2 series, JavaBeans for Programmers series, and Win32 Fundamentals series. Michael also serves as a technical director for ReviewNet, a company that provides Web-based staffing tools for information technology personnel. Finally, Michael is the creative lead at Gas Hound Games, a toy company he co-founded that is located on the Web at

When not risking life and limb on his skateboard or mountain bike, trying to avoid the penalty box in hockey, or watching movies with his wife, Masheed, Michael enjoys daydreaming next to his koi pond. You can visit Michael on the Web at http: //www. He also encourages you to check out his board game, Inc. The Game of Business, at http: //

Read an Excerpt

Day 1: Java 2 Micro Edition: The Big Picture

At one time Java was simply a programming language with a slant toward the Internet. Although that meaning certainly still holds true, it's easy to get lost in the many Java technologies that have arisen from the humble beginnings of a simple net-centric programming language. Java has grown by leaps and bounds and has reached far beyond its initial purpose of enabling network devices. It is interesting-and not necessarily coincidental-that Java is now returning to its early roots with J2ME, which stands for Java 2 Micro Edition. Because this book is essentially a guide to using J2ME to construct wireless applications, it makes sense to begin with a clear explanation of what J2ME is and is not. Please understand that this book assumes a fundamental knowledge of Java, so this first lesson jumps directly into J2ME and how it applies Java to wireless devices.

Today you explore the architecture of J2ME and how it relates to the other two main Java technologies, J2SE (Standard Edition) and J2EE (Enterprise Edition). You also learn about how J2ME is organized, along with the specific types of mobile devices targeted by it. More specifically, the following topics are covered in this introduction to J2ME:

  • Assessing the role of Java in the wireless world
  • Understanding J2ME and how it relates to other Java technologies
  • Examining the architecture of J2ME through configurations and profiles
  • Learning the two most important wireless J2ME acronyms: CLDC and MIDP

Java Without Wires

Before computers invaded Hollywood and led us to take for granted the ingenuity and craftiness that went into special effects, I can remember watching movies and trying to figure out how certain effects were carried out. One such effect was an object floating in the air, which was often created by gluing a wire to the object and suspending it from above. Although this effect might have fooled less sophisticated audiences in the early days of special effects, it wouldn't fly at all now. What does this have to do with Java and wireless computing? In the very near future the concept of a wire tethered to a mobile computer will seem just as "hokey" as the floating "flying saucers" in an Ed Wood movie.

The concept of a truly wireless mobile computer is new to the vast majority of computer users. We might have already become accustomed to wireless mobile phones, but the idea of being able to connect to the Internet in a similar fashion is something with ramifications we've yet to fully realize. The vast majority of us are still accustomed to plugging a modem into a phone jack to connect to the Internet remotely. It's pretty obvious that being able to check e-mail and surf the Web is very beneficial in a wireless scenario. Whether you're a business traveler connecting to a corporate intranet while waiting in an airport terminal or a restless author of a computer book looking for deals on eBay while in a dentist's waiting room, connecting to the Internet wirelessly is a process that we could all use in one way or another. However, e-mail and Web clients are only the beginning. Even with their limited processing power and small screens, it is now possible to develop interactive software for mobile devices that takes advantage of the wireless network connection.

Not surprisingly, Java is the technology that is making it possible to build custom, interactive software for wireless mobile devices. This is interesting because it brings Java full circle to its original purpose. As I mentioned at the opening of this chapter, Java originally began as a programming language that enabled networked devices to communicate with each other. More specifically, Java started out as a project at Sun with people studying how to put computers into everyday household items. One primary focus of the project was to have these computerized devices communicate with each other. As it played out, Sun was a little ahead of its time in applying Java to network everyday devices. However, the company was quick to react and ended up making Java a huge success by targeting it for the Web.

Now that technology and public perception have caught up with Java's earlier aspirations, Sun has gone back to the drawing board and retooled Java for the mobile computing domain. Not only is a version of Java now designed for the constraints of mobile devices, but this version is also well suited for wireless networking. This version of Java is known as J2ME, which stands for Java 2 Micro Edition. You learn more details about how J2ME fits into the existing Java framework in the next section titled "What is J2ME?" For now, let's continue a little further into the discussion of how Java fits into the wireless world.

You might wonder what exactly constitutes a wireless mobile device. Existing devices that are either already wireless or about to acquire wireless functionality include mobile phones, pagers, personal digital assistants (PDAs), and pocket computers. Although it isn't necessarily new for devices such as mobile phones and pagers to include wireless network functionality, it is very significant that many of them are now supporting Java. By saying that a wireless device supports Java, I mean the device includes a Java virtual machine that is capable of running Java programs. As you learn later in this chapter, these Java programs are a little different from traditional Java applets and applications in that they are designed to run within the limited hardware and software configurations of mobile devices. Figure 1.1 shows the Motorola i2000 mobile phone with built-in Java support....

Table of Contents

Part IGetting Started with J2ME and MIDP7
Day 1Java 2 Micro Edition: The Big Picture9
Java Without Wires10
What is J2ME?13
J2ME and Other Wireless Technologies14
Configurations and the CLDC16
The MID Profile (MIDP)19
Day 2Assembling a J2ME Development Kit25
A J2ME Development Primer26
Inside the J2ME Wireless Toolkit29
Visual J2ME Development Environments33
J2ME Web Servers36
Day 3Getting to Know the J2ME Emulator41
J2ME Emulator Essentials42
Emulating Physical Devices44
Running the Emulator from the Command Line45
Running the Emulator Within a Visual Environment56
Day 4Building Your First MIDlet63
What Is a MIDlet?64
Inside a MIDlet65
MIDlet Development Revisited67
A Painfully Simple MIDlet68
Building and Testing the Howdy MIDlet with KToolBar79
Day 5Working within the CLDC and MIDP APIs85
MIDlet Programming: A Tale of Two APIs86
Putting the APIs to Use97
The SysInfo MIDlet99
Day 6Creating Custom Device Profiles105
Understanding Device Profiles106
Using the Configuration Editor107
Tweaking a Device Profile118
Testing a Custom Device Profile120
Part IIDigging Deeper into MIDlet Development125
Day 7Building Graphical MIDlet127
The MIDP Graphics Coordinate System128
A Quick Color Primer129
The Graphics Class131
Building Your First Graphical MIDlet139
Building a Slide Show MIDlet143
Day 8Making the Most of MIDlet GUIs151
Getting to Know the Display152
Working with Screens and Forms154
Assessing the MIDP GUI Components158
Using Commands175
The Mortgage Sample MIDlet178
Day 9Exploring MIDlet I/O and Networking189
Inside MIDP Networking190
Understanding MIDlet I/O193
Communicating Across Network Connections196
The Fortune Example MIDlet198
Testing the Fortune MIDlet208
Day 10Being Your Own Wireless Meteorologist213
Weather and the Web214
Peeking Inside a Weather Web Page217
Constructing the Weather MIDlet221
Testing the Weather MIDlet232
Day 11Wireless Navigation237
Using the Web to Get From A to B238
Ripping Apart a Driving Directions Web Page243
Constructing the Directions MIDlet248
Testing the Directions MIDlet259
Day 12Optimizing MIDlet Code265
MIDlet Optimization Basics266
MIDlet Optimization Tips268
Java Optimization Techniques271
Putting MIDlet Optimization into Perspective274
Part IIIWireless Information Management with MIDlets279
Day 13Using the MIDP Record Management System (RMS)281
What Is the MIDP Record Management System (RMS)?282
Inside the RMS Package283
Working with Record Stores285
The ToDoList Sample MIDlet289
Day 14Staying in Touch with Your Contacts311
Managing Contacts on the Go312
Constructing the Contacts MIDlet313
Testing the Contacts MIDlet331
Day 15Managing Your Finances339
Tracking Your Mobile Spending340
Building the CheckRegister MIDlet341
Testing the CheckRegister MIDlet365
Day 16Bidding on the Go373
Keeping Up with Online Auctions from Afar374
Constructing the Auction Watch MIDlet377
Testing the Auction Watch MIDlet396
Part IVEntertainment without the Wires401
Day 17Creating Animated MIDlets403
What Is Animation?404
Types of Animation405
Implementing Sprite Animation409
The Atoms Sample MIDlet427
Day 18An Ode to Pong: Creating MIDlet Games437
Designing Traveling Gecko438
Constructing Traveling Gecko440
Testing Traveling Gecko456
Day 19The Next Level of MIDlet Gaming461
A Crash Course in Game AI462
Designing Connect4465
Constructing Connect4469
Testing Connect4488
Part VExploring J2ME Wireless Technologies491
Day 20A J2ME Wireless Tour493
Exploring J2ME Devices494
Assessing the J2ME Application Landscape502
Day 21The Future of J2ME509
The CLDC Is Not Alone510
The Convergence of J2ME and Other Java Technologies511
J2ME: A Gadget Lover's Dream514
Gaming with J2ME516
J2ME and Multimedia517
Part VIAppendixes521
AQuiz Answers523
BWhat's on the CD-ROM531
Sample Source Code531
J2ME Tools532

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews