1. Trang chủ
  2. » Công Nghệ Thông Tin

ABSOLUTE JAVA™ 5 th Edition pot

1.3K 7.4K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Cover

  • ABSOLUTE JAVA™ 5 th Edition

  • ©

  • Preface

  • ACKNOWLEDGMENTS

  • LOCATION OF VIDEONOTES IN THE TEXT

  • Brief Contents

  • Contents

  • Chapter 1 Getting Started

    • 1.1 INTRODUCTION TO JAVA

      • Origins of the Java Language*

      • Objects and Methods

      • Applets*

      • A Sample Java Application Program

      • Byte-Code and the Java Virtual Machine

      • Class Loader*

      • Compiling a Java Program or Class

      • Running a Java Program

      • TIP: Error Messages

    • 1.2 EXPRESSIONS AND ASSIGNMENT STATEMENTS

      • Identifiers

      • Variables

      • Assignment Statements

      • TIP: Initialize Variables

      • More Assignment Statements*

      • Assignment Compatibility

      • Constants

      • Arithmetic Operators and Expressions

      • Parentheses and Precedence Rules*

      • Integer and Floating-Point Division

      • PITFALL: Round-Off Errors in Floating-Point Numbers

      • PITFALL: Division with Whole Numbers

      • Type Casting

      • Increment and Decrement Operators

    • 1.3 THE CLASS String

      • String Constants and Variables

      • Concatenation of Strings

      • Classes

      • String Methods

      • Escape Sequences

      • String Processing

      • The Unicode Character Set*

    • 1.4 PROGRAM STYLE

      • Naming Constants

      • Java Spelling Conventions

      • Comments

      • Indenting

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 2 Console Input and Output

    • 2.1 SCREEN OUTPUT

      • System.out.println

      • TIP: Different Approaches to Formatting Output

      • Formatting Output with printf

      • TIP: Formatting Monetary Amounts with printf

      • TIP: Legacy Code

      • Money Formats Using NumberFormat*

      • Importing Packages and Classes

      • The DecimalFormat Class*

    • 2.2 CONSOLE INPUT USING THE Scanner CLASS

      • The Scanner Class

      • PITFALL: Dealing with the Line Terminator, '\n'

      • The Empty String

      • TIP: Prompt for Input

      • TIP: Echo Input

      • EXAMPLE: Self-Service Checkout

      • Other Input Delimiters

    • 2.3 INTRODUCTION TO FILE INPUT

      • The Scanner Class for Text File Input

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 3 Flow of Control

    • 3.1 BRANCHING MECHANISM

      • if-else Statements

      • Omitting the else

      • Compound Statements

      • TIP: Placing of Braces

      • Nested Statements

      • Multiway if-else Statement

      • EXAMPLE: State Income Tax

      • The switch Statement

      • PITFALL: Forgetting a break in a switch Statement

      • The Conditional Operator*

    • 3.2 BOOLEAN EXPRESSIONS

      • Simple Boolean Expressions

      • PITFALL: Using = in Place of ==

      • PITFALL: Using == with Strings

      • Lexicographic and Alphabetical Order

      • Building Boolean Expressions

      • PITFALL: Strings of Inequalities

      • Evaluating Boolean Expressions

      • TIP: Naming Boolean Variables

      • Short-Circuit and Complete Evaluation

      • Precedence and Associativity Rules

    • 3.3 LOOPS

      • while Statement and do-while Statement

      • Algorithms and Pseudocode

      • EXAMPLE: Averaging a List of Scores

      • The for Statement

      • The Comma in for Statements

      • TIP: Repeat N Times Loops

      • PITFALL: Extra Semicolon in a for Statement

      • PITFALL: Infinite Loops

      • Nested Loops

      • The break and continue Statements*

      • The exit Statement

    • 3.4 DEBUGGING

      • Loop Bugs

      • Tracing Variables

      • General Debugging Techniques

      • EXAMPLE: Debugging an Input Validation Loop

      • Preventive Coding

      • Assertion Checks*

    • 3.5 RANDOM NUMBER GENERATION

      • The Random Object

      • The Math.random() Method

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 4 Defining Classes I

    • 4.1 CLASS DEFINITIONS

      • Instance Variables and Methods

      • More about Methods

      • TIP: Any Method Can Be Used as a void Method

      • Local Variables

      • Blocks

      • TIP: Declaring Variables in a for Statement

      • Parameters of a Primitive Type

      • PITFALL: Use of the Terms “Parameter” and “Argument”

      • Simple Cases with Class Parameters

      • The this Parameter

      • Methods That Return a Boolean Value

      • The Methods equals and toString

      • Recursive Methods

      • TIP: Testing Methods

    • 4.2 INFORMATION HIDING AND ENCAPSULATION

      • public and private Modifiers

      • EXAMPLE: Yet Another Date Class

      • Accessor and Mutator Methods

      • TIP: A Class Has Access to Private Members of All Objects of the Class

      • TIP: Mutator Methods Can Return a Boolean Value*

      • Preconditions and Postconditions

    • 4.3 OVERLOADING

      • Rules for Overloading

      • PITFALL: Overloading and Automatic Type Conversion

      • PITFALL: You Cannot Overload Based on the Type Returned

    • 4.4 CONSTRUCTORS

      • Constructor Definitions

      • TIP: You Can Invoke Another Method in a Constructor

      • TIP: A Constructor Has a this Parameter

      • TIP: Include a No-Argument Constructor

      • EXAMPLE: The Final Date Class

      • Default Variable Initializations

      • An Alternative Way to Initialize Instance Variables

      • EXAMPLE: A Pet Record Class

      • The StringTokenizer Class*

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 5 Defining Classes II

    • 5.1 STATIC METHODS AND STATIC VARIABLES

      • Static Methods

      • PITFALL: Invoking a Nonstatic Method Within a Static Method

      • TIP: You Can Put a main in Any Class

      • Static Variables

      • The Math Class

      • Wrapper Classes

      • Automatic Boxing and Unboxing

      • Static Methods in Wrapper Classes

      • PITFALL: A Wrapper Class Does Not Have a No-Argument Constructor

    • 5.2 REFERENCES AND CLASS PARAMETERS

      • Variables and Memory

      • References

      • Class Parameters

      • PITFALL: Use of = and == with Variables of a Class Type

      • The Constant null

      • PITFALL: Null Pointer Exception

      • The new Operator and Anonymous Objects

      • EXAMPLE: Another Approach to Keyboard Input*

      • TIP: Use Static Imports*

    • 5.3 USING AND MISUSING REFERENCES

      • EXAMPLE: A Person Class

      • PITFALL: null Can Be an Argument to a Method

      • Copy Constructors

      • PITFALL: Privacy Leaks

      • Mutable and Immutable Classes

      • TIP: Deep Copy versus Shallow Copy

      • TIP: Assume Your Coworkers Are Malicious

    • 5.4 PACKAGES AND javadoc

      • Packages and import Statements

      • The Package java.lang

      • Package Names and Directories

      • PITFALL: Subdirectories Are Not Automatically Imported

      • The Default Package

      • PITFALL: Not Including the Current Directory in Your Class Path

      • Specifying a Class Path When You Compile*

      • Name Clashes*

      • Introduction to javadoc*

      • Commenting Classes for javadoc*

      • Running javadoc*

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 6 Arrays

    • 6.1 INTRODUCTION TO ARRAYS

      • Creating and Accessing Arrays

      • The length Instance Variable

      • TIP: Use for Loops with Arrays

      • PITFALL: Array Indices Always Start with Zero

      • PITFALL: Array Index Out of Bounds

      • Initializing Arrays

      • PITFALL: An Array of Characters Is Not a String

    • 6.2 ARRAYS AND REFERENCES

      • Arrays Are Objects

      • PITFALL: Arrays with a Class Base Type

      • Array Parameters

      • PITFALL: Use of = and == with Arrays

      • Arguments for the Method main*

      • Methods that Return an Array

    • 6.3 PROGRAMMING WITH ARRAYS

      • Partially Filled Arrays

      • EXAMPLE: A Class for Partially Filled Arrays

      • TIP: Accessor Methods Need Not Simply Return Instance Variables

      • The “for-each” Loop*

      • Methods with a Variable Number of Parameters*

      • EXAMPLE: A String Processing Example*

      • Privacy Leaks with Array Instance Variables

      • Enumerated Types*

      • EXAMPLE: Sorting an Array

      • TIP: Enumerated Types in switch Statements*

    • 6.4 MULTIDIMENSIONAL ARRAYS

      • Multidimensional Array Basics

      • Using the length Instance Variable

      • Ragged Arrays*

      • Multidimensional Array Parameters and Returned Values

      • EXAMPLE: A Grade Book Class

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 7 Inheritance

    • 7.1 INHERITANCE BASICS

      • Derived Classes

      • Overriding a Method Definition

      • Changing the Return Type of an Overridden Method

      • Changing the Access Permission of an Overridden Method

      • PITFALL: Overriding versus Overloading

      • The super Constructor

      • The this Constructor

      • TIP: An Object of a Derived Class Has More than One Type

      • PITFALL: The Terms Subclass and Superclass

      • EXAMPLE: An Enhanced StringTokenizer Class*

    • 7.2 ENCAPSULATION AND INHERITANCE

      • PITFALL: Use of Private Instance Variables from the Base Class

      • PITFALL: Private Methods Are Effectively Not Inherited

      • Protected and Package Access

      • PITFALL: Forgetting about the Default Package

      • PITFALL: A Restriction on Protected Access*

    • 7.3 PROGRAMMING WITH INHERITANCE

      • TIP: Static Variables Are Inherited

      • TIP: “is a” versus “has a”

      • Access to a Redefined Base Method

      • PITFALL: You Cannot Use Multiple supers

      • The Class Object

      • The Right Way to Define equals

      • TIP: getClass versus instanceof*

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 8 Polymorphism and Abstract Classes

    • 8.1 POLYMORPHISM

      • Late Binding

      • The final Modifier

      • EXAMPLE: Sales Records

      • Late Binding with toString

      • PITFALL: No Late Binding for Static Methods

      • Downcasting and Upcasting

      • PITFALL: Downcasting

      • TIP: Checking to See Whether Downcasting Is Legitimate*

      • A First Look at the clone Method

      • PITFALL: Sometimes the clone Method Return Type Is Object

      • PITFALL: Limitations of Copy Constructors*

    • 8.2 ABSTRACT CLASSES

      • Abstract Classes

      • PITFALL: You Cannot Create Instances of an Abstract Class

      • TIP: An Abstract Class Is a Type

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 9 Exception Handling

    • 9.1 EXCEPTION HANDLING BASICS

      • try-catch Mechanism

      • Exception Handling with the Scanner Class

      • TIP: Exception Controlled Loops

      • Throwing Exceptions

      • EXAMPLE: A Toy Example of Exception Handling

      • Exception Classes

      • Exception Classes from Standard Packages

      • Defining Exception Classes

      • TIP: Preserve getMessage

      • TIP: An Exception Class Can Carry a Message of Any Type

      • Multiple catch Blocks

      • PITFALL: Catch the More Specific Exception First

    • 9.2 THROWING EXCEPTIONS IN METHODS

      • Throwing an Exception in a Method

      • Declaring Exceptions in a throws Clause

      • Exceptions to the Catch or Declare Rule

      • throws Clause in Derived Classes

      • When to Use Exceptions

      • Event-Driven Programming*

    • 9.3 MORE PROGRAMMING TECHNIQUES FOR EXCEPTION HANDLING

      • PITFALL: Nested try-catch Blocks

      • The finally Block*

      • Rethrowing an Exception*

      • The AssertionError Class*

      • ArrayIndexOutOfBoundsException

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 10 File I/O

    • 10.1 INTRODUCTION TO FILE I/O

      • Streams

      • Text Files and Binary Files

    • 10.2 TEXT FILES

      • Writing to a Text File

      • PITFALL: A try Block Is a Block

      • PITFALL: Overwriting an Output File

      • Appending to a Text File

      • TIP: toString Helps with Text File Output

      • Reading from a Text File

      • Reading a Text File Using Scanner

      • Testing for the End of a Text File with Scanner

      • Reading a Text File Using BufferedReader

      • TIP: Reading Numbers with BufferedReader

      • Testing for the End of a Text File with BufferedReader

      • Path Names

      • Nested Constructor Invocations

      • System.in, System.out, and System.err

    • 10.3 THE File CLASS

      • Programming with the File Class

    • 10.4 BINARY FILES*

      • Writing Simple Data to a Binary File

      • UTF and writeUTF

      • Reading Simple Data from a Binary File

      • Checking for the End of a Binary File

      • PITFALL: Checking for the End of a File in the Wrong Way

      • Binary I/O of Objects

      • The Serializable Interface

      • PITFALL: Mixing Class Types in the Same File

      • Array Objects in Binary Files

    • 10.5 RANDOM ACCESS TO BINARY FILES*

      • Reading and Writing to the Same File

      • PITFALL: RandomAccessFile Need Not Start Empty

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 11 Recursion

    • 11.1 RECURSIVE Void METHODS

      • EXAMPLE: Vertical Numbers

      • Tracing a Recursive Call

      • A Closer Look at Recursion

      • PITFALL: Infi nite Recursion

      • Stacks for Recursion*

      • PITFALL: Stack Overflow*

      • Recursion versus Iteration

    • 11.2 RECURSIVE METHODS THAT RETURN A VALUE

      • General Form for a Recursive Method That Returns a Value

      • EXAMPLE: Another Powers Method

    • 11.3 THINKING RECURSIVELY

      • Recursive Design Techniques

      • Binary Search*

      • Efficiency of Binary Search*

      • EXAMPLE: Finding a File

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 12 UML and Patterns

    • 12.1 UML

      • History of UML

      • UML Class Diagrams

      • Class Interactions

      • Inheritance Diagrams

      • More UML

    • 12.2 PATTERNS*

      • Adaptor Pattern*

      • The Model-View-Controller Pattern*

      • EXAMPLE: A Sorting Pattern

      • Restrictions on the Sorting Pattern

      • Efficiency of the Sorting Pattern*

      • TIP: Pragmatics and Patterns

      • Pattern Formalism

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 13 Interfaces and Inner Classes

    • 13.1 INTERFACES

      • Interfaces

      • Abstract Classes Implementing Interfaces

      • Derived Interfaces

      • PITFALL: Interface Semantics Are Not Enforced

      • The Comparable Interface

      • EXAMPLE: Using the Comparable Interface

      • Defined Constants in Interfaces

      • PITFALL: Inconsistent Interfaces

      • The Serializable Interface*

      • The Cloneable Interface

    • 13.2 SIMPLE USES OF INNER CLASSES

      • Helping Classes

      • TIP: Inner and Outer Classes Have Access to Each Other’s Private Members

      • EXAMPLE: A Bank Account Class

      • The .class File for an Inner Class

      • PITFALL: Other Uses of Inner Classes

    • 13.3 MORE ABOUT INNER CLASSES

      • Static Inner Classes

      • Public Inner Classes

      • TIP: Referring to a Method of the Outer Class

      • Nesting Inner Classes

      • Inner Classes and Inheritance

      • Anonymous Classes

      • TIP: Why Use Inner Classes?

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 14 Generics and the ArrayList Class

    • 14.1 THE ArrayList CLASS

      • Using the ArrayList Class

      • TIP: Summary of Adding to an ArrayList

      • Methods in the Class ArrayList

      • The “for-each” Loop

      • EXAMPLE: Golf Scores

      • TIP: Use trimToSize to Save Memory

      • PITFALL: The clone Method Makes a Shallow Copy*

      • The Vector Class

      • Parameterized Classes and Generics

      • PITFALL: Nonparameterized ArrayList and Vector Classes

    • 14.2 GENERICS

      • Generic Basics

      • TIP: Compile with the -Xlint Option

      • EXAMPLE: A Generic Class for Ordered Pairs

      • PITFALL: A Generic Constructor Name Has No Type Parameter

      • PITFALL: You Cannot Plug in a Primitive Type for a Type Parameter

      • PITFALL: A Type Parameter Cannot Be Used Everywhere a Type Name Can Be Used

      • PITFALL: An Instantiation of a Generic Class Cannot be an Array Base Type

      • TIP: A Class Definition Can Have More Than One Type Parameter

      • PITFALL: A Generic Class Cannot Be an Exception Class

      • Bounds for Type Parameters

      • TIP: Generic Interfaces

      • Generic Methods*

      • Inheritance with Generic Classes*

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 15 Linked Data Structures

    • 15.1 JAVA LINKED LISTS

      • EXAMPLE: A Simple Linked List Class

      • Working with Linked Lists

      • PITFALL: Privacy Leaks

      • Node Inner Classes

      • EXAMPLE: A Generic Linked List

      • PITFALL: Using Node Instead of Node<T>

      • The equals Method for Linked Lists

    • 15.2 COPY CONSTRUCTORS AND THE clone METHOD*

      • Simple Copy Constructors and clone Methods*

      • Exceptions*

      • PITFALL: The clone Method Is Protected in object*

      • TIP: Use a Type Parameter Bound for a Better clone*

      • EXAMPLE: A Linked List with a Deep Copy clone Method*

      • TIP: Cloning Is an “All or Nothing” Affair

    • 15.3 ITERATORS

      • Defining an Iterator Class

      • Adding and Deleting Nodes

    • 15.4 VARIATIONS ON A LINKED LIST

      • Doubly Linked List

      • The Stack Data Structure

      • The Queue Data Structure

      • Running Times and Big-O Notation

      • Efficiency of Linked Lists

    • 15.5 HASH TABLES WITH CHAINING

      • A Hash Function for Strings

      • Efficiency of Hash Tables

    • 15.6 SETS

      • Fundamental Set Operations

      • Efficiency of Sets Using Linked Lists

    • 15.7 TREES

      • Tree Properties

      • EXAMPLE: A Binary Search Tree Class*

      • Efficiency of Binary Search Trees*

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 16 Collections, Maps and Iterators

    • 16.1 COLLECTIONS

      • Wildcards

      • The Collection Framework

      • PITFALL: Optional Operations

      • TIP: Dealing with All Those Exceptions

      • Concrete Collection Classes

      • Differences between ArrayList<T> and Vector<T>

      • Nonparameterized Version of the Collection Framework*

      • PITFALL: Omitting the <T>

    • 16.2 MAPS

      • Concrete Map Classes

    • 16.3 ITERATORS

      • The Iterator Concept

      • The Iterator<T> Interface

      • TIP: For-Each Loops as Iterators

      • List Iterators

      • PITFALL: next Can Return a Reference

      • TIP: Defining Your Own Iterator Classes

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 17 Swing I

    • 17.1 EVENT-DRIVEN PROGRAMMING

      • Events and Listeners

    • 17.2 BUTTONS, EVENTS, AND OTHER SWING BASICS

      • EXAMPLE: A Simple Window

      • PITFALL: Forgetting to Program the Close-Window Button

      • Buttons

      • Action Listeners and Action Events

      • PITFALL: Changing the Heading for actionPerformed

      • TIP: Ending a Swing Program

      • EXAMPLE: A Better Version of Our First Swing GUI

      • Labels

      • Color

      • EXAMPLE: A GUI with a Label and Color

    • 17.3 CONTAINERS AND LAYOUT MANAGERS

      • Border Layout Managers

      • Flow Layout Managers

      • Grid Layout Managers

      • Panels

      • EXAMPLE: A Tricolor Built with Panels

      • The Container Class

      • TIP: Code a GUI’s Look and Actions Separately

      • The Model-View-Controller Pattern*

    • 17.4 MENUS AND BUTTONS

      • EXAMPLE: A GUI with a Menu

      • Menu Bars, Menus, and Menu Items

      • Nested Menus*

      • The AbstractButton Class

      • The setActionCommand Method

      • Listeners as Inner Classes*

    • 17.5 TEXT FIELDS AND TEXT AREAS

      • Text Areas and Text Fields

      • TIP: Labeling a Text Field

      • TIP: Inputting and Outputting Numbers

      • A Swing Calculator

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 18 Swing II

    • 18.1 WINDOW LISTENERS

      • EXAMPLE: A Window Listener Inner Class

      • The dispose Method

      • PITFALL: Forgetting to Invoke setDefaultCloseOperation

      • The WindowAdapter Class

    • 18.2 ICONS AND SCROLL BARS

      • Icons

      • Scroll Bars

      • EXAMPLE: Components with Changing Visibility

    • 18.3 THE Graphics CLASS

      • Coordinate System for Graphics Objects

      • The Method paint and the Class Graphics

      • Drawing Ovals

      • Drawing Arcs

      • Rounded Rectangles*

      • paintComponent for Panels

      • Action Drawings and repaint

      • Some More Details on Updating a GUI*

    • 18.4 COLORS

      • Specifying a Drawing Color

      • Defining Colors

      • PITFALL: Using doubles to Define a Color

      • The JColorChooser Dialog Window

    • 18.5 FONTS AND THE drawString METHOD

      • The drawString Method

      • Fonts

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 19 Java Never Ends

    • 19.1 MULTITHREADING

      • EXAMPLE: A Nonresponsive GUI

      • Thread.sleep

      • The getGraphics Method

      • Fixing a Nonresponsive Program Using Threads

      • EXAMPLE: A Multithreaded Program

      • The Class Thread

      • The Runnable Interface*

      • Race Conditions and Thread Synchronization*

    • 19.2 NETWORKING WITH STREAM SOCKETS

      • Sockets

      • Sockets and Threading

    • 19.3 JAVABEANS

      • The Component Model

      • The JavaBeans Model

    • 19.4 JAVA AND DATABASE CONNECTIONS

      • Relational Databases

      • Java DB and JDBC

      • SQL

    • 19.5 WEB PROGRAMMING WITH JAVA SERVER PAGES

      • Applets, Servlets, and Java Server Pages

      • Oracle GlassFish Enterprise Server

      • HTML Forms—the Common Gateway Interface

      • JSP Declarations, Expressions, Scriptlets, and Directives

      • Chapter Summary

      • Answers to Self-Test Exercises

      • Programming Projects

  • Chapter 20 Applets and HTML

  • Appendix 1 Keywords

  • Appendix 2 Precedence and Associativity Rules

  • Appendix 3 ASCII Character Set

  • Appendix 4 Format Specifications for printf

  • Appendix 5 Summary of Classes and Interfaces

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

    • Y

