Description
Efnisyfirlit
- Preface for Instructors
- Preface for Students
- Acknowledgments
- Dependency Chart
- Brief Contents
- Contents
- Chapter 1: Introduction to Computers and Java
- 1.1 Computer Basics
- Hardware and Memory
- Programs
- Programming Languages, Compilers, and Interpreters
- Java Bytecode
- Class Loader
- 1.2 A Sip of Java
- History of the Java Language
- Applications and Applets
- A First Java Application Program
- Writing, Compiling, and Running a Java Program
- 1.3 Programming Basics
- Object-Oriented Programming
- Algorithms
- Testing and Debugging
- Software Reuse
- 1.4 Graphics Supplement
- A Sample Graphics Applet
- Size and Position of Figures
- Drawing Ovals and Circles
- Drawing Arcs
- Running an Applet
- Chapter Summary
- Chapter 2: Basic Computation
- 2.1 Variables and Expressions
- Variables
- Data Types
- Java Identifiers
- Assignment Statements
- Simple Input
- Simple Screen Output
- Constants
- Named Constants
- Assignment Compatibilities
- Type Casting
- Arithmetic Operators
- Parentheses and Precedence Rules
- Specialized Assignment Operators
- Case Study: Vending Machine Change
- Increment and Decrement Operators
- More About the Increment and Decrement Operators
- 2.2 The Class String
- String Constants and Variables
- Concatenation of Strings
- String Methods
- String Processing
- Escape Characters
- The Unicode Character Set
- 2.3 Keyboard and Screen I/O
- Screen Output
- Keyboard Input
- Other Input Delimiters (Optional)
- Formatted Output with printf (Optional)
- 2.4 Documentation and Style
- Meaningful Variable Names
- Comments
- Indentation
- Using Named Constants
- 2.5 Graphics Supplement
- Style Rules Applied to a Graphics Applet
- Creating a Java GUI Application with the JFrame Class
- Introducing the Class JOptionPane
- Reading Input as Other Numeric Types
- Programming Example: Change-Making Program with Windowing I/O
- Chapter Summary
- Chapter 3: Flow of Control: Branching
- 3.1 The if-else Statement
- The Basic if-else Statement
- Boolean Expressions
- Comparing Strings
- Nested if-else Statements
- Multibranch if-else Statements
- Programming Example: Assigning Letter Grades
- Case Study: Body Mass Index
- The Conditional Operator (Optional)
- The exit Method
- 3.2 The Type boolean
- Boolean Variables
- Precedence Rules
- Input and Output of Boolean Values
- 3.3 The switch Statement
- Enumerations
- 3.4 Graphics Supplement
- Specifying a Drawing Color
- A Dialog Box for a Yes-or-No Question
- Chapter Summary
- Chapter 4: Flow of Control: Loops
- 4.1 Java Loop Statements
- The while Statement
- The do-while Statement
- Programming Example: Bug Infestation
- Programming Example: Nested Loops
- The for Statement
- Declaring Variables Within a for Statement
- Using a Comma in a for Statement (Optional)
- The for-each Statement
- 4.2 Programming With Loops
- The Loop Body
- Initializing Statements
- Controlling the Number of Loop Iterations
- Case Study: Using a Boolean Variable to End a Loop
- Programming Example: Spending Spree
- The break Statement and continue Statement in Loops (Optional)
- Loop Bugs
- Tracing Variables
- Assertion Checks
- 4.3 Graphics Supplement
- Programming Example: A Multiface Applet
- The drawString Method
- Chapter Summary
- Chapter 5: Defining Classes and Methods
- 5.1 Class and Method Definitions
- Class Files and Separate Compilation
- Programming Example: Implementing a Dog Class
- Instance Variables
- Methods
- Defining void Methods
- Defining Methods That Return a Value
- Programming Example: First Try at Implementing a Species Class
- The Keyword this
- Local Variables
- Blocks
- Parameters of a Primitive Type
- 5.2 Information Hiding and Encapsulation
- Information Hiding
- Precondition and Postcondition Comments
- The public and private Modifiers
- Programming Example: A Demonstration of Why Instance Variables Should Be Private
- Programming Example: Another Implementation of a Class of Rectangles
- Accessor Methods and Mutator Methods
- Methods Calling Methods
- Programming Example: A Purchase Class
- Encapsulation
- Automatic Documentation with javadoc
- UML Class Diagrams
- 5.3 Objects and References
- Variables of a Class Type
- Defining an equals Method for a Class
- Programming Example: A Species Class
- Boolean-Valued Methods
- Case Study: Unit Testing
- Parameters of a Class Type
- Programming Example: Class-Type Parameters Versus Primitive-Type Parameters
- 5.4 Graphics Supplement
- The Graphics Class
- Programming Example: Multiple Faces, but with a Helping Method
- The Graphics2D Class and the Java2DTM API
- The init Method
- Adding Labels to an Applet
- Chapter Summary
- Chapter 6: More About Objects and Methods
- 6.1 Constructors
- Defining Constructors
- Calling Methods from Constructors
- Calling a Constructor from Other Constructors (Optional)
- 6.2 Static Variables and Static Methods
- Static Variables
- Static Methods
- Dividing the Task of a main Method into Subtasks
- Adding a main Method to a Class
- The Math Class
- Wrapper Classes
- 6.3 Writing Methods
- Case Study: Formatting Output
- Decomposition
- Addressing Compiler Concerns
- Testing Methods
- 6.4 Overloading
- Overloading Basics
- Overloading and Automatic Type Conversion
- Overloading and the Return Type
- Programming Example: A Class for Money
- 6.5 Information Hiding Revisited
- Privacy Leaks
- 6.6 Enumeration as a Class
- 6.7 Packages
- Packages and Importing
- Package Names and Directories
- Name Clashes
- 6.8 Graphics Supplement
- Adding Buttons
- Event-Driven Programming
- Programming Buttons
- Programming Example: A Complete Applet with Buttons
- Adding Icons
- Changing Visibility
- Programming Example: An Example of Changing Visibility
- Chapter Summary
- Chapter 7: Arrays
- 7.1 Array Basics
- Creating and Accessing Arrays
- Array Details
- The Instance Variable length
- More About Array Indices
- Initializing Arrays
- 7.2 Arrays in Classes and Methods
- Case Study: Sales Report
- Indexed Variables as Method Arguments
- Entire Arrays as Arguments to a Method
- Arguments for the Method main
- Array Assignment and Equality
- Methods That Return Arrays
- 7.3 Programming with Arrays and Classes
- Programming Example: A Specialized List Class
- Partially Filled Arrays
- 7.4 Sorting and Searching Arrays
- Selection Sort
- Other Sorting Algorithms
- Searching an Array
- 7.5 Multidimensional Arrays
- Multidimensional-Array Basics
- Multidimensional-Array Parameters and Returned Values
- Java’s Representation of Multidimensional Arrays
- Ragged Arrays (Optional)
- Programming Example: Employee Time Records
- 7.6 Graphics Supplement
- Text Areas and Text Fields
- Programming Example: A Question-and-Answer Applet
- The Classes JTextArea and JTextField
- Drawing Polygons
- Chapter Summary
- Chapter 8: Inheritance, Polymorphism, and Interfaces
- 8.1 Inheritance Basics
- Derived Classes
- Overriding Method Definitions
- Overriding Versus Overloading
- The final Modifier
- Private Instance Variables and Private Methods of a Base Class
- UML Inheritance Diagrams
- 8.2 Programming with Inheritance
- Constructors in Derived Classes
- The this Method—Again
- Calling an Overridden Method
- Programming Example: A Derived Class of a Derived Class
- Another Way to Define the equals Method in Undergraduate
- Type Compatibility
- The Class Object
- A Better equals Method
- 8.3 Polymorphism
- Dynamic Binding and Inheritance
- Dynamic Binding with toString
- 8.4 Interfaces and Abstract Classes
- Class Interfaces
- Java Interfaces
- Implementing an Interface
- An Interface as a Type
- Extending an Interface
- Case Study: Character Graphics
- Case Study: The Comparable Interface
- Abstract Classes
- 8.5 Graphics Supplement
- The Class JApplet
- The Class JFrame
- Window Events and Window Listeners
- The ActionListener Interface
- What to Do Next
- Chapter Summary
- Chapter 9: Exception Handling
- 9.1 Basic Exception Handling
- Exceptions in Java
- Predefined Exception Classes
- 9.2 Defining Your Own Exception Classes
- 9.3 More About Exception Classes
- Declaring Exceptions (Passing the Buck)
- Kinds of Exceptions
- Errors
- Multiple Throws and Catches
- The finally Block
- Rethrowing an Exception (Optional)
- Case Study: A Line-Oriented Calculator
- 9.4 Graphics Supplement
- Exceptions in GUIs
- Programming Example: A JFrame GUI Using Exceptions
- Chapter Summary
- Chapter 10: Streams, File I/O, and Networking
- 10.1 An Overview of Streams and File I/O
- The Concept of a Stream
- Why Use Files for I/O?
- Text Files and Binary Files
- 10.2 Text-File I/O
- Creating a Text File
- Appending to a Text File
- Reading from a Text File
- 10.3 Techniques for any File
- The Class File
- Programming Example: Reading a File Name from the Keyboard
- Using Path Names
- Methods of the Class File
- Defining a Method to Open a Stream
- Case Study: Processing a Comma-Separated Values File
- 10.4 Basic Binary-File I/O
- Creating a Binary File
- Writing Primitive Values to a Binary File
- Writing Strings to a Binary File
- Some Details About writeUTF
- Reading from a Binary File
- The Class EOFException
- Programming Example: Processing a File of Binary Data
- 10.5 Binary-File I/O with Objects and Arrays
- Binary-File I/O with Objects of a Class
- Some Details of Serialization
- Array Objects in Binary Files
- 10.6 Network Communication with Streams
- 10.7 Graphics Supplement
- Programming Example: A JFrame GUI for Manipulating Files
- Chapter Summary
- Chapter 11: Recursion
- 11.1 The Basics of Recursion
- Case Study: Digits to Words
- How Recursion Works
- Infinite Recursion
- Recursive Methods Versus Iterative Methods
- Recursive Methods That Return a Value
- 11.2 Programming with Recursion
- Programming Example: Insisting That User Input Be Correct
- Case Study: Binary Search
- Programming Example: Merge Sort—A Recursive Sorting Method
- Chapter Summary
- Chapter 12: Dynamic Data Structures and Generics
- 12.1 Array-Based Data Structures
- The Class ArrayList
- Creating an Instance of ArrayList
- Using the Methods of ArrayList
- Programming Example: A To-Do List
- Parameterized Classes and Generic Data Types
- 12.2 The Java Collections Framework
- The Collection Interface
- The Class HashSet
- The Map Interface
- The Class HashMap
- 12.3 Linked Data Structures
- The Class LinkedList
- Linked Lists
- Implementing the Operations of a Linked List
- A Privacy Leak
- Inner Classes
- Node Inner Classes
- Iterators
- The Java Iterator Interface
- Exception Handling with Linked Lists
- Variations on a Linked List
- Other Linked Data Structures
- 12.4 Generics
- The Basics
- Programming Example: A Generic Linked List
- Chapter Summary
- Appendix 1: Getting Java
- Appendix 2: Running Applets
- Appendix 3: Protected and Package Modifiers
- Appendix 4: The DecimalFormat Class
- Other Pattern Symbols
- Appendix 5: Javadoc
- Commenting Classes for Use with javadoc
- Running javadoc
- Appendix 6: Differences Between C++ and Java
- Primitive Types
- Strings
- Flow of Control
- Testing for Equality
- main Method (Function) and Other Methods
- Files and Including Files
- Class and Method (Function) Definitions
- No Pointer Types in Java
- Method (Function) Parameters
- Arrays
- Garbage Collection
- Other Comparisons
- Appendix 7: Unicode Character Codes
- Appendix 8: Introduction to Java 8 Functional Programming
- Index
- Credits