| Preface |
|
xix | |
| To the Reader |
|
xix | |
| About This Book |
|
xxi | |
| Conventions |
|
xxiii | |
| CD-ROM |
|
xxiv | |
| Acknowledgments |
|
xxv | |
|
|
|
1 | (18) |
|
Java as a Programming Tool |
|
|
2 | (1) |
|
|
|
3 | (1) |
|
The Java ``White Paper'' Buzzwords |
|
|
4 | (6) |
|
|
|
5 | (1) |
|
|
|
5 | (1) |
|
|
|
6 | (1) |
|
|
|
6 | |
|
|
|
5 | (3) |
|
|
|
8 | (1) |
|
|
|
8 | (1) |
|
|
|
9 | (1) |
|
|
|
9 | (1) |
|
|
|
10 | (1) |
|
|
|
10 | (1) |
|
|
|
10 | (3) |
|
|
|
11 | (1) |
|
|
|
12 | (1) |
|
|
|
13 | (2) |
|
Common Misconceptions About Java |
|
|
15 | (4) |
|
The Java Programming Environment |
|
|
19 | (24) |
|
Installing the Java Software Development Kit |
|
|
20 | (4) |
|
Setting the Execution Path |
|
|
20 | (1) |
|
Installing the Library Source and Documentation |
|
|
21 | (1) |
|
Installing the Core Java Program Examples |
|
|
22 | (1) |
|
Navigating the Java Directories |
|
|
23 | (1) |
|
|
|
24 | (1) |
|
Using the Command Line Tools |
|
|
25 | (2) |
|
|
|
26 | (1) |
|
Using an Integrated Development Environment |
|
|
27 | (3) |
|
Locating Compilation Errors |
|
|
29 | (1) |
|
Compiling and Running Programs from a Text Editor |
|
|
30 | (4) |
|
|
|
34 | (3) |
|
|
|
37 | (6) |
|
Fundamental Programming Structures in Java |
|
|
43 | (68) |
|
|
|
44 | (3) |
|
|
|
47 | (1) |
|
|
|
48 | (3) |
|
|
|
48 | (1) |
|
|
|
49 | (1) |
|
|
|
50 | (1) |
|
|
|
51 | (1) |
|
|
|
51 | (1) |
|
Assignments and Initializations |
|
|
52 | (2) |
|
|
|
53 | (1) |
|
|
|
54 | (8) |
|
Increment and Decrement Operators |
|
|
56 | (1) |
|
Relational and boolean Operators |
|
|
56 | (1) |
|
|
|
57 | (1) |
|
Mathematical Functions and Constants |
|
|
58 | (1) |
|
Conversions Between Numeric Types |
|
|
59 | (1) |
|
|
|
60 | (1) |
|
Parentheses and Operator Hierarchy |
|
|
61 | (1) |
|
|
|
62 | (12) |
|
|
|
62 | (1) |
|
|
|
62 | (1) |
|
|
|
63 | (2) |
|
Testing Strings for Equality |
|
|
65 | (2) |
|
Reading the On-line API Documentation |
|
|
67 | (2) |
|
|
|
69 | (2) |
|
|
|
71 | (3) |
|
|
|
74 | (19) |
|
|
|
75 | (1) |
|
|
|
75 | (4) |
|
|
|
79 | (5) |
|
|
|
84 | (4) |
|
Multiple Selections---the switch Statement |
|
|
88 | (2) |
|
|
|
90 | (3) |
|
|
|
93 | (2) |
|
|
|
95 | (16) |
|
Array Initializers and Anonymous Arrays |
|
|
96 | (1) |
|
|
|
97 | (2) |
|
|
|
99 | (1) |
|
|
|
100 | (3) |
|
|
|
103 | (3) |
|
|
|
106 | (5) |
|
|
|
111 | (70) |
|
Introduction to Object-Oriented Programming |
|
|
112 | (8) |
|
|
|
113 | (1) |
|
|
|
114 | (2) |
|
Relationships Between Classes |
|
|
116 | (2) |
|
Contrasting OOP with Traditional Procedural Programming Techniques |
|
|
118 | (2) |
|
|
|
120 | (11) |
|
Objects and Object Variables |
|
|
120 | (3) |
|
The GregorianCalendar Class of the Java Library |
|
|
123 | (8) |
|
Building Your Own Classes |
|
|
131 | (11) |
|
|
|
131 | (3) |
|
Using Multiple Source Files |
|
|
134 | (1) |
|
Analyzing the Employee Class |
|
|
135 | (1) |
|
First Steps with Constructors |
|
|
135 | (2) |
|
The Methods of the Employee Class |
|
|
137 | (3) |
|
Method Access to Private Data |
|
|
140 | (1) |
|
|
|
141 | (1) |
|
|
|
142 | (1) |
|
Static Fields and Methods |
|
|
142 | (6) |
|
|
|
142 | (1) |
|
|
|
143 | (1) |
|
|
|
144 | (1) |
|
|
|
145 | (1) |
|
|
|
145 | (3) |
|
|
|
148 | (7) |
|
|
|
155 | (9) |
|
|
|
155 | (1) |
|
Default Field Initialization |
|
|
156 | (1) |
|
|
|
157 | (1) |
|
Explicit Field Initialization |
|
|
157 | (1) |
|
|
|
158 | (1) |
|
Calling Another Constructor |
|
|
159 | (1) |
|
|
|
159 | (4) |
|
Object Destruction and the finalize Method |
|
|
163 | (1) |
|
|
|
164 | (9) |
|
|
|
164 | (9) |
|
|
|
173 | (4) |
|
|
|
173 | (1) |
|
|
|
174 | (1) |
|
|
|
174 | (1) |
|
|
|
175 | (1) |
|
|
|
175 | (1) |
|
Package and Overview Comments |
|
|
176 | (1) |
|
|
|
177 | (1) |
|
|
|
177 | (4) |
|
|
|
181 | (70) |
|
|
|
182 | (21) |
|
|
|
189 | (1) |
|
|
|
190 | (1) |
|
|
|
191 | (2) |
|
Preventing Inheritance: Final Classes and Methods |
|
|
193 | (1) |
|
|
|
194 | (3) |
|
|
|
197 | (5) |
|
|
|
202 | (1) |
|
Object: The Cosmic Superclass |
|
|
203 | (21) |
|
The equals and toString methods |
|
|
204 | (7) |
|
|
|
211 | (2) |
|
|
|
213 | (7) |
|
|
|
220 | (4) |
|
|
|
224 | (4) |
|
|
|
228 | (19) |
|
Using Reflection to Analyze the Capabilities of Classes |
|
|
228 | (5) |
|
Using Reflection to Analyze Objects at Run Time |
|
|
233 | (7) |
|
Using Reflection to Write Generic Array Code |
|
|
240 | (3) |
|
|
|
243 | (4) |
|
Design Hints for Inheritance |
|
|
247 | (4) |
|
Interfaces and Inner Classes |
|
|
251 | (44) |
|
|
|
252 | (10) |
|
|
|
257 | (1) |
|
Interfaces and Abstract Classes |
|
|
258 | (1) |
|
|
|
259 | (3) |
|
|
|
262 | (6) |
|
|
|
268 | (19) |
|
Using an Inner Class to Access Object State |
|
|
270 | (4) |
|
Special Syntax Rules for Inner Classes |
|
|
274 | (1) |
|
Are Inner Classes Useful? Are They Actually Necessary? Are They Secure? |
|
|
275 | (3) |
|
|
|
278 | (5) |
|
|
|
283 | (4) |
|
|
|
287 | (8) |
|
Properties of Proxy Classes |
|
|
292 | (3) |
|
|
|
295 | (52) |
|
|
|
296 | (3) |
|
|
|
299 | (4) |
|
|
|
303 | (6) |
|
Displaying Information in a Panel |
|
|
309 | (6) |
|
|
|
315 | (8) |
|
|
|
323 | (5) |
|
|
|
326 | (2) |
|
|
|
328 | (11) |
|
|
|
339 | (8) |
|
|
|
347 | (70) |
|
|
|
348 | (19) |
|
Example: Handling a button click |
|
|
351 | (6) |
|
Selecting Event Listeners |
|
|
357 | (4) |
|
Example: Changing the Look and Feel |
|
|
361 | (3) |
|
Example: Capturing Window Events |
|
|
364 | (3) |
|
|
|
367 | (3) |
|
Semantic and Low-Level Events in the AWT |
|
|
370 | (3) |
|
|
|
370 | (3) |
|
|
|
373 | (19) |
|
|
|
373 | (2) |
|
|
|
375 | (7) |
|
|
|
382 | (1) |
|
|
|
383 | (9) |
|
|
|
392 | (9) |
|
|
|
401 | (4) |
|
|
|
405 | (12) |
|
|
|
406 | (11) |
|
User Interface Components With Swing |
|
|
417 | (160) |
|
The Model-View-Controller Design Pattern |
|
|
418 | (7) |
|
A Model-View-Controller Analysis of Swing Buttons |
|
|
423 | (2) |
|
An Introduction to Layout Management |
|
|
425 | (6) |
|
|
|
427 | (2) |
|
|
|
429 | (2) |
|
|
|
431 | (26) |
|
|
|
431 | (7) |
|
|
|
438 | (9) |
|
|
|
447 | (1) |
|
|
|
448 | (4) |
|
Labels and Labeling Components |
|
|
452 | (2) |
|
|
|
454 | (1) |
|
|
|
455 | (2) |
|
|
|
457 | (23) |
|
|
|
457 | (3) |
|
|
|
460 | (5) |
|
|
|
465 | (5) |
|
|
|
470 | (3) |
|
|
|
473 | (7) |
|
|
|
480 | (22) |
|
|
|
481 | (3) |
|
|
|
484 | (1) |
|
Check Box and Radio Button Menu Items |
|
|
485 | (2) |
|
|
|
487 | (1) |
|
Keyboard Mnemonics and Accelerators |
|
|
488 | (3) |
|
Enabling and Disabling Menu Items |
|
|
491 | (5) |
|
|
|
496 | (2) |
|
|
|
498 | (4) |
|
Sophisticated Layout Management |
|
|
502 | (29) |
|
|
|
505 | (5) |
|
|
|
510 | (5) |
|
|
|
515 | (2) |
|
The gridx, gridy, gridwidth, and gridheight Parameters |
|
|
517 | (1) |
|
|
|
517 | (1) |
|
The fill and anchor Parameters |
|
|
518 | (1) |
|
|
|
518 | (1) |
|
An Alternative Method to Specify the gridx, gridy, gridwidth, and gridheight Parameters |
|
|
519 | (4) |
|
|
|
523 | (1) |
|
|
|
524 | (5) |
|
|
|
529 | (2) |
|
|
|
531 | (46) |
|
|
|
532 | (12) |
|
|
|
544 | (4) |
|
|
|
548 | (7) |
|
|
|
555 | (13) |
|
|
|
568 | (9) |
|
|
|
577 | (58) |
|
|
|
578 | (17) |
|
|
|
580 | (2) |
|
Running the Applet Viewer |
|
|
582 | (2) |
|
Viewing an Applet in a Browser |
|
|
584 | (4) |
|
Converting Applications to Applets |
|
|
588 | (2) |
|
|
|
590 | (2) |
|
|
|
592 | (1) |
|
Pop-Up Windows in Applets |
|
|
593 | (2) |
|
The Applet HTML Tags and Attributes |
|
|
595 | (14) |
|
Applet Attributes for Positioning |
|
|
596 | (2) |
|
Applet Attributes for Code |
|
|
598 | (3) |
|
Applet Attributes for Java-Challenged Viewers |
|
|
601 | (1) |
|
|
|
601 | (1) |
|
|
|
602 | (1) |
|
Passing Information to Applets |
|
|
603 | (6) |
|
|
|
609 | (3) |
|
|
|
609 | (1) |
|
Obtaining Multimedia Files |
|
|
610 | (2) |
|
|
|
612 | (11) |
|
Inter-Applet Communication |
|
|
612 | (1) |
|
Displaying Items in the Browser |
|
|
613 | (2) |
|
|
|
615 | (3) |
|
It's an Applet. It's an Application. It's is Both! |
|
|
618 | (5) |
|
|
|
623 | (12) |
|
|
|
625 | (2) |
|
|
|
627 | (1) |
|
|
|
628 | (1) |
|
|
|
628 | (5) |
|
|
|
633 | (1) |
|
|
|
634 | (1) |
|
|
|
635 | (58) |
|
|
|
636 | (8) |
|
The Classification of Exceptions |
|
|
637 | (2) |
|
Advertising the Exceptions That a Method Throws |
|
|
639 | (3) |
|
How to Throw an Exception |
|
|
642 | (1) |
|
Creating Exception Classes |
|
|
643 | (1) |
|
|
|
644 | (11) |
|
Catching Multiple Exceptions |
|
|
647 | (1) |
|
|
|
647 | (4) |
|
A Final Look at Java Error-and Exception-Handling |
|
|
651 | (4) |
|
Some Tips on Using Exceptions |
|
|
655 | (4) |
|
|
|
659 | (24) |
|
Useful Tricks for Debugging |
|
|
659 | (5) |
|
|
|
664 | (2) |
|
|
|
666 | (2) |
|
|
|
668 | (5) |
|
|
|
673 | (4) |
|
|
|
677 | (4) |
|
|
|
681 | (2) |
|
|
|
683 | (10) |
|
|
|
683 | (5) |
|
|
|
688 | (5) |
|
|
|
693 | (84) |
|
|
|
693 | (4) |
|
Reading and Writing Bytes |
|
|
694 | (3) |
|
|
|
697 | (20) |
|
|
|
699 | (5) |
|
|
|
704 | (3) |
|
Random-Access File Streams |
|
|
707 | (10) |
|
|
|
717 | (9) |
|
|
|
726 | (14) |
|
|
|
727 | (1) |
|
String Tokenizers and Delimited Text |
|
|
727 | (2) |
|
|
|
729 | (4) |
|
|
|
733 | (7) |
|
|
|
740 | (29) |
|
Storing Objects of Variable Type |
|
|
741 | (4) |
|
Object Serialization File Format |
|
|
745 | (4) |
|
The Problem of Saving Object References |
|
|
749 | (7) |
|
Output Format for Object References |
|
|
756 | (3) |
|
|
|
759 | (5) |
|
|
|
764 | (2) |
|
Using Serialization for Cloning |
|
|
766 | (3) |
|
|
|
769 | (8) |
| Appendix |
|
777 | (2) |
| Index |
|
779 | |