Nội dung

[...]... catch Blocks 55 1 PITFALL: Catch the More Specific Exception First 55 3 9.2 54 6 THROWING EXCEPTIONS IN METHODS 55 6 Throwing an Exception in a Method 55 6 Declaring Exceptions in a throws Clause 55 8 Exceptions to the Catch or Declare Rule 56 1 throws Clause in Derived Classes 56 2 When to Use Exceptions 56 3 Event-Driven Programming ★ 56 4 9.3 MORE PROGRAMMING TECHNIQUES FOR EXCEPTION HANDLING 56 6 PITFALL:... 350 TIP: Use for Loops with Arrays 352 PITFALL: Array Indices Always Start with Zero 352 PITFALL: Array Index Out of Bounds 352 Initializing Arrays 353 PITFALL: An Array of Characters Is Not a String 355 6.2 ARRAYS AND REFERENCES 356 Arrays Are Objects 356 PITFALL: Arrays with a Class Base Type 358 Array Parameters 358 PITFALL: Use of = and == with Arrays 360 Arguments for the Method main ★ 3 65 Methods... Exercises 51 6 Programming Projects 51 8 Chapter 9 9.1 Exception Handling 52 3 EXCEPTION HANDLING BASICS 52 5 try-catch Mechanism 52 5 Exception Handling with the Scanner Class 52 7 TIP: Exception Controlled Loops 52 8 Throwing Exceptions 53 0 EXAMPLE: A Toy Example of Exception Handling 53 2 Exception Classes 53 7 Exception Classes from Standard Packages 53 8 Defining Exception Classes 54 0 TIP: Preserve getMessage 54 4... Blocks 56 6 The finally Block ★ 56 6 Rethrowing an Exception ★ 56 8 The AssertionError Class ★ 56 8 ArrayIndexOutOfBoundsException 56 9 Contents Chapter Summary 56 9 Answers to Self-Test Exercises 57 0 Programming Projects 57 4 Chapter 10 10.1 File I/O 57 7 INTRODUCTION TO FILE I/O 57 8 Streams 57 8 Text Files and Binary Files 10.2 TEXT FILES 57 9 58 0 Writing to a Text File 58 0 PITFALL: A try Block Is a Block 58 6... Downcasting 50 1 496 xxi xxii Contents TIP: Checking to See Whether Downcasting Is Legitimate ★ 50 1 A First Look at the clone Method 50 4 PITFALL: Sometimes the clone Method Return Type Is Object 50 5 PITFALL: Limitations of Copy Constructors ★ 50 6 8.2 ABSTRACT CLASSES 50 9 Abstract Classes 51 0 PITFALL: You Cannot Create Instances of an Abstract Class TIP: An Abstract Class Is a Type 51 5 51 4 Chapter Summary 51 6... EXAMPLE: A Linked List with a Deep Copy clone Method ★ 832 TIP: Cloning Is an “All or Nothing” Affair 8 35 15. 3 ITERATORS 8 35 Defining an Iterator Class 836 Adding and Deleting Nodes 841 15. 4 VARIATIONS ON A LINKED LIST 846 Doubly Linked List 846 The Stack Data Structure 855 The Queue Data Structure 857 Running Times and Big-O Notation Efficiency of Linked Lists 8 65 15. 5 HASH TABLES WITH CHAINING 860 866... Overwriting an Output File 58 6 Appending to a Text File 58 7 TIP: toString Helps with Text File Output 58 8 Reading from a Text File 58 9 Reading a Text File Using Scanner 58 9 Testing for the End of a Text File with Scanner 59 2 Reading a Text File Using BufferedReader 59 9 TIP: Reading Numbers with BufferedReader 603 Testing for the End of a Text File with BufferedReader 603 Path Names 6 05 Nested Constructor... Programming Projects 10 75 Chapter 19 19.1 10 65 10 65 1071 Java Never Ends 1079 MULTITHREADING 1080 EXAMPLE: A Nonresponsive GUI 1081 Thread.sleep 1081 The getGraphics Method 10 85 Fixing a Nonresponsive Program Using Threads 1086 EXAMPLE: A Multithreaded Program 1086 The Class Thread 1087 The Runnable Interface ★ 1090 Race Conditions and Thread Synchronization ★ 1093 19.2 NETWORKING WITH STREAM SOCKETS 1098... about Methods 180 TIP: Any Method Can Be Used as a void Method 184 Local Variables 186 Blocks 187 TIP: Declaring Variables in a for Statement 188 Parameters of a Primitive Type 188 PITFALL: Use of the Terms “Parameter” and “Argument” 1 95 Simple Cases with Class Parameters 197 The this Parameter 197 Methods That Return a Boolean Value 199 The Methods equals and toString 202 Recursive Methods 2 05 TIP:... However, this book, and many other books and programmers, consider Java a general-purpose programming language that is suitable for most any application, whether it involves the Internet or not The first version of Java was neither of these things, but it evolved into both In 1991, James Gosling led a team at Sun Microsystems that developed the first version of Java (which was not yet called Java) This . progressed to these more advanced topics. CHANGES IN THIS EDITION This fifth edition presents the same programming philosophy as the fourth edition. For instructors, you can teach the same course,. class="bi x0 y0 w0 h0" alt="" This page intentionally left blank ABSOLUTE JAVA ™ 5 th Edition This page intentionally left blank ABSOLUTE JAVA ™ 5 th Edition Walter Savitch. the same topics in the same order with no changes in the material covered or the chapters assigned. The changes to this edition consist almost exclusively of supplementary material added to the

Ngày đăng: 28/03/2014, 21:20

TỪ KHÓA LIÊN QUAN