Part Ⅰ:Core Java APIs 3
Chapter 1—Java Basics 3
Hello World 3
FizzBuzz 7
The Fibonacci Series 10
Using Command-Line Arguments 10
Echo in Reverse 11
FizzBuzz Switched 12
Computing Factorials 13
Recursive Factorials 14
Caching Factorials 15
Preface 15
Computing Big Factorials 16
Handling Exceptions 17
Interactive Input 18
Using a StringBuffer 19
Sorting Numbers 21
Computing Primes 22
Exercises 23
Chapter 2—Objects,Classes,and Interfaces 24
A Rectangle Class 25
Testing the Rect Class 26
Another Subclass 27
A Rect Subclass 27
Complex Numbers 28
Computing Pseudo-Random Numbers 30
Computing Statistics 32
A Linked List Class 33
Advanced Sorting 36
Exercises 42
Chapter 3—Input/Output 44
Files and Streams 44
Working with Files 48
Copying File Contents 49
Reading and Displaying Text Files 52
Listing Directory and File Information 55
Compressing Files and Directories 60
Filtering Character Streams 62
Filtering Lines of Text 64
A Custom HTML Output Stream 65
Exercises 68
Chapter 4—Threads 70
Thread Basics 71
Threads and Thread Groups 72
Deadlock 75
Timers 77
Exercises 82
Downloading the Contents of a URL 84
Chapter 5—Networking 84
Using a URLConnection 86
Sending Email Through a URLConnection 87
Connecting to a Web Server 89
A Simple Web Server 91
A Proxy Server 93
Networking with Applets 96
A Generic Client 99
A Generic Multithreaded Server 101
A Multithreaded Proxy Server 113
Sending Datagrams 116
Receiving Datagrams 117
Exercises 119
Chapter 6—Security and Cryptography 121
Running Untrusted Code 122
Loading Untrusted Code 123
Message Digests and Digital Signatures 128
Cryptography 136
Exercises 139
Chapter 7—Internationalization 141
A Word About Locales 141
Unicode 142
Character Encodings 146
Handling Local Customs 148
Localizing User-Visible Messages 151
Formatted Messages 156
Exercises 159
Chapter 8—Reflection 161
Obtaining Class and Member Information 161
Invoking a Named Method 164
Exercises 168
Chapter 9—Object Serialization 169
Simple Serialization 169
Custom Serialization 172
Externalizable Classes 174
Serialization and Class Versioning 176
Serialized Applets 177
Exercises 178
Part Ⅱ:Graphics and GUIs 181
Chapter 10—Graphical User Interfaces 181
Components 183
Containers 189
Layout Management 190
Event Handling 203
A Complete GUI 217
Actions and Reflection 221
Custom Dialogs 222
Displaying Tables 227
Displaying Trees 230
A Simple Web Browser 234
Describing GUIs with Properties 242
Themes and the Metal Look-and-Feel 253
Custom Components 257
Exercises 263
Chapter 11—Graphics 266
Graphics Before Java 1.2 267
The Java 2D API 276
Drawing and Filling Shapes 277
Transforms 279
Line Styles with BasicStroke 281
Stroking Lines 283
Filling Shapes with Paint 284
Antialiasing 287
Combining Colors with AlphaComposite 289
Image Processing 292
A Custom Shape 295
Custom Strokes 299
Custom Paint 303
Advanced Animation 305
Displaying Graphics Examples 308
Exercises 312
Printing with the Java 1.1 API 314
Chapter 12—Printing 314
Printing with the Java 1.2 API 316
Printing Multipage Text Documents 319
Printing Swing Documents 327
Exercises 333
Chapter 13—Data Transfer 334
Data Transfer Architecture 334
Simple Copy-and-Paste 335
A Transferable Data Type 338
Cutting and Pasting Scribbles 344
Dragging and Dropping Scribbles 347
Exercises 353
Chapter 14—JavaBeans 354
Bean Basics 355
A Simple Bean 356
A More Complex Bean 360
Custom Events 364
Specifying Bean Information 365
Defining a Simple Property Editor 367
Defining a Complex Property Editor 369
Defining a Bean Customizer 371
Exercises 374
Chapter 15—Applets 375
Introduction to Applets 375
A First Applet 377
A Clock Applet 378
Applets and the Java 1.0 Event Model 380
Java 1.0 Event Details 383
Reading Applet Parameters 385
Images and Sounds 387
JAR Files 391
Exercises 392
Part Ⅲ:Enterprise Java 395
Chapter 16—Remote Method Invocation 395
Remote Banking 396
A Bank Server 400
A Multiuser Domain 404
Remote MUD Interfaces 405
The MUD Server 408
The MudPlace Class 411
The MudPerson Class 418
A MUD Client 420
Advanced RMI 428
Exercises 429
Chapter 17—Database Access with SQL 431
Accessing a Database 432
Using Database Metadata 438
Building a Database 441
Using the API Database 446
Atomic Transactions 450
Exercises 456
Chapter 18—Servlets and JSP 458
Servlet Setup 458
A Hello World Servlet 461
Servlet Initialization and Persistence:A Counter Servlet 463
Database Access with Servlets 467
A Login Screen with JSP 471
Request Forwarding 476
JSP Pages and JavaBeans 477
Ending a User Session 482
Custom Tags 483
Deploying a Web Application 488
Exercises 492
Chapter 19—XML 494
Parsing with JAXP and SAX 1 494
Parsing with SAX 2 499
Parsing and Manipulating with JAXP and DOM 502
Traversing a DOM Tree 506
Traversing a Document with DOM Level 2 508
The JDOM API 512
Exercises 514
Chapter 20—Example Index 516
Index 535