J2ME: the Complete Reference
Total Page:16
File Type:pdf, Size:1020Kb
Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 Blind Folio i J2ME: The Complete Reference James Keogh McGraw-Hill/Osborne New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:46 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 / Front Matter Blind Folio FM:ii McGraw-Hill/Osborne 2600 Tenth Street Berkeley, California 94710 U.S.A. To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact McGraw-Hill/Osborne at the above address. For information on translations or book distributors outside the U.S.A., please see the International Contact Information page immediately following the index of this book. J2ME: The Complete Reference Copyright © 2003 by The McGraw-Hill Companies. All rights reserved. Printed in the United States of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. 1234567890 CUS CUS 019876543 ISBN 0-07-222710-9 Publisher Copy Editor Brandon A. Nordin Judith Brown Vice President & Associate Publisher Proofreader Scott Rogers Claire Splan Editorial Director Indexer Wendy Rinaldi Jack Lewis Project Editor Computer Designers Mark Karmendy Apollo Publishing Services, Lucie Ericksen, Tara A. Davis Acquisitions Coordinator Athena Honore Illustrators Michael Mueller, Lyssa Wald, Technical Editor Melinda Moore Lytle Amar Mehta Series Design Peter F. Hancik This book was composed with Corel VENTURA™ Publisher. Information has been obtained by McGraw-Hill/Osborne from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill/Osborne, or others, McGraw-Hill/Osborne does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information. P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:47 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 Blind Folio iii This book is dedicated to Anne, Sandy, Joanne, Amber-Leigh Christine, and Graaf, without whose help and support this book couldn’t be written. P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:47 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 / Front Matter Blind Folio FM:iv About the Author Jim Keogh teaches courses on Java Application Development, including J2EE, at Columbia University and is a member of the Java Community Process Program. He developed the first e-commerce track at Columbia and became its first chairperson. Jim spent more than a decade developing advanced systems for major Wall Street firms. Jim introduced PC Programming nationally in his Popular Electronics Magazine column in 1982, four years after Apple Computer started in a garage. He was also a team member who built one of the first Windows applications by a Wall Street firm, featured by Bill Gates in 1986. Jim is the author of 55 books, including his most recent book, J2EE: The Complete Reference. He is also a faculty member in the Graduate School, Saint Peter’s College, New Jersey City, NJ. P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:47 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 / Front Matter FM:v Contents Introduction . xv Part I J2ME Basics 1 J2ME Overview . 3 Java 2 Micro Edition and the World of Java . 4 Enter Java . 5 Java Virtual Machine . 6 J2EE and J2SE . 6 The Birth of J2EE . 8 Back to the Future: J2ME . 8 Inside J2ME . 9 How J2ME Is Organized . 12 J2ME and Wireless Devices . 14 What J2ME Isn’t . 15 Other Java Platforms for Small Computing Devices . 16 v P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:47 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 / Front Matter vi J2ME: The Complete Reference 2 Small Computing Technology . 17 Wireless Technology . 18 Radio Transmission . 20 Limitations of Radio Transmissions . 20 Radio Data Networks . 22 Data Packets . 23 Microwave Technology . 24 Satellite Networks . 24 Mobile Radio Networks . 25 Cellular Telephone Networks . 26 Digital Wireless Transmissions . 28 Cell Phones and Text Input . 28 Messaging . 29 Personal Digital Assistants . 30 Mobile Power . 31 Set-Top Boxes . 32 Inside Look at a Set-Top Box . 33 Smart Cards . 34 3 J2ME Architecture and Development Environment . 35 J2ME Architecture . 36 Small Computing Device Requirements . 37 Run-Time Environment . 37 Inside the Java Archive File . 38 Inside the Java Application Descriptor File . 40 MIDlet Programming . 42 Event Handling . 43 User Interfaces . 44 Device Data . 44 Java Language for J2ME . 45 J2ME Software Development Kits . 48 Hello World J2ME Style . 50 Compiling Hello World . 53 Running Hello World . 54 Deploying Hello World . 54 What to Do When Your MIDlet Doesn’t Work Properly . 56 Multiple MIDlets in a MIDlet Suite . 57 J2ME Wireless Toolkit . 60 Building and Running a Project . 61 Hello World Project . 64 MIDlets on the Internet . 67 P:\010Comp\CompRef8\710-9\fm.vp Friday, February 07, 2003 1:49:47 PM Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / J2ME: TCR / Keogh / 222710-9 / Front Matter Contents vii 4 J2ME Best Practices and Patterns . 71 The Reality of Working in a J2ME World . 72 Best Practices . 73 Keep Applications Simple . 73 Keep Applications Small . 74 Limit the Use of Memory . 75 Off-Load Computations to the Server . 76 Manage Your Application’s Use of a Network Connection . 77 Simplify the User Interface . 79 Use Local Variables . 81 Don’t Concatenate Strings . 81 Avoid Synchronization . 82 Thread Group Class Workaround . 83 Upload Code from the Web Server . 83 Reading Settings from JAD Files . 84 Populating Drop-down Boxes . 85 Minimize Network Traffic . 86 Dealing with Time . 86 Automatic Data Synchronization . 88 Updating Data that Has Changed . 89 Be Careful of the Content of the startApp() Method . 90 Part II J2ME User Interface 5 Commands, Items, and Event Processing . 95 J2ME User Interfaces . 96 Display Class . 96 The Palm OS Emulator . 102 Command Class . 103 CommandListener . 105 Item Class . 111 Item Listener . 114 Exception Handling . ..