This book introduces programmers to objects at a gradual pace. The syntax boxes are revised to show typical code examples rather than abstract notation. This includes optional example modules using Alice and Greenfoot. The examples feature annotations with dos and don'ts along with cross references to more detailed explanations in the text. New tables show a large number of typical and cautionary examples. New programming and review problems are also presented that ensure a broad coverage of topics. In addition, Java 7 features are included to provide programmers with the most up-to-date information.
Preface.
Special Features.
Chapter 1. Introduction.
1.1 What Is Programming?
1.2 The Anatomy of a Computer.
1.3 Translating Human-Readable Programs to Machine Code.
1.4 The Java Programming Language.
1.5 The Structure of a Simple Program.
1.6 Compiling and Running a Java Program.
1.7 Errors.
1.8 Algorithms.
Chapter 2. Using Objects.
2.1 Types.
2.2 Variables.
2.3 The Assignment Operator.
2.4 Objects, Classes, and Methods.
2.5 Method Parameters and Retun Values.
2.6 Constructing Objects.
2.7 Accessor and Mutator Methods.
2.8 The API Documentation.
2.9T Implementing a Test Program.
2.10 Object References.
2.11G Graphical Applications and Frame Windows.
2.12G Drawing on a Component.
2.13G Ellipses, Lines, Text, and Color.
Chapter 3. Implementing Classes.
3.1 Instance Variables.
3.2 Encapsulation.
3.3 Specifying the Public Interface of a Class.
3.4 Commenting the Public Interface.
3.5 Providing the Class Implementation.
3.6T Unit Testing.
3.7 Local Variables.
3.8 Implicit Parameters.
3.9G Shape Classes.
Chapter 4. Fundamental Data Types.
4.1 Number Types.
4.2 Constants.
4.3 Arithmetic Operations and Mathematical Functions.
4.4 Calling Static Methods.
4.5 Strings.
4.6 Reading Input.
Chapter 5. Decisions.
5.1 The if Statement.
5.2 Comparing Values.
5.3 Multiple Alternatives.
5.4 Using Boolean Expressions.
5.5T Code Coverage.
Chapter 6. Iteration.
6.1 while Loops.
6.2 for Loops.
6.3 Common Loop Algorithms.
6.4 Nested Loops.
6.5 Application: Random Numbers and Simulations.
6.6T Using a Dubugger.
Chapter 7. Arrays and Array Lists.
7.1 Arrays.
7.2 Array Lists.
7.3 Wrappers and Auto-boxing.
7.4 The Enhanced for Loop.
7.5 Partially Filled Arrays.
7.6 Common Array Algorithms.
7.7T Regression Testing.
7.8 Two-Dimensional Arrays.
Chapter 8. Designing Classes.
8.1 Discovering Classes.
8.2 Cohesion and Coupling.
8.3 Immutable Classes.
8.4 Side Effects.
8.5 Preconditions and Postconditions.
8.6 Static Methods.
8.7 Static Variables.
8.8 Scope.
8.9 Packages.
8.10T Unit Test Frameworks.
Chapter 9. Interfaces and Polymorphism.
9.1 Using Interfaces for Algorithm Reuse.
9.2 Converting Between Class and Interface Types.
9.3 Polymorphism.
9.4 Using Interfaces for Callbacks.
9.5 Inner Classes.
9.6T Mock Objects.
9.7G Events, Event Sources, and Event Listeners.
9.8G Using Inner Classes for Listeners.
9.9G Building Applications with Buttons.
9.10G Processing Timer Events.
9.11G Mouse Events.
Chapter 10. Inheritance.
10.1 Inheritance Hierarchies.
10.2 Implementing Subclasses.
10.3 Overriding Methods.
10.4 Subclass Construction.
10.5 Converting Between Subclass and Superclass Types.
10.6 Polymorphism and Inheritance.
10.7 Object: The Cosmic Superclass.
10.8G Using Inheritance to Customize Frames.
Chapter 11. Input/Output and Exception Handling.
11.1 Reading and Writing Text Files.
11.2 Reading Text Input.
11.3 Throwing Exceptions.
11.4 Checked and Unchecked Exceptions.
11.5 Catching Exceptions.
11.6 The finally Clause.
11.7 Designing Your Own Exception Types.
11.8 Case Study: A Complete Example.
Chapter 12. Object-Oriented Design.
12.1 The Software Life Cycle.
12.2 Discovering Classes.
12.3 Relationships Between Classes.
12.4 Case Study: Printing an Invoice.
12.5 Case Study: An Automatic Teller Machine.
Chapter 13. Recursion.
13.1 Triangle Numbers.
13.2 Recursive Helper Methods.
13.3 The Efficiency of Recursion.
13.4 Permutations.
13.5 Mutual Recursions.
Chapter 14. Sorting and Searching.
14.1 Selection Sort.
14.2 Profiling the Selection Sort Algorithm.
14.3 Analyzing the Performance of the Selection Sort Algorithm.
14.4 Merge Sort.
14.5 Analyzing the Merge Sort Algorithm.
14.6 Searching.
14.7 Binary Search.
14.8 Sorting Real Data.
Chapter 15. An Introduction to Data Structures.
15.1 Using Linked Lists.
15.2 Implementing Linked Lists.
15.3 Abstract Data Types.
15.4 Stacks and Queues.
Chapter 16. Advanced Data Structures (Advanced).
16.1 Sets.
16.2 Maps.
16.3 Hash Tables.
16.4 Computing Hash Codes.
16.5 Binary Search Trees.
16.6 Binary Tree Traversal.
16.7 Priority Queues.
16.8 Heaps.
16.9 The Heapsort Algorithm.
Chapter 17. Generic Programming (Advanced).
17.1 Generic Classes and Type Parameters.
17.2 Implementing Generic Types.
17.3 Generic Methods.
17.4 Constraining Type Parameters.
17.5 Type Erasure.
Chapter 18. Graphical User Interfaces (Advanced).
18.1G Processing Text Input.
18.2G Text Areas.
18.3G Layout Management.
18.4G Choices.
18.5G Menus.
18.6G Exploring the Swing Documentation.
Appendices.
Appendix A. The Basic Latin and Latin-1 Subsets of Unicode.
Appendix B. Java Operator Summary.
Appendix C. Java Reserved Word Summary.
Appendix D. The Java Library.
Appendix E. Java Syntax Summary.
Appendix F. HTML Summary.
Appendix G. Tool Summary.
Appendix H. JavaDoc Summary.
Appendix I. Number Systems.
Appendix J. Bit and Shift Operations.
Appendix K. UML Summary.
Appendix L. Java Language Coding Guidelines.
Glossary.
Index.
Illustration Credits.