Java By Abstraction
A Client-View Approach
H. Roumani
Table of Contents
Preface
To the Student
Chapter 1: Introduction to Programming
1.1 Anatomy
of a Program
1.1.1 A Quick Tour
1.1.2 Language Elements
1.1.3 Program Execution
1.2 The Declaration Statement
1.2.1 Variable Names
1.2.2 The Integer Types
1.2.3 Declaration and Memory
1.2.4 Other Data Types
1.2.5 Primitive and Non-Primitive Types
1.3 The Assignment Statement
1.3.1 The int Operators
1.3.2 Other Arithmetic Operators
1.3.3 Mixed Types and Casting
Lab 1: The Computing Environment on Campus
Chapter 2: Programming By Delegation
2.1 What Is Delegation?
2.1.1 Delegating
to a static Method
2.1.2 Delegating
to an Object
2.1.3 A Unified View of Delegation
2.1.4 Case
Study: Procuring Bread
2.2 Application Development
2.2.1 Application
Architecture
2.2.2 The Client View
2.2.3 Post-Compilation
Errors
2.2.4 Case
Study: The Java Standard Library
2.2.5 Ready-Made
I/O Components
2.3 Software Engineering
2.3.1 Risk
Mitigation by Early Exposure
2.3.2 Handling
Constants
2.3.3 Contracts
2.3.4 Case
Study: Meet the Managers
Lab 2: The Development Environment
Chapter 3: Using APIs
3.1 Anatomy of an API
3.1.1 Overall Layout
3.1.2 Fields
3.1.3 Methods
3.2 A Development Walkthrough
3.2.1 The Development Process
3.2.2 The Mortgage Application
3.2.3 Output Formatting
3.2.4 Relational Operators
3.2.5 Input Validation
3.2.6 Assertions
3.3 General Characteristics of Utility
Classes
3.3.1 Memory Diagram
3.3.2 Advantages of Utility Classes
3.3.3 Case Study: Dialog I/O
Lab 3: A Development Project
Chapter 4: Using Objects
4.1 What is an Object?
4.1.1 An Abstraction View
4.1.2 An API View
4.2 The Life of an Object
4.2.1 The Birth of an Object
4.2.2 Objects at Work
4.2.3 The Object and its Reference
4.2.4 Objects Equality
4.2.5 Obligatory Methods
4.2.6 The Death of an Object
4.3 The Object's State
4.3.1 Accessors and Mutators
4.3.2 Attribute Privacy
4.3.3 Object with static Features
4.3.4 Object with final Features
Lab 4: Exploring Objects
Chapter 5: Control Structures
5.1 Selection
5.1.1 Flow of Control
5.1.2 The if
Statement
5.1.3 Building the Condition
5.1.4 Multi-Way Branching
5.2 Iteration
5.2.1 Flow of Control
5.2.2 The for
statement
5.2.3 Building the
5.2.4 Nested Loops
5.3 Applications
5.3.1 Exception-Free Input Validation
5.3.2 File I/O
Lab 5: Exploring Control Structures
Chapter 6: Strings
6.1 Language Support
6.1.1 The String Class
6.1.2 The Masquerade and the + Operator
6.2 String Handling
6.2.1 Method Overview
6.2.2 Accessors
6.2.3 Transformers
6.2.4 Comparators
6.2.5 Numeric Strings
6.3 Applications
6.3.1 Character Frequency
6.3.2 Character Substitution
6.3.3 Fixed-Size Codes
6.3.4 Variable-Size Codes
6.4 Advanced String Handling
6.4.1 The StringBuffer Class
6.4.2 Pattern Matching & Regular Expressions
6.4.3 Command-Line Arguments
Lab 6: Strings & Cryptography
Chapter 7: Software Development
7.1 The Development Process
7.1.1 The Waterfall Model
7.1.2 The Iterative Methodology
7.1.3 Elements of UML
7.2 Software Testing
7.2.1 The Essence of Testing
7.2.2 The Test Vector
7.2.3 Debugging
7.3 Case Study: Trajectories
7.3.1 Iterative Development
7.3.2 Unit Testing
7.3.3 Integration Testing
Lab 7: Testing & HTML Parsing
Chapter 8: Aggregation
8.1 What is Aggregation?
8.1.1 Definition and Terminology
8.1.2 The Aggregate's Constructor
8.1.3 Accessors & Mutators
8.1.4 The Client's Perspective
8.1.5 Case Study: I/O Streams
8.1.6 Case Study: Graphics
8.2 Working with Collections
8.2.1 Creating the Collection
8.2.2 Adding / Removing Elements
8.2.3 Indexed Traversals
8.2.4 Iterator-Based Traversal
8.2.5 Searching
8.2.6 Search Complexity
Lab 8: The Calendar & Graphics
Aggregates
Chapter 9: Inheritance
9.1 What is Inheritance?
9.1.1 Definition and Terminology
9.1.2 The Subclass API
9.1.3 Case Study: Credit Cards
9.2 Working with Inheritance Hierarchies
9.2.1 The Substitutability Principle
9.2.2 Early and Late Binding
9.2.3 Polymorphism
9.2.4 Abstract Classes and Interfaces
9.2.5 Case Study: Revisiting Streams
9.3 Obligatory Inheritance
9.3.1 The Object Class
9.3.2 Case Study: Object Serialization
9.3.3 Generics
Lab 9: The Fraction & Shape
Hierarchies
Chapter 10: The Collection Framework
10.1 What is the Collection Framework?
10.1.1 The
10.1.2 The Implementing Classes
10.1.3 Revisiting Generics
10.2 Using the Framework
10.2.1 API Highlights
10.2.2 The Iterator
10.2.3 Searching and Sorting
10.2.4 Summary of Features
10.3 Applications
10.3.1 Detecting Duplicates
10.3.2 Word Frequencies
10.3.3 Sorting a Map
Lab 10: A Robot in a Maze
Chapter 11: Exception Handling
11.1 What are Exceptions?
11.1.1 Runtime Errors
11.1.2 The Delegation Model
11.2 Java's Exception Constructs
11.2.1 The Basic try-catch Construct
11.2.2 Handling Multiple Exceptions
11.2.3 Other Constructs
11.3 Exception Objects
11.3.1 The Throwable Hierarchy
11.3.2 Object-Oriented Exception Handling
11.3.3 Checked Exceptions
11.4 Building Robust Apps
11.4.1 Validation versus Exception
11.4.2 Logic Errors
Lab 11 Socket Programming
Chapter 12: A Multi-Class Application
12.1 Introduction
12.1.1 Multi-Class Applications
12.1.2 The Abstract Foods Company
12.2 Inventory Control
12.2.1 The Items
12.2.2 The Fresh Items
12.2.3 The Inventory Map
12.3 Contacts
12.3.1 The Need for an Abstract Class
12.3.2 The Clients
12.3.3 The Suppliers
12.3.4 The Contacts Map
12.4 Transactions
12.4.1 Why Are Transactions Needed?
12.4.2 The Trx Class
12.4.3 The Journal List
Lab 12: Inventory, Contacts, and
Transactions
Appendix A UCS, Unicode, and ASCII
Appendix B Operators & Precedence
Appendix C Coding Style
Appendix D A Glimpse of the Implementer's View
Appendix E The type API
Index