BRIEF CONTENTS PREFACE READ THIS BEFORE YOU BEGIN CHAPTER 1 CREATING YOUR FIRST JAVA CLASSES CHAPTER 2 USING DATA WITHIN A PROGRAM CHAPTER 3 USING METHODS,CLASSES,AND OBJECTS CHAPTER 4 MORE OBJECT CONCEPTS CHAPTER 5 MAKING DECISIONS CHAPTER 6 LOOPING CHAPTER 7 CHARACTERS,STRINGS,AND THE STRINGBUILDER CHAPTER 8 ARRAYS CHAPTER 9 INTRODUCTION TO INHERITANCE CHAPTER 10 ADVANCED INHERITANCE CONCEPTS CHAPTER 11 EXCEPTION HANDLING CHAPTER 12 FILE INPUT AND OUTPUT CHAPTER 13 INTRODUCTION TO SWING COMPONENTS APPENDIX A WORKING WITH THE JAVA PLATFORM APPENDIX B LEARNING ABOUT ASCII AND UNICODE APPENDIX C FORMATTING OUTPUT APPENDIX D GENERATING RANDOM NUMBERS APPENDIX E JAVADOC GLOSSARY CONTENTS PREFACE READ THIS BEFORE YOU BEGIN CHAPTER 1 CREATING YOUR FIRST JAVA CLASSES LEARNING ABOUT PROGRAMMING INTRODUCING OBJECT-ORIENTED PROGRAMMING CONCEPTS Procedural Programming Object-Oriented Programming Understanding Objects,Classes,and Encapsulation Understanding Inheritance and Polymorphism LEARNING ABOUT JAVA Java Program Types ANALYZING A JAVA APPLICATION THAT USES CONSOLE OUTPUT Understanding the Statement That Prints the Output Understanding the First Class Understanding the main()Method ADDING COMMENTS TO A JAVA CLASS SAVING,COMPILING,RUNNING,AND MODIFYING A JAVA APPLICATION Saving a Java Class Compiling a Java Class Running a Java Application Modifying a Java Class CREATING A JAVA APPLICATION USING GUI OUTPUT CORRECTING ERRORS AND FINDING HELP YOU DO IT Your First Application Adding Comments to a Class Modifying a Class Creating a Dialog Box DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 2 USING DATA WITHIN A PROGRAM USING CONSTANTS AND VARIABLES Declaring Variables Declaring Named Constants Pitfall:Forgetting That a Variable Holds One Value at a Time LEARNING ABOUT THE int DATA TYPE DISPLAYING DATA WRITING ARITHMETIC STATEMENTS Writing Arithmetic Statements Efficiently USING THE BOOLEAN DATA TYPE LEARNING ABOUT FLOATING-POINT DATA TYPES UNDERSTANDING NUMERIC-TYPE CONVERSION WORKING WITH THE char DATA TYPE USING THE Scanner CLASS FOR KEYBOARD INPUT Pitfall:Using nextLine()Following One of the Other Scanner Input Methods USING THE JOptionPane CLASS FOR GUI INPUT Using Input Dialog Boxes Using Confirm Dialog Boxes YOU DO IT Working with Numeric Values Accepting User Data Performing Arithmetic Experimenting with Java Programs DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 3 USING METHODS,CLASSES,AND OBJECTS CREATING METHODS WITH ZERO,ONE,AND MULTIPLE PARAMETERS Creating Methods That Require a Single Parameter Creating Methods That Require Multiple Parameters CREATING METHODS THAT RETURN VALUES Calling a Method from Another Method LEARNING ABOUT CLASS CONCEPTS CREATING A CLASS CREATING INSTANCE METHODS IN A CLASS DECLARING OBJECTS AND USING THEIR METHODS Understanding Data Hiding ORGANIZING CLASSES AN INTRODUCTION TO USING CONSTRUCTORS UNDERSTANDING THAT CLASSES ARE DATA TYPES YOU DO IT Creating a Static Method That Requires No Arguments and Returns No Values Calling a Static Method from Another Class Creating a Static Method That Accepts Arguments and Returns Values Creating a Class That Contains Instance Fields and Methods Creating a Class That Instantiates Objects of Another Class Adding a Constructor to a Class Creating a More Complete Class DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 4 MORE OBJECT CONCEPTS UNDERSTANDING BLOCKS AND SCOPE OVERLOADING A METHOD LEARNING ABOUT AMBIGUITY SENDING ARGUMENTS TO CONSTRUCTORS OVERLOADING CONSTRUCTORS LEARNING ABOUT THE this REFERENCE Using the this Reference to Make Overloaded Constructors More Efficient USING static VARIABLES USING CONSTANT FIELDS USING AUTOMATICALLY IMPORTED,PREWRITTEN CONSTANTS AND METHODS USING AN EXPLICITLY IMPORTED PREWRITTEN CLASS AND ITS METHODS UNDERSTANDING COMPOSITION A BRIEF LOOK AT NESTED AND INNER CLASSES YOU DO IT Demonstrating Scope Overloading Methods Creating a Constructor That Requires an Argument Using an Explicitly Imported Prewritten Class Creating an Interactive Application with a Timer DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 5 MAKING DECISIONS UNDERSTANDING DECISION MAKING MAKING DECISIONS WITH THE if AND if...else STRUCTURES Pitfall:Misplacing a Semicolon in an if Statement Pitfall:Using the Assignment Operator Instead of the Equivalency Operator Pitfall:Attempting to Compare Objects Using the Relational Operators The if...else Structure USING MULTIPLE STATEMENTS IN AN if OR if...else STRUCTURE NESTING if AND if...else STATEMENTS USING LOGICAL AND and OR OPERATORS MAKING ACCURATE AND EFFICIENT DECISIONS Using AND and OR Appropriately USING THE switch STATEMENT USING THE CONDITIONAL AND NOT OPERATORS Using the NOT Operator UNDERSTANDING PRECEDENCE YOU DO IT Using an if...else Creating an Event Class to Use in a Decision-Making Application Writing an Application that Uses the Event class Using the switch Statement DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 6 LOOPING LEARNING ABOUT THE LOOP STRUCTURE USING A while LOOP TO CREATE A DEFINITE LOOP USING A while LOOP TO CREATE AN INDEFINITE LOOP USING SHORTCUT ARITHMETIC OPERATORS USING A for LOOP LEARNING HOW AND WHEN TO USE A do...while LOOP LEARNING ABOUT NESTED LOOPS IMPROVING LOOP PERFORMANCE Avoiding Unnecessary Operations Considering the Order of Evaluation of Short-Circuit Operators Comparing to Zero Employing Loop Fusion YOU DO IT Writing a Loop to Validate Data Entries Working with Prefix and Postfix Increment Operators Working with Definite Loops Working with Nested Loops DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 7 CHARACTERS,STRINGS,AND THE STRINGBUILDER IDENTIFYING PROBLEMS THAT CAN OCCUR WHEN YOU MANIPULATE STRING DATA MANIPULATING CHARACTERS DECLARING A String OBJECT COMPARING String VALUES USING OTHER String METHODS CONVERTING Strings TO NUMBERS LEARNING ABOUT THE StringBuilder AND StringBuffer CLASSES YOU DO IT Using String Class Methods Converting a String to an Integer Using StringBuilderMethods DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 8 ARRAYS DECLARING AND INITIALIZING AN ARRAY Initializing an Array USING SUBSCRIPTS WITH AN ARRAY DECLARING AN ARRAY OF OBJECTS SEARCHING AN ARRAY FOR AN EXACT MATCH SEARCHING AN ARRAY FOR A RANGE MATCH PASSING ARRAYS TO AND RETURNING ARRAYS FROM METHODS Returning an Array from a Method MANIPULATING ARRAYS OF Strings SORTING ARRAY ELEMENTS Sorting Arrays of Objects USING TWO-DIMENSIONAL AND MULTIDIMENSIONAL ARRAYS Using the length Field with a Two-Dimensional Array Understanding Ragged Arrays Using Multidimensional Arrays USING THE Arrays CLASS USING THE ArrayList CLASS Understanding the Limitations of the ArrayList Class YOU DO IT Creating and Populating an Array Initializing an Array Using a for Loop to Access Array Elements Creating Parallel Arrays to Eliminate Nested if Statements Creating an Application with an Array of Objects Creating an Interactive Application That Creates an Array of Objects Passing an Array to a Method Using Arrays Class Methods DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 9 INTRODUCTION TO INHERITANCE LEARNING ABOUT THE CONCEPT OF INHERITANCE EXTENDING CLASSES OVERRIDING SUPERCLASS METHODS UNDERSTANDING HOW CONSTRUCTORS ARE CALLED DURING INHERITANCE USING SUPERCLASS CONSTRUCTORS THAT REQUIRE ARGUMENTS ACCESSING SUPERCLASS METHODS Comparing this and super LEARNING ABOUT INFORMATION HIDING METHODS YOU CANNOT OVERRIDE A Subclass Cannot Override staticMethods in Its Superclass A Subclass Cannot Override finalMethods in Its Superclass A Subclass Cannot Override Methods in a final Superclass YOU DO IT Creating a Superclass and an Application to Use It Creating a Subclass and an Application to Use It Creating a Subclass Method That Overrides a Superclass Method Understanding the Role of Constructors in Inheritance Inheritance When the Superclass Requires Constructor Arguments Accessing an Overridden Superclass Method from Within a Subclass DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 10 ADVANCED INHERITANCE CONCEPTS CREATING AND USING ABSTRACT CLASSES USING DYNAMIC METHOD BINDING Using a Superclass as a Method Parameter Type CREATING ARRAYS OF SUBCLASS OBJECTS USING THE Object CLASS AND ITS METHODS Using the toString()Method Using the equals()Method USING INHERITANCE TO ACHIEVE GOOD SOFTWARE DESIGN CREATING AND USING INTERFACES Creating Interfaces to Store Related Constants CREATING AND USING PACKAGES YOU DO IT Creating an Abstract Class Extending an Abstract Class Extending an Abstract Class with a Second Subclass Instantiating Objects from Subclasses Using Object References Overriding the Object Class equals()Method Eliminating Duplicate User Entries Creating a Package DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 11 EXCEPTION HANDLING LEARNING ABOUT EXCEPTIONS TRYING CODE AND CATCHING Exceptions THROWING AND CATCHING MULTIPLE Exceptions USING THE Finally BLOCK UNDERSTANDING THE ADVANTAGES OF EXCEPTION HANDLING SPECIFYING THE Exceptions A METHOD CAN THROW TRACING Exceptions THROUGH THE CALL STACK CREATING YOUR OWN Exceptions USING ASSERTIONS YOU DO IT Catching an Exception and Using getMessage() Generating a NumberFormatException Adding NumberFormatException Handling Capabilities to an Application Creating a Class That Automatically Throws Exceptions Creating a Class That Passes on an Exception Creating an Application That Can Catch Exceptions Extending a Class That Throws Exceptions Using the printStackTrace()Method Creating an Exception Class Using an Exception You Created DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 12 FILE INPUT AND OUTPUT UNDERSTANDING COMPUTER FILES USING THE File CLASS UNDERSTANDING DATA FILE ORGANIZATION AND STREAMS USING STREAMS WRITING TO AND READING FROM A FILE Reading from a File WRITING FORMATTED FILE DATA READING FORMATTED FILE DATA USING A VARIABLE FILENAME CREATING AND USING RANDOM ACCESS FILES WRITING RECORDS TO A RANDOM ACCESS FILE READING RECORDS FROM A RANDOM ACCESS FILE Accessing a Random Access File Sequentially Accessing a Random Access File Randomly READING AND WRITING OBJECTS TO AND FROM FILES YOU DO IT Using the File Class to Examine File Status Comparing Two File Dates Using InputStream and OutputStream Objects Writing to an Output File Reading Data from a File Creating a Class to Use in a File of Objects Creating a Program that Writes Event Objects to a File Creating a Program that Accesses Stored Event Object Data DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION CHAPTER 13 INTRODUCTION TO SWING COMPONENTS UNDERSTANDING Swing COMPONENTS USING THE JFrame CLASS Customizing a JFrame's Appearance USING A JLabel Changing a JLabel's Font USING A LAYOUT MANAGER EXTENDING THE JFrame CLASS ADDING JTextFields,JBUTTONS,AND TOOL TIPS TO A JFrame Adding JButtons Using Tool Tips LEARNING ABOUT EVENT-DRIVEN PROGRAMMING Preparing Your Class to Accept Event Messages Telling Your Class to Expect Events to Happen Telling Your Class How to Respond to Events Using the setEnabled()Method UNDERSTANDING Swing EVENT LISTENERS USING THE JCheckBox CLASS USING THE ButtonGroup CLASS USING THE JComboBox CLASS YOU DO IT Creating a JFrame Ending an Application When a JFrame Closes Adding Components to a JFrame Adding Functionality to a JButton and a JTextField Distinguishing Event Sources Including JCheckBoxes in an Application DON'T DO IT KEY TERMS CHAPTER SUMMARY REVIEW QUESTIONS EXERCISES DEBUGGING EXERCISES GAME ZONE TOUGH QUESTIONS UP FOR DISCUSSION APPENDIX A WORKING WITH THE JAVA PLATFORM APPENDIX B LEARNING ABOUT ASCII AND UNICODE APPENDIX C FORMATTING OUTPUT APPENDIX D GENERATING RANDOM NUMBERS APPENDIX E JAVADOC GLOSSARY