Preface | | vii | |
| | vii | |
| | viii | |
| | ix | |
| Conventions used in the book | | | ix | |
| | x | |
| | x | |
| | xi | |
| Basics of Java Programming | | | 1 | (19) |
| | 2 | (1) |
| | 2 | (2) |
| Declaring Members: Variables and Methods | | | 3 | (1) |
| | 4 | (2) |
| | 4 | (1) |
| | 5 | (1) |
| | 6 | (1) |
| | 6 | (1) |
| | 7 | (2) |
| | 9 | (2) |
| | 11 | (1) |
| | 11 | (3) |
| | 12 | (2) |
| | 14 | (1) |
| Sample Standalone Java Application | | | 14 | (2) |
| Main Elements of a Java Standalone Application | | | 14 | (1) |
| Compiling and Running a Standalone Program | | | 15 | (1) |
| | 16 | (4) |
| Main Elements of an Applet | | | 16 | (1) |
| Compiling and Running an Applet | | | 17 | (1) |
| | 18 | (1) |
| | 19 | (1) |
| | 20 | (21) |
| | 21 | (7) |
| | 21 | (1) |
| | 21 | (1) |
| | 21 | (1) |
| | 21 | (1) |
| | 22 | (2) |
| | 24 | (1) |
| | 24 | (1) |
| | 24 | (2) |
| | 26 | (1) |
| | 26 | (1) |
| | 27 | (1) |
| | 28 | (1) |
| | 28 | (1) |
| | 29 | (2) |
| Declaring, Initializing and Using Variables | | | 29 | (1) |
| Object Reference Variables | | | 30 | (1) |
| | 31 | (1) |
| | 31 | (1) |
| | 31 | (1) |
| | 32 | (1) |
| | 32 | (2) |
| | 33 | (1) |
| Initial Values for Variables | | | 34 | (3) |
| Default Values for Member Variables | | | 34 | (1) |
| Initializing Local Variables of Primitive Datatypes | | | 35 | (1) |
| Initializing Local Reference Variables | | | 36 | (1) |
| | 36 | (1) |
| Java Source File Structure | | | 37 | (1) |
| | 38 | (1) |
| | 38 | (3) |
| The main () Method Modifiers | | | 39 | (1) |
| | 39 | (1) |
| | 39 | (1) |
| | 40 | (1) |
| Operators and Assignments | | | 41 | (45) |
| Precedence and Associativity Rules for Operators | | | 42 | (1) |
| | 43 | (2) |
| | 43 | (1) |
| Narrowing and Widening Conversions | | | 43 | (1) |
| | 44 | (1) |
| | 45 | (1) |
| Simple Assignment Operator = | | | 45 | (4) |
| Assigning Primitive Values | | | 46 | (1) |
| | 46 | (1) |
| | 46 | (1) |
| Numeric Type Conversions on Assignment | | | 47 | (1) |
| | 48 | (1) |
| Arithmetic Operators: *, /, %, +, - | | | 49 | (5) |
| Arithmetic Operator Precedence and Associativity | | | 49 | (1) |
| Arithmetic Expression Evaluation | | | 50 | (1) |
| Numeric Promotions in Arithmetic Expressions | | | 51 | (2) |
| Arithmetic Extended Assignment Operators: *=, /=, %=, +=, -= | | | 53 | (1) |
| The Binary String Concatenation Operator + | | | 54 | (1) |
| Variable Increment and Decrement Operators: ++, -- | | | 54 | (4) |
| | 54 | (1) |
| | 55 | (1) |
| | 55 | (3) |
| | 58 | (1) |
| Relational Operators: <, <=, >, >= | | | 58 | (1) |
| | 59 | (2) |
| Primitive Data Value Equality: ==, != | | | 59 | (1) |
| Object Reference Equality: ==, != | | | 59 | (1) |
| | 60 | (1) |
| Boolean Logical Operators: !, ^, &, | | | | 61 | (2) |
| Operand Evaluation for Boolean Logical Operators | | | 62 | (1) |
| Boolean Logical Extended Assignment Operators: &=, ^=, |= | | | 62 | (1) |
| Conditional Operators; &&, || | | | 63 | (1) |
| | 64 | (1) |
| | 64 | (2) |
| Calculating 2's Complement | | | 65 | (1) |
| Integer Bitwise Operators: ~, &, |, ^ | | | 66 | (2) |
| Bitwise Extended Assignment Operators: &=, ^=, |= | | | 67 | (1) |
| Shift Operators: <<, >>, >>> | | | 68 | (3) |
| The Shift-left Operator << | | | 69 | (1) |
| The Shift-right-with-sign-fill Operator >> | | | 70 | (1) |
| The Shift-right-with-zero-fill Operator >>> | | | 70 | (1) |
| Shift Extended Assignment Operators: <<=, >>=, >>>= | | | 71 | (1) |
| The Conditional Operator? : | | | 71 | (1) |
| Other Operators: new, [], instanceof | | | 72 | (2) |
| | 72 | (2) |
| | 74 | (2) |
| Passing Primitive Data Values | | | 76 | (1) |
| Passing Object Reference Values | | | 77 | (2) |
| | 79 | (1) |
| Array Elements as Actual Parameters | | | 80 | (2) |
| | 82 | (1) |
| | 82 | (4) |
| | 83 | (1) |
| | 84 | (1) |
| | 85 | (1) |
| Declarations and Access Control | | | 86 | (46) |
| | 87 | (10) |
| Declaring Array Variables | | | 87 | (1) |
| | 88 | (1) |
| | 89 | (1) |
| | 89 | (2) |
| | 91 | (2) |
| | 93 | (1) |
| | 94 | (3) |
| | 97 | (1) |
| | 97 | (3) |
| | 98 | (1) |
| Instance Methods and Object Reference this | | | 98 | (1) |
| | 99 | (1) |
| | 100 | (5) |
| | 101 | (2) |
| | 103 | (1) |
| | 103 | (2) |
| | 105 | (3) |
| | 106 | (1) |
| | 107 | (1) |
| Accessibility Modifiers for Classes and Interfaces | | | 108 | (1) |
| Other Modifiers for Classes | | | 109 | (3) |
| | 109 | (1) |
| | 110 | (1) |
| | 111 | (1) |
| Scope and Accessibility of Members | | | 112 | (2) |
| | 112 | (1) |
| Book Scope for Local Variables | | | 113 | (1) |
| Member Accessibility Modifiers | | | 114 | (7) |
| | 115 | (2) |
| | 117 | (1) |
| Default Accessibility for Members | | | 118 | (1) |
| | 118 | (2) |
| | 120 | (1) |
| Other Modifiers for Members | | | 121 | (11) |
| | 121 | (2) |
| | 123 | (1) |
| | 124 | (1) |
| | 124 | (1) |
| | 125 | (1) |
| | 126 | (1) |
| | 126 | (1) |
| | 127 | (3) |
| | 130 | (1) |
| | 131 | (1) |
| Flow Control and Exception Handling | | | 132 | (40) |
| Overview of Flow Control Statements | | | 133 | (1) |
| | 133 | (8) |
| | 133 | (1) |
| | 134 | (2) |
| | 136 | (4) |
| | 140 | (1) |
| | 141 | (4) |
| | 142 | (1) |
| | 143 | (1) |
| | 143 | (2) |
| | 145 | (8) |
| | 145 | (2) |
| | 147 | (1) |
| | 148 | (1) |
| | 149 | (4) |
| | 153 | (3) |
| | 155 | (1) |
| try, catch and finally Blocks | | | 156 | (4) |
| | 157 | (1) |
| | 157 | (2) |
| | 159 | (1) |
| | 160 | (2) |
| | 162 | (10) |
| | 164 | (5) |
| | 169 | (1) |
| | 169 | (3) |
| Object-oriented Programming | | | 172 | (51) |
| | 173 | (6) |
| Object-oriented Programming Concepts | | | 175 | (3) |
| | 178 | (1) |
| Method Overriding and Variable Shadowing | | | 179 | (8) |
| | 179 | (2) |
| | 181 | (1) |
| Overriding vs. Overloading | | | 181 | (2) |
| | 183 | (2) |
| | 185 | (2) |
| Chaining Constructors using this () and super () | | | 187 | (8) |
| | 188 | (2) |
| | 190 | (3) |
| | 193 | (2) |
| | 195 | (6) |
| | 195 | (2) |
| | 197 | (1) |
| | 197 | (1) |
| | 198 | (1) |
| | 199 | (1) |
| | 199 | (2) |
| Assigning, Passing and Casting References | | | 201 | (12) |
| Reference Assignment Conversions | | | 204 | (1) |
| Parameter Passing Conversions | | | 205 | (1) |
| Reference Casting and instanceof Operator | | | 206 | (3) |
| Converting References of Class and Interface Types | | | 209 | (1) |
| | 210 | (3) |
| Polymorphism and Dynamic Method Lookup | | | 213 | (4) |
| | 216 | (1) |
| Inheritance vs. Aggregation | | | 217 | (6) |
| | 217 | (1) |
| Choosing between Inheritance and Aggregation | | | 217 | (3) |
| | 220 | (1) |
| | 221 | (1) |
| | 222 | (1) |
| | 223 | (27) |
| Overview of Nested Classes | | | 224 | (2) |
| Top-level Nested Classes and Interfaces | | | 226 | (4) |
| | 230 | (8) |
| Accessing Shadowed Members from Non-static Inner Classes | | | 232 | (2) |
| Compiling and Importing Non-static Inner Classes | | | 234 | (1) |
| Inheritance and Containment Hierarchy of Non-static Inner Classes | | | 235 | (1) |
| | 236 | (2) |
| | 238 | (5) |
| Access Rules for Local Classes | | | 240 | (1) |
| Instantiating Local Classes | | | 240 | (3) |
| | 243 | (7) |
| Extending an Existing Class | | | 243 | (2) |
| Implementing an Interface | | | 245 | (1) |
| Instantiating Anonymous Classes | | | 245 | (1) |
| Access Rules for Anonymous Classes | | | 246 | (1) |
| | 247 | (2) |
| | 249 | (1) |
| | 249 | (1) |
| | 250 | (21) |
| | 251 | (6) |
| | 251 | (1) |
| | 251 | (1) |
| | 252 | (1) |
| | 253 | (2) |
| Invoking Garbage Collection | | | 255 | (1) |
| | 255 | (2) |
| | 257 | (14) |
| Variable Initializer Expressions | | | 257 | (3) |
| Static Initializer Blocks | | | 260 | (2) |
| Instance Initializer Blocks | | | 262 | (2) |
| Constructing Initial Object State | | | 264 | (3) |
| | 267 | (3) |
| | 270 | (1) |
| | 271 | (24) |
| | 272 | (1) |
| | 272 | (1) |
| | 273 | (1) |
| | 273 | (6) |
| Implementing the Runnable Interface | | | 273 | (3) |
| Extending the Thread Class | | | 276 | (2) |
| | 278 | (1) |
| | 279 | (4) |
| | 279 | (1) |
| | 280 | (1) |
| | 281 | (1) |
| | 282 | (1) |
| | 283 | (12) |
| | 283 | (1) |
| | 284 | (1) |
| | 285 | (1) |
| | 285 | (1) |
| | 286 | (1) |
| | 286 | (4) |
| Miscellaneous Methods in the Thread Class | | | 290 | (2) |
| | 292 | (1) |
| | 293 | (1) |
| | 294 | (1) |
| | 295 | (28) |
| Overview of the java. lang package | | | 296 | (1) |
| | 296 | (3) |
| | 298 | (1) |
| | 299 | (4) |
| Common Wrapper Class Constructors | | | 299 | (1) |
| Common Wrapper Class Utility Methods | | | 300 | (1) |
| | 301 | (1) |
| | 301 | (1) |
| | 301 | (1) |
| | 302 | (1) |
| | 302 | (1) |
| | 303 | (4) |
| Miscellaneous Rounding Functions | | | 303 | (1) |
| | 304 | (1) |
| | 305 | (1) |
| Pseudo Random Number Generator | | | 305 | (1) |
| | 305 | (2) |
| | 307 | (10) |
| Creating and Initializing Strings | | | 307 | (2) |
| Reading Individual Characters in a String | | | 309 | (1) |
| | 310 | (1) |
| Character Case in a String | | | 311 | (1) |
| | 311 | (1) |
| Searching for Characters and Substrings | | | 312 | (1) |
| | 313 | (1) |
| Conversion of Objects to Strings | | | 313 | (1) |
| | 314 | (3) |
| | 317 | (6) |
| Constructing String Buffers | | | 317 | (1) |
| Changing and Reading Characters in String Buffers | | | 318 | (1) |
| Constructing Strings from String Buffers | | | 318 | (1) |
| Appending, Inserting and Deleting Characters in String Buffers | | | 318 | (2) |
| Controlling String Buffer Capacity | | | 320 | (1) |
| | 320 | (1) |
| | 321 | (1) |
| | 322 | (1) |
| | 323 | (28) |
| | 324 | (3) |
| | 324 | (1) |
| | 325 | (1) |
| | 326 | (1) |
| | 327 | (3) |
| | 329 | (1) |
| | 330 | (3) |
| | 333 | (5) |
| | 336 | (2) |
| | 338 | (3) |
| Sorted Sets and Sorted Maps | | | 341 | (4) |
| | 345 | (6) |
| | 348 | (1) |
| | 349 | (1) |
| | 350 | (1) |
| | 351 | (31) |
| Overview of the java.awt package | | | 352 | (1) |
| Components and Containers | | | 352 | (7) |
| | 353 | (2) |
| | 355 | (1) |
| | 355 | (1) |
| | 355 | (1) |
| | 355 | (1) |
| | 356 | (1) |
| | 357 | (1) |
| | 357 | (2) |
| | 359 | (18) |
| | 360 | (1) |
| | 361 | (1) |
| | 362 | (1) |
| Checkbox and CheckboxGroup | | | 363 | (2) |
| | 365 | (1) |
| | 366 | (1) |
| | 367 | (2) |
| | 369 | (3) |
| | 372 | (3) |
| | 375 | (2) |
| | 377 | (5) |
| | 380 | (1) |
| | 381 | (1) |
| | 381 | (1) |
| | 382 | (30) |
| Layout Management Policies | | | 383 | (3) |
| | 383 | (1) |
| Common Methods for Designing a Layout | | | 384 | (1) |
| Communication between Container and Layout Manager | | | 384 | (1) |
| Layout and Preferred Size | | | 385 | (1) |
| | 386 | (1) |
| | 386 | (1) |
| | 387 | (2) |
| | 388 | (1) |
| | 389 | (3) |
| | 391 | (1) |
| | 392 | (4) |
| | 396 | (1) |
| | 396 | (3) |
| | 399 | (1) |
| | 399 | (7) |
| | 405 | (1) |
| | 406 | (1) |
| Building Component Hierarchies | | | 407 | (5) |
| | 411 | (1) |
| | 411 | (1) |
| | 412 | (38) |
| Overview of Event Handling | | | 413 | (1) |
| | 413 | (8) |
| | 414 | (1) |
| | 415 | (2) |
| | 417 | (3) |
| | 420 | (1) |
| The Event Delegation Model | | | 421 | (8) |
| | 427 | (2) |
| | 429 | (4) |
| Evetn Listeners as Anonymous Inner Classes | | | 432 | (1) |
| Building GUI-based Applications | | | 433 | (8) |
| | 439 | (2) |
| Low-Level Event Processing | | | 441 | (9) |
| | 447 | (1) |
| | 448 | (1) |
| | 448 | (2) |
| | 450 | (37) |
| | 451 | (3) |
| | 451 | (1) |
| | 451 | (2) |
| | 453 | (1) |
| | 454 | (4) |
| | 456 | (2) |
| Remdering Text and Working with Fonts | | | 458 | (4) |
| | 462 | (9) |
| | 462 | (1) |
| | 463 | (3) |
| | 466 | (1) |
| | 467 | (2) |
| | 469 | (2) |
| | 471 | (4) |
| | 473 | (2) |
| | 475 | (2) |
| Organizing Painting and Event Handling | | | 477 | (4) |
| | 479 | (2) |
| | 481 | (6) |
| | 485 | (1) |
| | 486 | (1) |
| | 486 | (1) |
| | 487 | (22) |
| | 488 | (1) |
| | 488 | (7) |
| | 489 | (2) |
| | 491 | (1) |
| Applet Layout Management Specification | | | 491 | (2) |
| Applet Code Specification | | | 493 | (2) |
| | 495 | (2) |
| | 496 | (1) |
| | 497 | (3) |
| Other Useful Methods of the Applet Class | | | 500 | (1) |
| Supplying Applet Parameters | | | 501 | (2) |
| Using Images and Sound in Applets | | | 503 | (2) |
| | 505 | (1) |
| | 506 | (3) |
| | 507 | (1) |
| | 508 | (1) |
| | 508 | (1) |
| | 509 | (39) |
| | 510 | (2) |
| Heavyweight and Lightweight Components | | | 511 | (1) |
| | 511 | (1) |
| | 512 | (1) |
| The Root Pane Container Model | | | 512 | (4) |
| | 516 | (15) |
| | 517 | (1) |
| | 518 | (1) |
| | 519 | (2) |
| | 521 | (2) |
| | 523 | (2) |
| | 525 | (1) |
| Components with Complex Models | | | 526 | (3) |
| Large Compound Components | | | 529 | (1) |
| | 530 | (1) |
| | 531 | (9) |
| | 531 | (3) |
| | 534 | (1) |
| Alternatives to Traditional Event Handling | | | 535 | (3) |
| | 538 | (1) |
| | 538 | (2) |
| Building a GUI with Swing | | | 540 | (8) |
| | 547 | (1) |
| | 547 | (1) |
| | 548 | (45) |
| | 549 | (1) |
| | 549 | (6) |
| | 551 | (2) |
| File or Directory Existence | | | 553 | (1) |
| | 553 | (1) |
| Listing Directory Entries | | | 553 | (1) |
| Creating New Files and Directories | | | 554 | (1) |
| Renaming Files and Directories | | | 554 | (1) |
| Deleting Files and Directories | | | 554 | (1) |
| Byte Streams: Input Streams and Output Streams | | | 555 | (12) |
| | 558 | (2) |
| | 560 | (1) |
| I/O of Java Primitive Values | | | 560 | (3) |
| | 563 | (1) |
| Comparison of Byte Output Streams and Input Streams | | | 564 | (1) |
| | 565 | (2) |
| Character Streams: Readers and Writers | | | 567 | (16) |
| | 570 | (1) |
| | 571 | (1) |
| | 572 | (2) |
| | 574 | (1) |
| | 575 | (1) |
| | 575 | (1) |
| | 576 | (3) |
| | 579 | (2) |
| Comparison of Character Writers and Readers | | | 581 | (1) |
| Comparison of Byte Streams and Character Streams | | | 581 | (1) |
| | 582 | (1) |
| | 583 | (4) |
| | 586 | (1) |
| | 587 | (6) |
| | 587 | (1) |
| | 588 | (3) |
| | 591 | (1) |
| | 591 | (1) |
| | 592 | (1) |
| | 593 | (14) |
| | 594 | (2) |
| | 596 | (5) |
| Javadoc Tags for Classes, Interfaces and Members | | | 597 | (2) |
| Documenting Classes and Interfaces | | | 599 | (1) |
| | 600 | (1) |
| Documenting Member Variables | | | 600 | (1) |
| Some Documentation Conventions | | | 601 | (1) |
| | 601 | (6) |
| Common Pitfalls when Using Javadoc | | | 604 | (1) |
| | 604 | (2) |
| | 606 | (1) |
| | 606 | (1) |
A Taking the SCPJ2 Exam | | 607 | (9) |
| Preparing for the programmer exam | | | 607 | (1) |
| | 608 | (3) |
| Obtaining an exam voucher | | | 608 | (1) |
| | 608 | (1) |
| | 609 | (2) |
| | 611 | (1) |
| Moving on to the developer exam | | | 611 | (1) |
| How the examination is conducted | | | 612 | (1) |
| | 612 | (1) |
| Utilizing the allotted time | | | 612 | (1) |
| | 612 | (1) |
| | 613 | (3) |
| Forms of answers expected | | | 613 | (1) |
| | 614 | (1) |
| Topics covered by the questions | | | 614 | (2) |
B Objectives for the SCPJ2 Exam | | 616 | (7) |
C Annotated Answers to Review Questions | | 623 | (43) |
D Solutions to Programming Exercises | | 666 | (32) |
E Sample Exam | | 698 | (31) |
Index | | 729 | |