书籍详情
JAVA程序设计与问题解决:基础篇(英文版.第4版)
作者:(美)萨维奇 著
出版社:人民邮电出版社
出版时间:2006-12-01
ISBN:9787115152886
定价:¥59.00
购买这本书可以去
内容简介
本书是国外高校采用率很高的Java程序设计经典教材。书中以Java基础知识为主,包括基本类型、字符串、控制流、类和方法的定义、数组、继承等,此外,还介绍了一些编程技巧。本书使用了J2SE 5.0的最新特性,并且包含新的可选讲的图形编程内容和贯穿全书的GUI材料。本书内容高度协调,包含自测题、编程提示和编程项目以及关于编程缺陷和容易出错的程序语言特征的章节。.本书适合作为高等院校计算机专业本科生或研究生Java语言程序设计课程的教材,也适合相关技术人员参考。 本书是一部享有盛誉的Java教程,已被全球包括哈佛大学、普度大学、得克萨斯大学奥斯汀分校、密歇根大学、加州大学洛杉矶分校等名校在内的200多所高校采用为教材。..书中作者在讲授Java程序设计语言基础知识的同时,还将问题求解的技能、编程技巧和良好的编程实践融会其中。流畅易读的语言,透彻清晰的叙述,精心编排的版式和内容,充分体现了作者数十年计算机语言教学的经验和功力。新版覆盖了Java 5.0,而且包含了可选讲的图形编程内容。书中包含丰富的自测题、编程技巧提示、编程项目和常见编程错误,而且内容组织方式非常灵活,可以根据实际教学需要调整授课内容和讲授顺序,适合各种教学方式,也是极好的自学教程。...
作者简介
作者:Walter SavitchWalter Savitch加州大学圣迭戈分校退休教授。1960年于加州大学伯克利分校获得博士学位,曾担任加州大学圣迭戈分校计算机科学系教授和认知科学跨学科博士项目主任。他在复杂性理论和并行计算模型方面做出了重要贡献,研究领域还包括形式语言理论、计算语言学等。除本书外,他著有一系列编程语言教材,都广受欢迎,畅销不衰,被誉为读者最多的计算机编程语言图书作者。...
目录
CHAPTER 1 Introduction to Computers and Java 3
Objectives 4
Prerequisites 4
1.1 Computer Basics 5
Hardware and Memory 5
Programs 7
Programming Languages and Compilers 9
Java Byte-Code 10
Class Loader 12
1.2 Designing Programs 13
Object-Oriented Programming 13
Encapsulation 14
Polymorphism 15
Inheritance 16
If You Know Some Other Programming Language 17
Algorithms 17
Reusable Components 18
Testing and Debugging 19
1.3 A Sip of Java 21
History of the Java Language 21
Applets 22
A First Java Application Program 22
Compiling a Java Program or Class 27
Running a Java Program 29
1.4 Graphics Supplement (Optional) 29
Objects and Methods 30
A Sample Graphics Applet 30
Size and Positions of Figures 33
Drawing Arcs 36
Running an Applet 36
Chapter Summary 39
Answers to Self-Test Questions 40
Programming Projects 42
CHAPTER 2 Primitive Types, Strings, and Console I/O 45
Objectives 46
Prerequisites 46
2.1 Primitive Types and Expressions 47
Variables 47
Java Identifiers 51
Primitive Types 52
Assignment Statements 53
Specialized Assignment Operators 55
Simple Screen Output 56
Simple Input 56
Number Constants 58
Assignment Compatibilities 59
Type Casting 61
Programming Tip: Initialize Variables 63
Arithmetic Operators 66
Parentheses and Precedence Rules 67
Case Study: Vending Machine Change 69
Increment and Decrement Operators 74
More about the Increment and Decrement Operators 75
2.2 The Class String 76
String Constants and Variables 76
Concatenation of Strings 77
Classes 78
String Methods 79
String Processing 83
Escape Characters 84
The Unicode Character Set 85
2.3 Keyboard and Screen I/O 87
Screen Output 87
Keyboard Input 90
2.4 Documentation and Style 98
Programming Tip: Use Meaningful Names for Variables 99
Documentation and Comments 99
Indenting 102
Named Constants 102
2.5 Graphics Supplement (Optional) 106
Programming Example: Style Rules Applied to a Graphics Applet 106
JOpti onPane 106
Inputting Other Numeric Types 115
Programming Example: Change-Making Program with Windowing I/O 117
Chapter Summary 120
Answers to Self-Test Questions 120
Programming Projects 125
CHAPTER 3 F1ow of Contro1 129
Objectives 130
Prerequisites 130
3.1 Branching Statements 130
The if-eIse Statement 130
Introduction to Boolean Expressions 134
Programming Tip: Alphabetical Order 139
Nested Statements and Compound Statements 142
Multibranch if-e1se Statements 145
Programming Example: Assigning Letter Grades 146
The switch Statement 149
The Conditional Operator (Optional) 153
3.2 Java Loop Statements 155
whi1e Statements 156
The do-whi1e Statement 160
Programming Example: Bug Infestation 164
The for Statement 168
The Comma in for Statements (Optional) 172
The break Statement in Loops 175
The exit Method 177
3.3 Programming with Loops 179
The Loop Body 179
Initializing Statements 181
Ending a Loop 182
Programming Example: Nested Loops 183
Programming Tip: Avoid Declaring Variables in a Loop Body 184
Loop Bugs 184
Tracing Variables 188
3.4 The Type boo] ean 189
Boolean Expressions and Boolean Variables 190
Programming Tip: Naming Boolean Variables 191
Precedence Rules 192
Input and Output of Boolean Values 195
Case Study: Using a Boolean Variable to End a Loop 195
3.5 Graphics Supplement (Optional) 199
Specifying a Drawing Color 199
Programming Example: A Multiface Applet 203
The drawString Method 208
A JOptionPane Yes/No Window 209
Chapter Summary 211
Answers to Self-Test Questions 211
Programming Projects 217
CHAPTER 4 Defining Classes and Methods 221
Objectives 222
Prerequisites 222
4.1 Class and Method Definitions 222
Class Files and Separate Compilation 224
Instance Variables 225
Using Methods 228
void Method Definitions 231
Methods That Return a Value 233
The this Parameter 238
Local Variables 240
Blocks 242
Parameters of a Primitive Type 243
Summary of Class and Method Definition Syntax 249
4.2 Information Hiding and Encapsulation 250
Information Hiding 250
Programming Tip: Parameter Names Are Local to the Method 251
Precondition and Postcondition Comments 251
The public and private Modifiers 254
Programming Tip: Instance Variables Should Be prirate 257
Programming Example: A Purchase Class 261
Encapsulation 265
Automatic Documentation with javadoc 268
UML Class Diagrams 268
4.3 Objects and Reference 270
Variables of a Class Type and Objects 270
Programming Example: A Species Class 279
Boolean-Valued Methods 282
Class Parameters 284
Comparing Class Parameters and Primitive-Type Parameters 287
4.4 Graphics Supplement (Optional) 291
The G raphi cs Class 291
Programming Example: Multiple Faces Redone with a Helping Method 294
The init Method 298
Adding Labels to an Applet 298
Chapter Summary 302
Answers to Self-Test Questions 303
Programming Projects 310
CHAPTER 5 More About Objects and Methods 315
Objectives 316
Prerequisites 316
5.1 Programming with Methods 317
Methods Calling Methods 317
Programming Tip: Make Helping Methods Private 323
5.2 Static Methods and Static Variables 326
Static Methods 326
Static Variables (Optional) 332
The Math Class 334
Integer, Double, and Other Wrapper Classes 337
5.3 Designing Methods 343
Case Study: Formatting Output 343
Top-Down Design 348
Testing Methods 350
5.4 Overloading 352
Overloading Basics 352
Programming Example: A Pet Class 355
Programming Example: A Class for Money 363
5.5 Constructors 369
Defining Constructors 370
Programming Tip: You Can Use Other Methods in a Constructor 378
5.6 Information Hiding Revisited 380
5.7 Packages 384
Packages and Importing 384
Package Names and Directories 385
Name Clashes 388
5.8 Graphics Supplement (Optional) 389
Programming Tip: Code Appearance and Actions Separately 389
Adding Buttons 390
Event-Driven Programming 391
Programming Example: A Complete Button Applet 391
Programming Buttons 392
Icons 399
Changing Visibility 401
Programming Example: An Example of Changing Visibility 4Ol
What's Next 405
Chapter Summary 405
Answers to Self-Test Questions 406
Programming projects 412
CHAPTER 6 Arrays 417
Objectives 418
Prerequisites 418
6.1 Array Basics 419
Creating and Accessing Arrays 419
Array Details 420
Programming Tip: Use Singular Array Names 424
The 1ength Instance Variable 425
Programming Tip: Use a for Loop to Step Through an Array 427
Initializing Arrays 429
6.2 Arrays in Classes and Methods 430
Case Study: Sales Report 430
Indexed Variables as Method Arguments 438
Entire Arrays as Method Arguments 440
Arguments for the Method mai n 441
Methods That Return Arrays 446
6.3 Programming with Arrays and Classes 449
Programming Example: A Specialized List Class 450
Partially Filled Arrays 457
Searching an Array 457
6.4 Sorting Arrays 460
Selection Sort 460
Other Sorting Algorithms 465
6.5 Multidimensional Arrays 465
Multidimensional-Array Basics 467
Multidimensional-Array Parameters and Returned Values 470
Implementation of Multidimensional Arrays 471
Ragged Arrays (Optional) 475
Programming Example: Employee Time Records 476
6.6 Graphics Supplement (Optional) 482
Graphics Supplement Part 1: Text Areas and Text Fields 483
Programming Example: A Question-and-Answer Applet 483
JTextArea and JTextFi el d Objects 483
Graphics Supplement Part 2: Drawing Polygons 487
Drawing Polygons 487
Chapter Summary 491
Answers to Self-Test Questions 492
Programming Projects 497
CHAPTER 7 Inheritance 501
Objectives 502
Prerequisites 502
7.1 Inheritance Basics 502
Programming Example: A Person Class 503
Derived Classes 504
Overriding Method Definitions 507
Overriding Versus Overloading 508
The final Modifier 508
Programming Tip: Assume That Your Coworkers Are Malicious 510
UML Inheritance Diagrams 510
7.2 Programming with Inheritance 513
Constructors in Derived Classes 513
The this Method (Optional) 514
Call to an Overridden Method 515
Programming Example: Multilevel Derived Classes 516
A Subtle Point About Overloading and Overriding (Optional) 521
Programming Tip: An Object Can Have More than One Type 522
Programming Tip: “Is a” and “Has a” Relations 525
The Class Object 526
Case Study: Character Graphics 528
Abstract Classes 538
Interfaces 542
7.3 Dynamic Binding and Polymorphism 544
Dynamic Binding 544
Type Checking and Dynamic Binding 546
Dynamic Binding with toString 547
Polymorphism 548
7.4 Graphics Supplement (Optional) 551
The Class JApplet 551
The Class JFrame 552
Window Events and Window Listeners 555
The ActionListener Interface 556
Programming Example: Happy Face as a JFrame 557
What To Do Next 558
Chapter Summary 559
Answers to Self-Test Questions 559
Programming Projects 565
Objectives 4
Prerequisites 4
1.1 Computer Basics 5
Hardware and Memory 5
Programs 7
Programming Languages and Compilers 9
Java Byte-Code 10
Class Loader 12
1.2 Designing Programs 13
Object-Oriented Programming 13
Encapsulation 14
Polymorphism 15
Inheritance 16
If You Know Some Other Programming Language 17
Algorithms 17
Reusable Components 18
Testing and Debugging 19
1.3 A Sip of Java 21
History of the Java Language 21
Applets 22
A First Java Application Program 22
Compiling a Java Program or Class 27
Running a Java Program 29
1.4 Graphics Supplement (Optional) 29
Objects and Methods 30
A Sample Graphics Applet 30
Size and Positions of Figures 33
Drawing Arcs 36
Running an Applet 36
Chapter Summary 39
Answers to Self-Test Questions 40
Programming Projects 42
CHAPTER 2 Primitive Types, Strings, and Console I/O 45
Objectives 46
Prerequisites 46
2.1 Primitive Types and Expressions 47
Variables 47
Java Identifiers 51
Primitive Types 52
Assignment Statements 53
Specialized Assignment Operators 55
Simple Screen Output 56
Simple Input 56
Number Constants 58
Assignment Compatibilities 59
Type Casting 61
Programming Tip: Initialize Variables 63
Arithmetic Operators 66
Parentheses and Precedence Rules 67
Case Study: Vending Machine Change 69
Increment and Decrement Operators 74
More about the Increment and Decrement Operators 75
2.2 The Class String 76
String Constants and Variables 76
Concatenation of Strings 77
Classes 78
String Methods 79
String Processing 83
Escape Characters 84
The Unicode Character Set 85
2.3 Keyboard and Screen I/O 87
Screen Output 87
Keyboard Input 90
2.4 Documentation and Style 98
Programming Tip: Use Meaningful Names for Variables 99
Documentation and Comments 99
Indenting 102
Named Constants 102
2.5 Graphics Supplement (Optional) 106
Programming Example: Style Rules Applied to a Graphics Applet 106
JOpti onPane 106
Inputting Other Numeric Types 115
Programming Example: Change-Making Program with Windowing I/O 117
Chapter Summary 120
Answers to Self-Test Questions 120
Programming Projects 125
CHAPTER 3 F1ow of Contro1 129
Objectives 130
Prerequisites 130
3.1 Branching Statements 130
The if-eIse Statement 130
Introduction to Boolean Expressions 134
Programming Tip: Alphabetical Order 139
Nested Statements and Compound Statements 142
Multibranch if-e1se Statements 145
Programming Example: Assigning Letter Grades 146
The switch Statement 149
The Conditional Operator (Optional) 153
3.2 Java Loop Statements 155
whi1e Statements 156
The do-whi1e Statement 160
Programming Example: Bug Infestation 164
The for Statement 168
The Comma in for Statements (Optional) 172
The break Statement in Loops 175
The exit Method 177
3.3 Programming with Loops 179
The Loop Body 179
Initializing Statements 181
Ending a Loop 182
Programming Example: Nested Loops 183
Programming Tip: Avoid Declaring Variables in a Loop Body 184
Loop Bugs 184
Tracing Variables 188
3.4 The Type boo] ean 189
Boolean Expressions and Boolean Variables 190
Programming Tip: Naming Boolean Variables 191
Precedence Rules 192
Input and Output of Boolean Values 195
Case Study: Using a Boolean Variable to End a Loop 195
3.5 Graphics Supplement (Optional) 199
Specifying a Drawing Color 199
Programming Example: A Multiface Applet 203
The drawString Method 208
A JOptionPane Yes/No Window 209
Chapter Summary 211
Answers to Self-Test Questions 211
Programming Projects 217
CHAPTER 4 Defining Classes and Methods 221
Objectives 222
Prerequisites 222
4.1 Class and Method Definitions 222
Class Files and Separate Compilation 224
Instance Variables 225
Using Methods 228
void Method Definitions 231
Methods That Return a Value 233
The this Parameter 238
Local Variables 240
Blocks 242
Parameters of a Primitive Type 243
Summary of Class and Method Definition Syntax 249
4.2 Information Hiding and Encapsulation 250
Information Hiding 250
Programming Tip: Parameter Names Are Local to the Method 251
Precondition and Postcondition Comments 251
The public and private Modifiers 254
Programming Tip: Instance Variables Should Be prirate 257
Programming Example: A Purchase Class 261
Encapsulation 265
Automatic Documentation with javadoc 268
UML Class Diagrams 268
4.3 Objects and Reference 270
Variables of a Class Type and Objects 270
Programming Example: A Species Class 279
Boolean-Valued Methods 282
Class Parameters 284
Comparing Class Parameters and Primitive-Type Parameters 287
4.4 Graphics Supplement (Optional) 291
The G raphi cs Class 291
Programming Example: Multiple Faces Redone with a Helping Method 294
The init Method 298
Adding Labels to an Applet 298
Chapter Summary 302
Answers to Self-Test Questions 303
Programming Projects 310
CHAPTER 5 More About Objects and Methods 315
Objectives 316
Prerequisites 316
5.1 Programming with Methods 317
Methods Calling Methods 317
Programming Tip: Make Helping Methods Private 323
5.2 Static Methods and Static Variables 326
Static Methods 326
Static Variables (Optional) 332
The Math Class 334
Integer, Double, and Other Wrapper Classes 337
5.3 Designing Methods 343
Case Study: Formatting Output 343
Top-Down Design 348
Testing Methods 350
5.4 Overloading 352
Overloading Basics 352
Programming Example: A Pet Class 355
Programming Example: A Class for Money 363
5.5 Constructors 369
Defining Constructors 370
Programming Tip: You Can Use Other Methods in a Constructor 378
5.6 Information Hiding Revisited 380
5.7 Packages 384
Packages and Importing 384
Package Names and Directories 385
Name Clashes 388
5.8 Graphics Supplement (Optional) 389
Programming Tip: Code Appearance and Actions Separately 389
Adding Buttons 390
Event-Driven Programming 391
Programming Example: A Complete Button Applet 391
Programming Buttons 392
Icons 399
Changing Visibility 401
Programming Example: An Example of Changing Visibility 4Ol
What's Next 405
Chapter Summary 405
Answers to Self-Test Questions 406
Programming projects 412
CHAPTER 6 Arrays 417
Objectives 418
Prerequisites 418
6.1 Array Basics 419
Creating and Accessing Arrays 419
Array Details 420
Programming Tip: Use Singular Array Names 424
The 1ength Instance Variable 425
Programming Tip: Use a for Loop to Step Through an Array 427
Initializing Arrays 429
6.2 Arrays in Classes and Methods 430
Case Study: Sales Report 430
Indexed Variables as Method Arguments 438
Entire Arrays as Method Arguments 440
Arguments for the Method mai n 441
Methods That Return Arrays 446
6.3 Programming with Arrays and Classes 449
Programming Example: A Specialized List Class 450
Partially Filled Arrays 457
Searching an Array 457
6.4 Sorting Arrays 460
Selection Sort 460
Other Sorting Algorithms 465
6.5 Multidimensional Arrays 465
Multidimensional-Array Basics 467
Multidimensional-Array Parameters and Returned Values 470
Implementation of Multidimensional Arrays 471
Ragged Arrays (Optional) 475
Programming Example: Employee Time Records 476
6.6 Graphics Supplement (Optional) 482
Graphics Supplement Part 1: Text Areas and Text Fields 483
Programming Example: A Question-and-Answer Applet 483
JTextArea and JTextFi el d Objects 483
Graphics Supplement Part 2: Drawing Polygons 487
Drawing Polygons 487
Chapter Summary 491
Answers to Self-Test Questions 492
Programming Projects 497
CHAPTER 7 Inheritance 501
Objectives 502
Prerequisites 502
7.1 Inheritance Basics 502
Programming Example: A Person Class 503
Derived Classes 504
Overriding Method Definitions 507
Overriding Versus Overloading 508
The final Modifier 508
Programming Tip: Assume That Your Coworkers Are Malicious 510
UML Inheritance Diagrams 510
7.2 Programming with Inheritance 513
Constructors in Derived Classes 513
The this Method (Optional) 514
Call to an Overridden Method 515
Programming Example: Multilevel Derived Classes 516
A Subtle Point About Overloading and Overriding (Optional) 521
Programming Tip: An Object Can Have More than One Type 522
Programming Tip: “Is a” and “Has a” Relations 525
The Class Object 526
Case Study: Character Graphics 528
Abstract Classes 538
Interfaces 542
7.3 Dynamic Binding and Polymorphism 544
Dynamic Binding 544
Type Checking and Dynamic Binding 546
Dynamic Binding with toString 547
Polymorphism 548
7.4 Graphics Supplement (Optional) 551
The Class JApplet 551
The Class JFrame 552
Window Events and Window Listeners 555
The ActionListener Interface 556
Programming Example: Happy Face as a JFrame 557
What To Do Next 558
Chapter Summary 559
Answers to Self-Test Questions 559
Programming Projects 565
猜您喜欢