Preface p. xix Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. 5 Java Applets and Applications p. 5 Security p. 5 Portability p. 6 Java's Magic: The Bytecode p. 6 The Java Buzzwords p. 7 Object-Oriented Programming p. 8 Encapsulation p. 9 Polymorphism p. 10 Inheritance p. 10 Obtaining the Java Software Developer's Kit p. 12 A First Simple Program p. 12 Entering the Program p. 13 Compiling the Program p. 13 The First Sample Program Line by Line p. 14 Handling Syntax Errors p. 17 A Second Simple Program p. 17 Another Data Type p. 20 Converting Gallons to Liters p. 22 Two Control Statements p. 23 The if Statement p. 23 The for Loop p. 25 Create Blocks of Code p. 27 Semicolons and Positioning p. 29 Indentation Practices p. 29 Improving the Gallons-to-Liters Converter p. 30 The Java Keywords p. 32 Identifiers in Java p. 32 The Java Class Libraries p. 33 Module 1 Mastery Check p. 34 Introducing Data Types and Operators p. 35 Why Data Types Are Important p. 36 Java's Simple Types p. 36 Integers p. 37 Floating-Point Types p. 38 Characters p. 40
The Boolean Type p. 41 How Far Away Is the Lightning? p. 43 Literals p. 44 Hexadecimal and Octal Constants p. 44 Character Escape Sequences p. 45 String Literals p. 45 A Closer Look at Variables p. 47 Initializing a Variable p. 47 Dynamic Initialization p. 48 The Scope and Lifetime of Variables p. 49 Operators p. 52 Arithmetic Operators p. 52 Increment and Decrement p. 54 Relational and Logical Operators p. 55 Short-Circuit Logical Operators p. 57 The Assignment Operator p. 58 Shorthand Assignments p. 60 Type Conversion in Assignments p. 61 Casting Incompatible Types p. 62 Operator Precedence p. 64 Display a Truth Table for the Logical Operators p. 65 Expressions p. 66 Type Conversion in Expressions p. 66 Spacing and Parentheses p. 68 Module 2 Mastery Check p. 69 Program Control Statements p. 71 Input Characters from the Keyboard p. 72 The if Statement p. 74 Nested ifs p. 75 The if-else-if Ladder p. 76 The switch Statement p. 78 Nested switch Statements p. 82 Start Building a Java Help System p. 83 The for Loop p. 86 Some Variations on the for Loop p. 87 Missing Pieces p. 88 Loops with No Body p. 90 Declaring Loop Control Variables Inside the for Loop p. 91 The while Loop p. 92 The do-while Loop p. 94 Improve the Java Help System p. 97
Use break to Exit a Loop p. 100 Use break as a Form of goto p. 102 Use continue p. 106 Finish the Java Help System p. 109 Nested Loops p. 112 Module 3 Mastery Check p. 113 Introducing Classes, Objects, and Methods p. 115 Class Fundamentals p. 116 The General Form of a Class p. 116 Defining a Class p. 117 How Objects Are Created p. 121 Reference Variables and Assignment p. 121 Methods p. 122 Adding a Method to the Vehicle Class p. 123 Returning from a Method p. 125 Returning a Value p. 126 Using Parameters p. 129 Adding a Parameterized Method to Vehicle p. 130 Creating a Help Class p. 133 Constructors p. 139 Parameterized Constructors p. 140 Adding a Constructor to the Vehicle Class p. 141 The new Operator Revisited p. 142 Garbage Collection and Finalizers p. 143 The finalize() Method p. 144 Demonstrate Finalization p. 145 The this Keyword p. 147 Module 4 Mastery Check p. 149 More Data Types and Operators p. 151 Arrays p. 152 One-Dimensional Arrays p. 152 Sorting an Array p. 156 Multidimensional Arrays p. 158 Two-Dimensional Arrays p. 158 Irregular Arrays p. 160 Arrays of Three or More Dimensions p. 161 Initializing Multidimensional Arrays p. 161 Alternative Array Declaration Syntax p. 163 Assigning Array References p. 164 Using the length Member p. 165 A Queue Class p. 168
Strings p. 172 Constructing Strings p. 172 Operating on Strings p. 173 Arrays of Strings p. 176 Strings Are Immutable p. 176 Using Command-Line Arguments p. 178 The Bitwise Operators p. 180 The Bitwise AND, OR, XOR, and NOT Operators p. 180 The Shift Operators p. 185 Bitwise Shorthand Assignments p. 187 A ShowBits Class p. 188 The? Operator p. 191 Module 5 Mastery Check p. 193 A Closer Look at Methods and Classes p. 195 Controlling Access to Class Members p. 196 Java's Access Specifiers p. 196 Improving the Queue Class p. 202 Pass Objects to Methods p. 203 How Arguments Are Passed p. 205 Returning Objects p. 208 Method Overloading p. 210 Overloading Constructors p. 216 Overloading the Queue Constructor p. 219 Recursion p. 222 Understanding static p. 224 Static Blocks p. 227 The Quicksort p. 229 Introducing Nested and Inner Classes p. 232 Module 6 Mastery Check p. 236 Inheritance p. 239 Inheritance Basics p. 240 Member Access and Inheritance p. 243 Constructors and Inheritance p. 246 Using super to Call Superclass Constructors p. 248 Using super to Access Superclass Members p. 254 Extending the Vehicle Class p. 255 Creating a Multilevel Hierarchy p. 258 When Are Constructors Called? p. 261 Superclass References and Subclass Objects p. 262 Method Overriding p. 268 Overridden Methods Support Polymorphism p. 271
Why Overriden Methods? p. 273 Applying Method Overriding to TwoDShape p. 273 Using Abstract Classes p. 278 Using final p. 283 final Prevents Overriding p. 283 final Prevents Inheritance p. 283 Using final with Data Members p. 284 The Object Class p. 286 Module 7 Mastery Check p. 287 Packages and Interfaces p. 289 Packages p. 290 Defining a Package p. 290 Finding Packages and CLASSPATH p. 292 A Short Package Example p. 292 Packages and Member Access p. 294 A Package Access Example p. 295 Understanding Protected Members p. 297 Importing Packages p. 299 Java's Class Library Is Contained in Packages p. 302 Interfaces p. 303 Implementing Interfaces p. 304 Using Interface References p. 308 Creating a Queue Interface p. 310 Variables in Interfaces p. 316 Interfaces Can Be Extended p. 317 Module 8 Mastery Check p. 318 Exception Handling p. 321 The Exception Hierarchy p. 322 Exception Handling Fundamentals p. 322 Using try and catch p. 323 A Simple Exception Example p. 324 The Consequences of an Uncaught Exception p. 327 Exceptions Enable You to Handle Errors Gracefully p. 328 Using Multiple catch Statements p. 330 Catching Subclass Exceptions p. 331 Try Blocks Can Be Nested p. 332 Throwing an Exception p. 334 Rethrowing an Exception p. 334 A Closer Look at Throwable p. 336 Using finally p. 338 Using throws p. 340
Java's Built-in Exceptions p. 342 Creating Exception Subclasses p. 344 Adding Exceptions to the Queue Class p. 347 Module 9 Mastery Check p. 350 Using I/O p. 353 Java's I/O Is Built upon Streams p. 354 Byte Streams and Character Streams p. 354 The Byte Stream Classes p. 355 The Character Stream Classes p. 355 The Predefined Streams p. 355 Using the Byte Streams p. 358 Reading Console Input p. 358 Writing Console Output p. 360 Reading and Writing Files Using Byte Streams p. 361 Inputting from a File p. 362 Writing to a File p. 364 Reading and Writing Binary Data p. 366 A File Comparison Utility p. 370 Random Access Files p. 372 Using Java's Character-Based Streams p. 375 Console Input Using Character Streams p. 376 Console Output Using Character Streams p. 379 File I/O Using Character Streams p. 381 Using a FileWriter p. 381 Using a FileReader p. 382 Using Java's Type Wrappers to Convert Numeric Strings p. 384 Creating a Disk-Based Help System p. 387 Module 10 Mastery Check p. 394 Multithreaded Programming p. 395 Multithreading Fundamentals p. 396 The Thread Class and Runnable Interface p. 397 Creating a Thread p. 398 Some Simple Improvements p. 401 Extending Thread p. 403 Creating Multiple Threads p. 406 Determining When a Thread Ends p. 409 Thread Priorities p. 412 Synchronization p. 416 Using Synchronized Methods p. 416 The synchronized Statement p. 419 Thread Communication Using notify(), wait(), and notifyall() p. 422
An Example That Uses wait() and notify() p. 423 Suspending, Resuming, and Stopping Threads p. 428 Using the Main Thread p. 432 Module 11 Mastery Check p. 434 Applets, Events, and Miscellaneous Topics p. 435 Applet Basics p. 436 Applet Organization and Essential Elements p. 440 The Applet Architecture p. 440 A Complete Applet Skeleton p. 441 Applet Initialization and Termination p. 442 Requesting Repainting p. 443 The update() Method p. 444 A Simple Banner Applet p. 445 Using the Status Window p. 449 Passing Parameters to Applets p. 450 The Applet Class p. 452 Event Handling p. 454 The Delegation Event Model p. 454 Events p. 454 Event Sources p. 455 Event Listeners p. 455 Event Classes p. 455 Event Listener Interfaces p. 456 Using the Delegation Event Model p. 458 Handling Mouse Events p. 458 A Simple Mouse Event Applet p. 459 More Java Keywords p. 462 The transient and volatile Modifiers p. 462 Instanceof p. 463 Strictfp p. 463 Assert p. 463 Native Methods p. 465 What Next? p. 465 Module 12 Mastery Check p. 466 Answers to Mastery Checks p. 467 Using Java's Documentation Comments p. 503 The javadoc Tags p. 504 @author p. 505 @deprecated p. 505 {@docroot} p. 505 @exception p. 506
{@inheritdoc} p. 506 {@link} p. 506 {@linkplain} p. 506 @param p. 506 @return p. 507 @see p. 507 @serial p. 507 @serialdata p. 507 @serialfield p. 508 @since p. 508 @throws p. 508 {@value} p. 508 @version p. 508 The General Form of a Documentation Comment p. 509 What javadoc Outputs p. 509 An Example that Uses Documentation Comments p. 509 Index p. 511 Table of Contents provided by Blackwell's Book Services and R.R. Bowker. Used with permission.