OReilly.J2ME.in a Nutshell.pdf

(5878 KB) Pobierz
J2ME in a Nutshell
15339068.001.png
J2ME in a Nutshell
Kim Topley
Publisher: O'Reilly
Edition March 2002
ISBN: 0-596-00253-X, 478 pages
J2ME in a Nutshell provides a solid, no-nonsense reference to the 'alphabet soup' of micro
edition programming, covering the CLDC, CDC, KVM and MIDP APIs. The book also
includes tutorials for the CLDC, KVM, MIDP and MIDlets, MIDlet user interfaces,
networking and storage, and advice on programming small handhelds. Combined with
O'Reilly's classic quick reference to all the core micro-edition APIs, this is the one book that
will take you from curiosity to code with no frustrating frills in between.
Table of Contents
Preface .....................................................
Contents of This Book ..........................................
Related Books ................................................
J2ME Programming Resources Online ................................
Examples Online ..............................................
Conventions Used in This Book ....................................
Request for Comments ..........................................
Acknowledgments .............................................
1
1
3
4
5
5
6
6
I: Introduction to the Java 2 Micro Edition Platform API ..................
8
1. Introduction ................................................
1.1 What Is the J2ME Platform? ....................................
1.2 J2ME Specifications .........................................
1.3 J2ME and Other Java Platforms ..................................
9
9
14
14
2. The Connected Limited Device Configuration ........................
2.1 The CLDC Java Virtual Machine .................................
2.2 The CLDC Class Libraries .....................................
2.3 KVM Debugging ...........................................
2.4 Advanced KVM Topics .......................................
16
16
24
32
37
3. The Mobile Information Device Profile and MIDlets ....................
3.1 MIDP Overview ............................................
3.2 The MIDP Java Platform ......................................
3.3 MIDlets and MIDlet Suites .....................................
3.4 MIDlet Execution Environment and Lifecycle ........................
3.5 Developing MIDlets .........................................
3.6 Delivery and Installation of MIDlets ..............................
47
47
51
51
57
62
76
4. MIDlet User Interfaces ........................................
4.1 User Interface Overview ......................................
4.2 The High-Level User Interface API ...............................
84
84
88
5. The Low-Level MIDlet User Interface API ...........................
5.1 The Canvas Class ...........................................
5.2 Painting and the Graphics Class ..................................
5.3 Graphics Attributes ..........................................
5.4 Drawing Lines and Arcs .......................................
5.5 Translating the Graphics Origin ..................................
5.6 A Simple Animation MIDlet ....................................
5.7 The Graphics Clip ...........................................
5.8 Rendering Text ............................................
5.9 Images ..................................................
5.10 Event Handling ...........................................
5.11 Multithreading and the User Interface .............................
139
139
143
144
147
153
155
158
161
166
171
176
6. Wireless Java: Networking and Persistent Storage .....................
6.1 A Networking Architecture for Small Devices ........................
6.2 Sockets ..................................................
6.3 Datagrams ................................................
6.4 HTTP Connections ..........................................
6.5 Persistent Storage ...........................................
179
179
183
187
192
207
7. The Connected Device Configuration and Its Profiles ...................
7.1 The CDC ................................................
227
227
8. J2ME Command-Line Tools .....................................
8.1 cvm: The Connected Device Configuration Virtual Machine ...............
8.2 kdp: The KVM Debug Proxy ...................................
8.3 kvm: The Kilobyte Virtual Machine ...............................
8.4 midp: The MID Profile Execution Environment .......................
8.5 emulator: The J2ME Wireless Toolkit Emulator .......................
8.6 preverify: The KVM Class Preverifier .............................
8.7 MakeMIDPApp: JAD to PRC Conversion Tool .......................
8.8 chMEKeyTool: Public Key Certificate Management Tool ................
239
239
244
246
250
254
258
261
264
9. J2ME Programming Environments ................................
9.1 The J2ME Wireless Toolkit ....................................
9.2 MIDP for PalmOS ..........................................
9.3 J2ME and Forte For Java ......................................
9.4 Other Integrated Development Environments .........................
267
267
281
291
296
II: API Quick Reference .........................................
298
10. J2ME Packages and Classes ....................................
10.1 J2ME Packages ...........................................
10.2 J2SE Packages Not Present in J2ME ..............................
10.3 J2ME Package Contents ......................................
308
308
309
310
11. java.io ...................................................
Package java.io ...............................................
ByteArrayInputStream ..........................................
ByteArrayOutputStream .........................................
DataInput ...................................................
DataInputStream ..............................................
DataOutput ..................................................
DataOutputStream .............................................
EOFException ...............................................
InputStream .................................................
InputStreamReader ............................................
InterruptedIOException .........................................
IOException .................................................
OutputStream ................................................
OutputStreamWriter ............................................
PrintStream .................................................
Reader .....................................................
UnsupportedEncodingException ....................................
UTFDataFormatException .......................................
Writer .....................................................
325
325
325
327
327
328
329
330
331
332
333
334
334
335
336
337
338
339
339
339
12. java.lang ..................................................
Package java.lang .............................................
ArithmeticException ...........................................
ArrayIndexOutOfBoundsException ..................................
ArrayStoreException ...........................................
Boolean ....................................................
Byte ......................................................
Character ...................................................
Class ......................................................
ClassCastException ............................................
ClassNotFoundException ........................................
341
341
342
343
343
343
344
345
346
347
347
Error ......................................................
Exception ...................................................
IllegalAccessException ..........................................
IllegalArgumentException ........................................
IllegalMonitorStateException ......................................
IllegalStateException ...........................................
IllegalThreadStateException ......................................
IndexOutOfBoundsException .....................................
InstantiationException ..........................................
Integer .....................................................
InterruptedException ...........................................
Long ......................................................
Math ......................................................
NegativeArraySizeException ......................................
NullPointerException ...........................................
NumberFormatException ........................................
Object .....................................................
OutOfMemoryError ............................................
Runnable ...................................................
Runtime ....................................................
RuntimeException .............................................
SecurityException .............................................
Short ......................................................
String .....................................................
StringBuffer .................................................
StringIndexOutOfBoundsException .................................
System ....................................................
Thread .....................................................
Throwable ..................................................
VirtualMachineError ...........................................
348
348
349
349
350
350
351
351
352
352
353
354
355
355
356
356
356
358
358
359
359
360
360
361
363
365
366
367
368
369
13. java.util ..................................................
Package java.util ..............................................
Calendar ...................................................
Date ......................................................
EmptyStackException ..........................................
Enumeration .................................................
Hashtable ...................................................
NoSuchElementException ........................................
Random ....................................................
Stack ......................................................
Timer .....................................................
TimerTask ..................................................
TimeZone ..................................................
Vector .....................................................
370
370
371
373
374
374
375
376
376
377
378
379
379
380
14. javax.microedition.io .........................................
Package javax.microedition.io .....................................
Connection ..................................................
ConnectionNotFoundException ....................................
Connector ..................................................
ContentConnection ............................................
Datagram ...................................................
DatagramConnection ...........................................
HttpConnection ...............................................
InputConnection ..............................................
OutputConnection .............................................
StreamConnection .............................................
383
383
384
385
385
387
388
389
391
393
394
394
Zgłoś jeśli naruszono regulamin