名称: Java How to Program (9th Edition) 作者信息: 作者: Paul Deitel [ 英文 pdf ]
简单介绍
The Deitels’ groundbreaking How to Program series offers unparalleled breadth and depth of object-oriented programming concepts and intermediate-level topics for further study. Their Live Code Approach features thousands of lines of code in hundreds of complete working programs. This enables readers to confirm that programs run as expected. Java How to Program (Early Objects) 9e contains an optional extensive OOD/UML 2 case study on developing and implementing the software for an automated teller machine.This edition covers both Java SE7 and SE6.
Preface xxiii Before You Begin xxxiii 1 Introduction to Computers and Java 1 1.1 Introduction 2 1.2 Computers: Hardware and Software 5 1.3 Data Hierarchy 6 1.4 Computer Organization 8 1.5 Machine Languages, Assembly Languages and High-Level Languages 10 1.6 Introduction to Object Technology 11 1.7 Operating Systems 13 1.8 Programming Languages 16 1.9 Java and a Typical Java Development Environment 18 1.10 Test-Driving a Java Application 22 1.11 Web 2.0: Going Social 26 1.12 Software Technologies 29 1.13 Keeping Up-to-Date with Information Technologies 31 1.14 Wrap-Up 32
2 Introduction to Java Applications 37 2.1 Introduction 38 2.2 Your First Program in Java: Printing a Line of Text 38 2.3 Modifying Your First Java Program 44 2.4 Displaying Text with printf 46 2.5 Another Application: Adding Integers 47 2.6 Memory Concepts 52 2.7 Arithmetic 53 2.8 Decision Making: Equality and Relational Operators 56 2.9 Wrap-Up 60
3 Introduction to Classes, Objects, Methods and Strings 71 3.1 Introduction 72 3.2 Declaring a Class with a Method and Instantiating an Object of a Class 72 3.3 Declaring a Method with a Parameter 76 3.4 Instance Variables, set Methods and get Methods 79 3.5 Primitive Types vs. Reference Types 84 3.6 Initializing Objects with Constructors 85 3.7 Floating-Point Numbers and Type double 88 3.8 (Optional) GUI and Graphics Case Study: Using Dialog Boxes 92 3.9 Wrap-Up 95
4 Control Statements: Part 1 102 4.1 Introduction 103 4.2 Algorithms 103 4.3 Pseudocode 104 4.4 Control Structures 104 4.5 if Single-Selection Statement 107 4.6 if…else Double-Selection Statement 107 4.7 while Repetition Statement 112 4.8 Formulating Algorithms: Counter-Controlled Repetition 113 4.9 Formulating Algorithms: Sentinel-Controlled Repetition 118 4.10 Formulating Algorithms: Nested Control Statements 125 4.11 Compound Assignment Operators 130 4.12 Increment and Decrement Operators 130 4.13 Primitive Types 134 4.14 (Optional) GUI and Graphics Case Study: Creating Simple Drawings 134 4.15 Wrap-Up 138
5 Control Statements: Part 2 151 5.1 Introduction 152 5.2 Essentials of Counter-Controlled Repetition 152 5.3 for Repetition Statement 154 5.4 Examples Using the for Statement 158 5.5 do…while Repetition Statement 162 5.6 switch Multiple-Selection Statement 164 5.7 break and continue Statements 172 5.8 Logical Operators 173 5.9 Structured Programming Summary 179 5.10 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals 184 5.11 Wrap-Up 187
6 Methods: A Deeper Look 197 6.1 Introduction 198 6.2 Program Modules in Java 198 6.3 static Methods, static Fields and Class Math 200 6.4 Declaring Methods with Multiple Parameters 202 6.5 Notes on Declaring and Using Methods 205 6.6 Method-Call Stack and Activation Records 206 6.7 Argument Promotion and Casting 207 6.8 Java API Packages 208 6.9 Case Study: Random-Number Generation 210 6.9.1 Generalized Scaling and Shifting of Random Numbers 214 6.9.2 Random-Number Repeatability for Testing and Debugging 214 6.10 Case Study: A Game of Chance; Introducing Enumerations 215 6.11 Scope of Declarations 219 6.12 Method Overloading 222 6.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes 224 6.14 Wrap-Up 227
7 Arrays and ArrayLists 240 7.1 Introduction 241 7.2 Arrays 242 7.3 Declaring and Creating Arrays 243 7.4 Examples Using Arrays 244 7.5 Case Study: Card Shuffling and Dealing Simulation 254 7.6 Enhanced for Statement 258 7.7 Passing Arrays to Methods 259 7.8 Case Study: Class GradeBook Using an Array to Store Grades 262 7.9 Multidimensional Arrays 268 7.10 Case Study: Class GradeBook Using a Two-Dimensional Array 271 7.11 Variable-Length Argument Lists 278 7.12 Using Command-Line Arguments 279 7.13 Class Arrays 281 7.14 Introduction to Collections and Class ArrayList 284 7.15 (Optional) GUI and Graphics Case Study: Drawing Arcs 286 7.16 Wrap-Up 289
8 Classes and Objects: A Deeper Look 311 8.1 Introduction 312 8.2 Time Class Case Study 312 8.3 Controlling Access to Members 316 8.4 Referring to the Current Object’s Members with the this Reference 317 8.5 Time Class Case Study: Overloaded Constructors 320 8.6 Default and No-Argument Constructors 326 8.7 Notes on Set and Get Methods 326 8.8 Composition 328 8.9 Enumerations 331 8.10 Garbage Collection and Method finalize 333 8.11 static Class Members 334 8.12 static Import 338 8.13 final Instance Variables 339 8.14 Time Class Case Study: Creating Packages 340 8.15 Package Access 345 8.16 (Optional) GUI and Graphics Case Study: Using Objects with Graphics 347 8.17 Wrap-Up 351
9 Object-Oriented Programming: Inheritance 359 9.1 Introduction 360 9.2 Superclasses and Subclasses 361 9.3 protected Members 363 9.4 Relationship between Superclasses and Subclasses 364 9.4.1 Creating and Using a CommissionEmployee Class 364 9.4.2 Creating and Using a BasePlusCommissionEmployee Class 370 9.4.3 Creating a CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy 375 9.4.4 CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables 377 9.4.5 CommissionEmployee—BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables 380 9.5 Constructors in Subclasses 385 9.6 Software Engineering with Inheritance 386 9.7 Class Object 387 9.8 (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels 388 9.9 Wrap-Up 391
10 Object-Oriented Programming: Polymorphism 394 10.1 Introduction 395 10.2 Polymorphism Examples 397 10.3 Demonstrating Polymorphic Behavior 398 10.4 Abstract Classes and Methods 400 10.5 Case Study: Payroll System Using Polymorphism 403 10.5.1 Abstract Superclass Employee 404 10.5.2 Concrete Subclass SalariedEmployee 407 10.5.3 Concrete Subclass HourlyEmployee 408 10.5.4 Concrete Subclass CommissionEmployee 410 10.5.5 Indirect Concrete Subclass BasePlusCommissionEmployee 412 10.5.6 Polymorphic Processing, Operator instanceof and Downcasting 413 10.5.7 Summary of the Allowed Assignments Between Superclass and Subclass Variables 418 10.6 final Methods and Classes 418 10.7 Case Study: Creating and Using Interfaces 419 10.7.1 Developing a Payable Hierarchy 421 10.7.2 Interface Payable 422 10.7.3 Class Invoice 422 10.7.4 Modifying Class Employee to Implement Interface Payable 425 10.7.5 Modifying Class SalariedEmployee for Use in the Payable Hierarchy 427 10.7.6 Using Interface Payable to Process Invoices and Employees Polymorphically 428 10.7.7 Common Interfaces of the Java API 430 10.8 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism 431 10.9 Wrap-Up 433
11 Exception Handling: A Deeper Look 438 11.1 Introduction 439 11.2 Example: Divide by Zero without Exception Handling 439 11.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions 442 11.4 When to Use Exception Handling 447 11.5 Java Exception Hierarchy 447 11.6 finally Block 450 11.7 Stack Unwinding and Obtaining Information from an Exception Object 454 11.8 Chained Exceptions 457 11.9 Declaring New Exception Types 459 11.10 Preconditions and Postconditions 460 11.11 Assertions 461 11.12 (New in Java SE 7) Multi-catch: Handling Multiple Exceptions in One catch 462 11.13 (New in Java SE 7) try-with-Resources: Automatic Resource Deallocation 463 11.14 Wrap-Up 463
12 ATM Case Study, Part 1: Object-Oriented Design with the UML 469 12.1 Case Study Introduction 470 12.2 Examining the Requirements Document 470 12.3 Identifying the Classes in a Requirements Document 478 12.4 Identifying Class Attributes 484 12.5 Identifying Objects’ States and Activities 489 12.6 Identifying Class Operations 493 12.7 Indicating Collaboration Among Objects 499 12.8 Wrap-Up 506
13 ATM Case Study Part 2: Implementing an Object-Oriented Design 510 13.1 Introduction 511 13.2 Starting to Program the Classes of the ATM System 511 13.3 Incorporating Inheritance and Polymorphism into the ATM System 516 13.4 ATM Case Study Implementation 522 13.4.1 Class ATM 523 13.4.2 Class Screen 528 13.4.3 Class Keypad 529 13.4.4 Class CashDispenser 530 13.4.5 Class DepositSlot 531 13.4.6 Class Account 532 13.4.7 Class BankDatabase 534 13.4.8 Class Transaction 537 13.4.9 Class BalanceInquiry 53…