內容簡介
本書是關姜棕舉於Java語言編程的優秀教材之一,秉承Deitel系列叢書的一貫特點:內容豐殼台富、覆蓋面廣,提供詳細代碼與實例研究,總結出大量的面向對象編程技巧和經驗。本書詳細說明了在Java中面向對象編程的基本理論及實用知識,由初學者為起點,由點到面、由淺入深、循序漸進地介紹了事件處理、對象、挨獄喇匪接口碑禁捆、內置類、繼承、多態性、數據結構和束臭朵集合、查找與排序、流檔案、applet、圖形用戶界面及多執行緒等,並且詳細介紹了網路套用的開發與實踐。第九版在前一版的基礎上增加了更多的實際案例,煮鴉遙辣更新了很多內容,有助於讀者學習和借鑑。本書包括更廣泛的教學特性,訂檔檔其中列舉了數百個可實際使用的程式實例,並給出實際的運行結果,可以使學生在學習時更為直觀。
圖書目錄
Contents
Chapter 1 Introduction to Computers and Java 1
1.1 Introduction 2
1.2 Computers: Hardware and Software 4
1.3 Data Hierarchy 5
1.4 Computer Organization 6
1.5 Machine Languages, Assembly Languages and High-Level Languages 7
1.6 Introduction to Object Technology 8
1.7 Operating Systems 10
1.8 Programming Languages 12
1.9 Java and a Typical Java Development Environment 14
1.10 Test-Driving a Java Application 17
1.11 Web 2.0: Going Social 21
1.12 Software Technologies 23
1.13 Keeping Up-to-Date with Information Technologies 24
1.14 Wrap-Up 24
Chapter 2 Introduction to Java Applications 29
2.1 Introduction 29
2.2 Your First Program in Java: Printing a Line of Text 30
2.3 Modifying Your First Java Program 35
2.4 Displaying Text with printf 36
2.5 Another Application: Adding Integers 37
2.6 Memory Concepts 41
2.7 Arithmetic 42
2.8 Decision Making: Equality and Relational Operators 45
2.9 Wrap-Up 48
Chapter 3 Introduction to Classes, Objects, Methods and Strings 58
3.1 Introduction 58
3.2 Declaring a Class with a Method and Instantiating an Object of a Class 59
3.3 Declaring a Method with a Parameter 62
3.4 Instance Variables, set Methods and get Methods 64
3.5 Primitive Types vs. Reference Types 68
3.6 Initializing Objects with Constructors 69
3.7 Floating-Point Numbers and Type double 71
3.8 (Optional) GUI and Graphics Case Study: Using Dialog Boxes 75
3.9 Wrap-Up 77
Chapter 4 Control Statements: Part 1 84
4.1 Introduction 85
4.2 Algorithms 85
4.3 Pseudocode 85
4.4 Control Structures 86
4.5 if Single-Selection Statement 88
4.6 if…else Double-Selection Statement 89
4.7 while Repetition Statement 92
4.8 Formulating Algorithms: Counter-Controlled Repetition 93
4.9 Formulating Algorithms: Sentinel-Controlled Repetition 97
4.10 Formulating Algorithms: Nested Control Statements 103
4.11 Compound Assignment Operators 107
4.12 Increment and Decrement Operators 107
4.13 Primitive Types 110
4.14 (Optional) GUI and Graphics Case Study: Creating Simple Drawings 110
4.15 Wrap-Up 113
Chapter 5 Control Statements: Part 2 126
5.1 Introduction 126
5.2 Essentials of Counter-Controlled Repetition 127
5.3 for Repetition Statement 128
5.4 Examples Using the for Statement 131
5.5 do…while Repetition Statement 135
5.6 switch Multiple-Selection Statement 136
5.7 break and continue Statements 142
5.8 Logical Operators 144
5.9 Structured Programming Summary 148
5.10 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals 152
5.11 Wrap-Up 154
Chapter 6 Methods: A Deeper Look 164
6.1 Introduction 165
6.2 Program Modules in Java 165
6.3 static Methods, static Fields and Class Math 166
6.4 Declaring Methods with Multiple Parameters 168
6.5 Notes on Declaring and Using Methods 171
6.6 Method-Call Stack and Activation Records 172
6.7 Argument Promotion and Casting 172
6.8 Java API Packages 173
6.9 Case Study: Random-Number Generation 175
6.10 Case Study: A Game of Chance; Introducing Enumerations 179
6.11 Scope of Declarations 182
6.12 Method Overloading 184
6.13 (Optional) GUI and Graphics Case Study: Colors and Filled Shapes 186
6.14 Wrap-Up 188
Chapter 7 Arrays and ArrayLists 201
7.1 Introduction 202
7.2 Arrays 202
7.3 Declaring and Creating Arrays 203
7.4 Examples Using Arrays 204
7.5 Case Study: Card Shuffling and Dealing Simulation 212
7.6 Enhanced for Statement 215
7.7 Passing Arrays to Methods 216
7.8 Case Study: Class GradeBook Using an Array to Store Grades 219
7.9 Multidimensional Arrays 223
7.10 Case Study: Class GradeBook Using a Two-Dimensional Array 226
7.11 Variable-Length Argument Lists 230
7.12 Using Command-Line Arguments 232
7.13 Class Arrays 233
7.14 Introduction to Collections and Class ArrayList 235
7.15 (Optional) GUI and Graphics Case Study: Drawing Arcs 237
7.16 Wrap-Up 240
Chapter 8 Classes and Objects: A Deeper Look 259
8.1 Introduction 260
8.2 Time Class Case Study 260
8.3 Controlling Access to Members 263
8.4 Referring to the Current Object’s Members with the this Reference 264
8.5 Time Class Case Study: Overloaded Constructors 266
8.6 Default and No-Argument Constructors 270
8.7 Notes on Set and Get Methods 271
8.8 Composition 272
8.9 Enumerations 274
8.10 Garbage Collection and Method finalize 276
8.11 static Class Members 277
8.12 static Import 280
8.13 final Instance Variables 281
8.14 Time Class Case Study: Creating Packages 282
8.15 Package Access 286
8.16 (Optional) GUI and Graphics Case Study: Using Objects with Graphics 287
8.17 Wrap-Up 290
Chapter 9 Object-Oriented Programming: Inheritance 298
9.1 Introduction 298
9.2 Superclasses and Subclasses 299
9.3 protected Members 301
9.4 Relationship between Superclasses and Subclasses 302
9.5 Constructors in Subclasses 318
9.6 Software Engineering with Inheritance 319
9.7 Class Object 320
9.8 (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels 320
9.9 Wrap-Up 322
Chapter 10 Object-Oriented Programming: Polymorphism 326
10.1 Introduction 327
10.2 Polymorphism Examples 328
10.3 Demonstrating Polymorphic Behavior 329
10.4 Abstract Classes and Methods 331
10.5 Case Study: Payroll System Using Polymorphism 333
10.6 final Methods and Classes 346
10.7 Case Study: Creating and Using Interfaces 346
10.8 (Optional) GUI and Graphics Case Study: Drawing with Polymorphism 356
10.9 Wrap-Up 357
Chapter 11 Exception Handling: A Deeper Look 362
11.1 Introduction 363
11.2 Example: Divide by Zero without Exception Handling 363
11.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions 365
11.4 When to Use Exception Handling 369
11.5 Java Exception Hierarchy 369
11.6 finally Block 372
11.7 Stack Unwinding and Obtaining Information from an Exception Object 375
11.8 Chained Exceptions 378
11.9 Declaring New Exception Types 379
11.10 Preconditions and Postconditions 380
11.11 Assertions 381
11.12 (New in Java SE 7) Multi-catch: Handling Multiple Exceptions in One catch 382
11.13 (New in Java SE 7) try-with-Resources: Automatic Resource Deallocation 382
11.14 Wrap-Up 383
Chapter 12 ATM Case Study, Part 1: Object-Oriented Design with the UML 388
12.1 Case Study Introduction 388
12.2 Examining the Requirements Document 389
12.3 Identifying the Classes in a Requirements Document 395
12.4 Identifying Class Attributes 400
12.5 Identifying Objects’ States and Activities 404
12.6 Identifying Class Operations 407
12.7 Indicating Collaboration Among Objects 412
12.8 Wrap-Up 418
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design 421
13.1 Introduction 422
13.2 Starting to Program the Classes of the ATM System 422
13.3 Incorporating Inheritance and Polymorphism into the ATM System 425
13.4 ATM Case Study Implementation 431
13.5 Wrap-Up 449
Chapter 14 GUI Components: Part 1 451
14.1 Introduction 452
14.2 Java’s New Nimbus Look-and-Feel 453
14.3 Simple GUI-Based Input/Output with JOptionPane 454
14.4 Overview of Swing Components 456
14.5 Displaying Text and Images in a Window 457
14.6 Text Fields and an Introduction to Event Handling with Nested Classes 461
14.7 Common GUI Event Types and Listener Interfaces 466
14.8 How Event Handling Works 467
14.9 JButton 468
14.10 Buttons That Maintain State 471
14.11 JComboBox; Using an Anonymous Inner Class for Event Handling 476
14.12 JList 479
14.13 Multiple-Selection Lists 480
14.14 Mouse Event Handling 482
14.15 Adapter Classes 486
14.16 JPanel Subclass for Drawing with the Mouse 488
14.17 Key Event Handling 491
14.18 Introduction to Layout Managers 493
14.19 Using Panels to Manage More Complex Layouts 501
14.20 JTextArea 502
14.21 Wrap-Up 504
Chapter 15 Graphics and Java 2D 517
15.1 Introduction 517
15.2 Graphics Contexts and Graphics Objects 519
15.3 Color Control 520
15.4 Manipulating Fonts 525
15.5 Drawing Lines, Rectangles and Ovals 529
15.6 Drawing Arcs 531
15.7 Drawing Polygons and Polylines 533
15.8 Java 2D API 535
15.9 Wrap-Up 541
Chapter 16 Strings, Characters and Regular Expressions 549
16.1 Introduction 550
16.2 Fundamentals of Characters and Strings 550
16.3 Class String 551
16.4 Class StringBuilder 561
16.5 Class Character 566
16.6 Tokenizing Strings 570
16.7 Regular Expressions, Class Pattern and Class Matcher 571
16.8 Wrap-Up 577
Chapter 17 Files, Streams and Object Serialization 588
17.1 Introduction 589
17.2 Files and Streams 589
17.3 Class File 590
17.4 Sequential-Access Text Files 593
17.5 Object Serialization 605
17.6 Additional java.io Classes 612
17.7 Opening Files with JFileChooser 614
17.8 Wrap-Up 617
Chapter 18 Recursion 625
18.1 Introduction 625
18.2 Recursion Concepts 626
18.3 Example Using Recursion: Factorials 627
18.4 Example Using Recursion: Fibonacci Series 630
18.5 Recursion and the Method-Call Stack 632
18.6 Recursion vs. Iteration 633
18.7 Towers of Hanoi 635
18.8 Fractals 636
18.9 Recursive Backtracking 644
18.10 Wrap-Up 645
Chapter 19 Searching, Sorting and Big O 652
19.1 Introduction 652
19.2 Searching Algorithms 653
19.3 Sorting Algorithms 660
19.4 Wrap-Up 671
Chapter 20 Generic Collections 676
20.1 Introduction 677
20.2 Collections Overview 677
20.3 Type-Wrapper Classes for Primitive Types 678
20.4 Autoboxing and Auto-Unboxing 678
20.5 Interface Collection and Class Collections 679
20.6 Lists 679
20.7 Collections Methods 686
20.8 Stack Class of Package java.util 694
20.9 Class PriorityQueue and Interface Queue 696
20.10 Sets 697
20.11 Maps 699
20.12 Properties Class 702
20.13 Synchronized Collections 704
20.14 Unmodifiable Collections 705
20.15 Abstract Implementations 706
20.16 Wrap-Up 706
Chapter 21 Generic Classes and Methods 712
21.1 Introduction 712
21.2 Motivation for Generic Methods 713
21.3 Generic Methods: Implementation and Compile-Time Translation 715
21.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as
the Return Type 717
21.5 Overloading Generic Methods 720
21.6 Generic Classes 720
21.7 Raw Types 726
21.8 Wildcards in Methods That Accept Type Parameters 729
21.9 Generics and Inheritance: Notes 732
21.10 Wrap-Up 733
Chapter 22 Custom Generic Data Structures 737
22.1 Introduction 737
22.2 Self-Referential Classes 738
22.3 Dynamic Memory Allocation 739
22.4 Linked Lists 739
22.5 Stacks 747
22.6 Queues 750
22.7 Trees 752
22.8 Wrap-Up 757
Chapter 23 Applets and Java Web Start 767
23.1 Introduction 767
23.2 Sample Applets Provided with the JDK 768
23.3 Simple Java Applet: Drawing a String 772
23.4 Applet Life-Cycle Methods 775
23.5 Initialization with Method init 776
23.6 Sandbox Security Model 777
23.7 Java Web Start and the Java Network Launch Protocol (JNLP) 778
23.8 Wrap-Up 783
Chapter 24 Multimedia: Applets and Applications 788
24.1 Introduction 788
24.2 Loading, Displaying and Scaling Images 789
24.3 Animating a Series of Images 794
24.4 Image Maps 799
24.5 Loading and Playing Audio Clips 801
24.6 Playing Video and Other Media with Java Media Framework 804
24.7 Wrap-Up 807
24.8 Web Resources 807
Chapter 25 GUI Components: Part 2 815
25.1 Introduction 815
25.2 JSlider 816
25.3 Windows: Additional Notes 819
25.4 Using Menus with Frames 820
25.5 JPopupMenu 826
25.6 Pluggable Look-and-Feel 828
25.7 JDesktopPane and JInternalFrame 831
25.8 JTabbedPane 834
25.9 Layout Managers: BoxLayout and GridBagLayout 836
25.10 Wrap-Up 845
Chapter 26 Multithreading 850
26.1 Introduction 851
26.2 Thread States: Life Cycle of a Thread 852
26.3 Creating and Executing Threads with Executor Framework 855
26.4 Thread Synchronization 858
26.5 Producer/Consumer Relationship without Synchronization 864
26.6 Producer/Consumer Relationship: ArrayBlockingQueue 870
26.7 Producer/Consumer Relationship with Synchronization 872
26.8 Producer/Consumer Relationship: Bounded Buffers 877
26.9 Producer/Consumer Relationship: The Lock and Condition Interfaces 883
26.10 Concurrent Collections Overview 888
26.11 Multithreading with GUI 889
26.12 Interfaces Callable and Future 899
26.13 Java SE 7: Fork/Join Framework 900
26.14 Wrap-Up 900
Chapter 27 Networking 908
27.1 Introduction 908
27.2 Manipulating URLs 909
27.3 Reading a File on a Web Server 913
27.4 Establishing a Simple Server Using Stream Sockets 915
27.5 Establishing a Simple Client Using Stream Sockets 917
27.6 Client/Server Interaction with Stream Socket Connections 918
27.7 Datagrams: Connectionless Client/Server Interaction 927
27.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server 932
27.9 [Web Bonus] Case Study: DeitelMessenger 943
27.10 Wrap-Up 943
Chapter 28 Accessing Databases with JDBC 949
28.1 Introduction 950
28.2 Relational Databases 951
28.3 Relational Database Overview: The books Database 951
28.4 SQL 954
28.5 Instructions for Installing MySQL and MySQL Connector/J 960
28.6 Instructions for Setting Up a MySQL User Account 961
28.7 Creating Database books in MySQL 962
28.8 Manipulating Databases with JDBC 963
28.9 RowSet Interface 976
28.10 Java DB/Apache Derby 978
28.11 PreparedStatements 979
28.12 Stored Procedures 991
28.13 Transaction Processing 991
28.14 Wrap-Up 992
28.15 Web Resources 992
Chapter 29 JavaServer Faces Web Apps: Part 1 999
29.1 Introduction 1000
29.2 HyperText Transfer Protocol (HTTP) Transactions 1000
29.3 Multitier Application Architecture 1004
29.4 Your First JSF Web App 1004
29.5 Model-View-Controller Architecture of JSF Apps 1011
29.6 Common JSF Components 1011
29.7 Validation Using JSF Standard Validators 1014
29.8 Session Tracking 1019
29.9 Wrap-Up 1025
Chapter 30 JavaServer Faces Web Apps: Part 2 1032
30.1 Introduction 1032
30.2 Accessing Databases in Web Apps 1033
30.3 Ajax 1042
30.4 Adding Ajax Functionality to the Validation App 1044
30.5 Wrap-Up 1046
Chapter 31 Web Services 1050
31.1 Introduction 1051
31.2 Web Service Basics 1052
31.3 Simple Object Access Protocol (SOAP) 1052
31.4 Representational State Transfer (REST) 1053
31.5 JavaScript Object Notation (JSON) 1053
31.6 Publishing and Consuming SOAP-Based Web Services 1054
31.7 Publishing and Consuming REST-Based XML Web Services 1063
31.8 Publishing and Consuming REST-Based JSON Web Services 1067
31.9 Session Tracking in a SOAP Web Service 1070
31.10 Consuming a Database-Driven SOAP Web Service 1082
31.11 Equation Generator: Returning User-Defined Types 1087
31.12 Wrap-Up 1095
Appendix A Operator Precedence Chart 1103
Appendix B ASCII Character Set 1104
Appendix C Keywords and Reserved Words 1105
Appendix D Primitive Types 1106
Index 1107
附錄E~附錄L請登錄華信教育資源網(www.hxedu.com.cn)註冊下載。
Appendix E Using the Java API Documentation
Appendix F Using the Debugger
Appendix G Formatted Output
Appendix H Number Systems
Appendix I GroupLayout
Appendix J Java Desktop Integration Components
Appendix K Mashups
Appendix L Unicode?