Paul Deitel和Harvey Deitel是全球畅销的编程语言教材和专业图书作家,“How to Program”系列是其最负盛名的一套计算机编程教材,已经销售近40年,并被翻译成中文在内的十几种语言。他们成立的Deitel & Associates公司是一家国际知名的企业培训和写作公司, 专门进行计算机编程语言、对象技术、移动应用开发及Internet和Web软件技术方面的培训和写作,出版了一流的编程专业的大学教材、 专业图书以及LiveLessons视频课程。
Paul Deitel和Harvey Deitel是全球畅销的编程语言教材和专业图书作家,“How to Program”系列是其最负盛名的一套计算机编程教材,已经销售近40年,并被翻译成中文在内的十几种语言。他们成立的Deitel & Associates公司是一家国际知名的企业培训和写作公司, 专门进行计算机编程语言、对象技术、移动应用开发及Internet和Web软件技术方面的培训和写作,出版了一流的编程专业的大学教材、 专业图书以及LiveLessons视频课程。
目錄:
Contents
Chapter 1Introduction to Computers and Java1
1.1Introduction2
1.2Computers: Hardware and Software4
1.3Data Hierarchy5
1.4Computer Organization6
1.5Machine Languages, Assembly Languages and High-Level Languages7
1.6Introduction to Object Technology8
1.7Operating Systems10
1.8Programming Languages12
1.9Java and a Typical Java Development Environment14
1.10Test-Driving a Java Application17
1.11Web 2.0: Going Social21
1.12Software Technologies23
1.13Keeping Up-to-Date with Information Technologies24
1.14Wrap-Up24
Chapter 2Introduction to Java Applications29
2.1Introduction29
2.2Your First Program in Java: Printing a Line of Text30
2.3Modifying Your First Java Program35
2.4Displaying Text with printf36
2.5Another Application: Adding Integers37
2.6Memory Concepts41
2.7Arithmetic42
2.8Decision Making: Equality and Relational Operators45
2.9Wrap-Up48
Chapter 3Introduction to Classes, Objects,Methods and Strings58
3.1Introduction58
3.2Declaring a Class with a Method and Instantiating an Object of a Class59
3.3Declaring a Method with a Parameter62
3.4Instance Variables, set Methods and get Methods64
3.5Primitive Types vs. Reference Types68
3.6Initializing Objects with Constructors69
3.7Floating-Point Numbers and Type double71
3.8Optional GUI and Graphics Case Study: Using Dialog Boxes75
3.9Wrap-Up77
Chapter 4Control Statements: Part 184
4.1Introduction85
4.2Algorithms85
4.3Pseudocode85
4.4Control Structures86
4.5if Single-Selection Statement88
4.6ifelse Double-Selection Statement89
4.7while Repetition Statement92
4.8Formulating Algorithms: Counter-Controlled Repetition93
4.9Formulating Algorithms: Sentinel-Controlled Repetition97
4.10Formulating Algorithms: Nested Control Statements103
4.11Compound Assignment Operators107
4.12Increment and Decrement Operators107
4.13Primitive Types110
4.14Optional GUI and Graphics Case Study: Creating Simple Drawings110
4.15Wrap-Up113
Chapter 5Control Statements: Part 2126
5.1Introduction126
5.2Essentials of Counter-Controlled Repetition127
5.3for Repetition Statement128
5.4Examples Using the for Statement131
5.5dowhile Repetition Statement135
5.6switch Multiple-Selection Statement136
5.7break and continue Statements142
5.8Logical Operators144
5.9Structured Programming Summary148
5.10Optional GUI and Graphics Case Study: Drawing Rectangles and Ovals152
5.11Wrap-Up154
Chapter 6Methods: A Deeper Look164
6.1Introduction165
6.2Program Modules in Java165
6.3static Methods, static Fields and Class Math166
6.4Declaring Methods with Multiple Parameters168
6.5Notes on Declaring and Using Methods171
6.6Method-Call Stack and Activation Records172
6.7Argument Promotion and Casting172
6.8Java API Packages173
6.9Case Study: Random-Number Generation175
6.10Case Study: A Game of Chance; Introducing Enumerations179
6.11Scope of Declarations182
6.12Method Overloading184
6.13Optional GUI and Graphics Case Study: Colors and Filled Shapes186
6.14Wrap-Up188
Chapter 7Arrays and ArrayLists201
7.1Introduction202
7.2Arrays202
7.3Declaring and Creating Arrays203
7.4Examples Using Arrays204
7.5Case Study: Card Shuffling and Dealing Simulation212
7.6Enhanced for Statement215
7.7Passing Arrays to Methods216
7.8Case Study: Class GradeBook Using an Array to Store Grades219
7.9Multidimensional Arrays223
7.10Case Study: Class GradeBook Using a Two-Dimensional Array226
7.11Variable-Length Argument Lists230
7.12Using Command-Line Arguments232
7.13Class Arrays233
7.14Introduction to Collections and Class ArrayList235
7.15Optional GUI and Graphics Case Study: Drawing Arcs237
7.16Wrap-Up240
Chapter 8Classes and Objects: A Deeper Look259
8.1Introduction260
8.2Time Class Case Study260
8.3Controlling Access to Members263
8.4Referring to the Current Objects Members with the this Reference264
8.5Time Class Case Study: Overloaded Constructors266
8.6Default and No-Argument Constructors270
8.7Notes on Set and Get Methods271
8.8Composition272
8.9Enumerations274
8.10Garbage Collection and Method finalize276
8.11static Class Members277
8.12static Import280
8.13final Instance Variables281
8.14Time Class Case Study: Creating Packages282
8.15Package Access286
8.16Optional GUI and Graphics Case Study: Using Objects with Graphics287
8.17Wrap-Up290
Chapter 9Object-Oriented Programming: Inheritance298
9.1Introduction298
9.2Superclasses and Subclasses299
9.3protected Members301
9.4Relationship between Superclasses and Subclasses302
9.5Constructors in Subclasses318
9.6Software Engineering with Inheritance319
9.7Class Object320
9.8Optional GUI and Graphics Case Study: Displaying Text and Images Using Labels320
9.9Wrap-Up322
Chapter 10Object-Oriented Programming: Polymorphism326
10.1Introduction327
10.2Polymorphism Examples328
10.3Demonstrating Polymorphic Behavior329
10.4Abstract Classes and Methods331
10.5Case Study: Payroll System Using Polymorphism333
10.6final Methods and Classes346
10.7Case Study: Creating and Using Interfaces346
10.8Optional GUI and Graphics Case Study: Drawing with Polymorphism356
10.9Wrap-Up357
Chapter 11Exception Handling: A Deeper Look362
11.1Introduction363
11.2Example: Divide by Zero without Exception Handling363
11.3Example: Handling ArithmeticExceptions and InputMismatchExceptions365
11.4When to Use Exception Handling369
11.5Java Exception Hierarchy369
11.6finally Block372
11.7Stack Unwinding and Obtaining Information from an Exception Object375
11.8Chained Exceptions378
11.9Declaring New Exception Types379
11.10Preconditions and Postconditions380
11.11Assertions381
11.12New in Java SE 7 Multi-catch: Handling Multiple Exceptions in One catch382
11.13New in Java SE 7 try-with-Resources: Automatic Resource Deallocation382
11.14Wrap-Up383
Chapter 12ATM Case Study, Part 1: Object-Oriented Design with the UML388
12.1Case Study Introduction388
12.2Examining the Requirements Document389
12.3Identifying the Classes in a Requirements Document395
12.4Identifying Class Attributes400
12.5Identifying Objects States and Activities404
12.6Identifying Class Operations407
12.7Indicating Collaboration Among Objects412
12.8Wrap-Up418
Chapter 13ATM Case Study Part 2: Implementing an Object-Oriented Design421
13.1Introduction422
13.2Starting to Program the Classes of the ATM System422
13.3Incorporating Inheritance and Polymorphism into the ATM System425
13.4ATM Case Study Implementation431
13.5Wrap-Up449
Chapter 14GUI Components: Part 1451
14.1Introduction452
14.2Javas New Nimbus Look-and-Feel453
14.3Simple GUI-Based InputOutput with JOptionPane454
14.4Overview of Swing Components456
14.5Displaying Text and Images in a Window457
14.6Text Fields and an Introduction to Event Handling with Nested Classes461
14.7Common GUI Event Types and Listener Interfaces466
14.8How Event Handling Works467
14.9JButton468
14.10Buttons That Maintain State471
14.11JComboBox; Using an Anonymous Inner Class for Event Handling476
14.12JList479
14.13Multiple-Selection Lists480
14.14Mouse Event Handling482
1
內容試閱:
Preface
Live in fragments no longer, only connect.
Edgar Morgan Foster
Welcome to Java and Java How to Program, Ninth Edition! This book presents leadingedge computing technologies for students, instructors and software developers.
The new Chapter 1 engages students with intriguing facts and figures to get them excited about studying computers and programming. The chapter includes a table of some of the research made possible by computers; current technology trends and hardware discussion; the data hierarchy; a table of mobile and Internet app platforms; a new section on social networking; an introduction to Android; a table of popular web services; a table of business and technology publications and websites that will help you stay up to date with the latest technology news and trends; and updated exercises.
The book is appropriate for introductory course sequences based on the ACMIEEE curriculum recommendations and for AP Computer Science exam preparation.
We focus on software engineering best practices. At the heart of the book is the Deitel signature live-code approachconcepts are presented in the context of complete working programs, rather than in code snippets. Each complete code example is accompanied by live sample executions. All the source code is available at www.deitel.combooks jhtp9.
As you read the book, if you have questions, send an e-mail to deitel@deitel.com; well respond promptly. For updates on this book, visit www.deitel.combooksjhtp9, follow us on Facebook www.deitel.comdeitelfan and Twitter @deitel, and subscribe to the Deitel Buzz Online newsletter www.deitel.comnewsletter subscribe.html.
New and Updated Features
Here are the updates weve made for Java How to Program, 9e:
Java Standard Edition SE 7
l Easy to use as a Java SE 6 or Java SE 7 book. There are a few Java Standard Edition SE 7 features that affect CS 1 and CS 2 courses. We cover those features in optional modular sections that are easy to include or omit. Heres some of the new functionality: Strings in switch statements, the try-with-resources statement for managing AutoClosable objects, multi-catch for defining a single exception handler to replace multiple exception handlers that perform the same task, the NIO filesystem APIs and inferring the types of generic objects from the variable theyre assigned to by using the <> notation. We also overview the new concurrency API features.
l Java SE 7 filesystem APIs. We provide an alternate online version of Chapter 17, Files, Streams and Object Serialization, thats reimplemented with the new filesystem APIs from Java SE 7.
l Java SE 7s AutoClosable versions of Connection, Statement and ResultSet. With the source code for Chapter 28, Accessing Databases with JDBC, we provide a version of the chapters first example thats implemented using Java SE 7s AutoClosable versions of Connection, Statement and ResultSet. AutoClosable objects reduce the likelihood of resource leaks when you use them with Java SE 7s try-with-resources statement, which automatically closes the AutoClosable objects allocated in the parentheses following the try keyword.
Pedagogic Features
l Enhanced Making a Difference exercises set. We encourage you to use computers and the Internet to research and solve significant social problems. These exercises are meant to increase awareness and discussion of important issues the world is facing. We hope youll approach them with your own values, politics and beliefs. Check out our new Making a Difference Resource Center at www.deitel.com MakingADifference for additional ideas you may want to investigate further.
l Page numbers for key terms in chapter summaries. For key terms that appear in the chapter summaries, we include the page number of the key terms defining occurrence.
Object Technology
l Object-oriented programming and design. We introduce the basic concepts and terminology of object technology in Chapter 1. Students develop their first customized classes and objects in Chapter 3. Presenting objects and classes early gets students t