Contents
Chapter 1 Genesis of Java 1
Java概述
1.1 Introduction 1
Java簡介
1.2 Java Development Today 1
Java發展歷史
1.3 Evolution of 'C' Based Programming Languages 1
C系列語言發展
1.4 Main Features of Java Programming Language 2
Java語言的主要特性
1.4.1 Portability 2
輕量級
1.4.2 Simple 3
簡單
1.4.3 Robust 3
健壯
1.4.4 Multithread 4
多線程
1.4.5 Architecture-Neutral 4
平臺無關
1.4.6 Interpreted and High Performance 5
解釋性和高效
1.4.7 Distributed 5
分布式
1.4.8 Dynamic 5
動態
1.4.9 Security 5
安全
1.5 Java Applet 6
Java Applet小應用程序
1.6 Exercise for you 7
課后習題
Chapter 2 Java Overview 8
Java總覽
2.1 Concepts of OOP 8
面向對象程序設計
2.1.1 Class 9
類
2.1.2 Object 9
對象
2.1.3 Encapsulation 10
封裝
2.1.4 Inheritance 10
繼承
2.1.5 Polymorphism 11
多態
2.2 More Details on Object-Oriented Programming 11
面向對象程序設計具體實例
2.2.1 Encapsulation of Car 12
Car類封裝
2.2.2 Inheritance of Car 12
Car類繼承
2.2.3 Polymorphism of Car 13
Car類多態
2.2.4 Conclusion on Object-Oriented Programming 13
面向對象程序設計小結
2.3 Write the First Java Program 14
編寫**個Java程序
2.4 How to Run the First Java Program 15
運行**個Java程序
2.5 Lexical Elements 16
語法規則
2.6 White Space 17
空白符
2.7 Comments 18
注解
2.7.1 Single Line 18
單行注解
2.7.2 Multi-line 18
多行注解
2.7.3 Javadoc 18
Javadoc注解
2.8 Keywords 19
關鍵字
2.9 Identifiers 19
標志符
2.10 Java Class Library 20
Java類庫
2.11 Sample Program Practice 20
程序實例
2.12 Exercise for you 21
課后習題
Chapter 3 Data Types 22
數據類型
3.1 Data Types Overview 22
數據類型概述
3.2 Primitive Types 23
基本數據類型
3.3 Casting 23
類型轉換
3.3.1 Widening 24
類型擴展
3.3.2 Narrowing 24
類型收縮
3.4 Reference Types 24
引用類型
3.5 Summary 25
基本類型匯總
3.6 Complex Data Types 26
復合數據類型
3.6.1 Reference Data Types 26
引用數據類型
3.6.2 Class Types 26
類類型
3.6.3 Interface Types 26
接口類型
3.7 Composite Data Types 27
構造復合數據類型
3.7.1 Initializing Composite Data Types 27
復合數據類型數據初始化
3.7.2 Predefined Composite Data Types 28
預定義復合數據類型
3.8 Casting Variables to a Different Type 28
不同數據類型轉換
3.8.1 Automatic Casting 28
自動轉換
3.8.2 Explicit Casting 28
顯式轉換
3.9 Java's Floating Point Types 29
浮點數據
3.9.1 Primitive Floating Point Types 29
基本浮點類型
3.9.2 Integer Operators 29
整型運算符
3.9.3 Input and Output of Floating Point Values 30
輸入輸出浮點數據
3.9.4 Casting of Floating Point to and from Integer Values, and Floating Point Literals 30
整型數據和浮點型字符轉換為浮點數據
3.9.5 Floating Point Operations in the Standard Packages 30
系統包中的浮點運算
3.9.6 The Float Class 31
Float類
3.10 Variable 32
變量
3.10.1 Declaring a Variable 32
變量聲明
3.10.2 Difference between Zero and '0'-Unicode Characters 33
區分數字0和字符0
3.10.3 Initialization of the Variable 33
變量初始化
3.10.4 Error Checking by the Compiler 33
編譯錯誤
3.10.5 Using the Cast Operator 33
類型轉換符的使用
3.10.6 Why Declare the Variables as Type Int? 33
變量聲明為整型
3.10.7 Shortcut Declaring Variables of the Same Type 33
同類型變量的聲明
3.10.8 Assigning Values to Variables 34
變量賦值
3.10.9 A Shortcut, Declare and Assign at the Same Time 34
變量同時聲明與賦值
3.11 Record 34
記錄
3.12 Sample Program Practice 35
程序實例
3.13 Exercise for you 36
課后習題
Chapter 4 Operators 37
運算符
4.1 Arithmetic Operators 37
算術運算符
4.1.1 The Modulus Operators 37
取模運算符
4.1.2 Arithmetic Assignment Operators 38
算術賦值運算符
4.1.3 Increment and Decrement 38
自增與自減運算符
4.2 Relational Operators 39
關系運算符
4.3 Boolean Logical Operators 39
邏輯運算符
4.4 Bitwise and Shift Operators 41
位運算符與移位運算符
4.4.1 Bitwise Complement (~) 41
按位取反運算符
4.4.2 Bitwise AND (&) 41
按位與運算符
4.4.3 Bitwise OR ( | ) 41
按位或運算符
4.4.4 Bitwise XOR (^) 42
按位異或運算符
4.4.5 Left Shift (<<) 42
按位左移運算符
4.4.6 Signed Right Shift (>>) 42
帶符號按位右移運算符
4.4.7 Unsigned Right Shift (>>>) 43
無符號按位右移運算符
4.5 Assignment Operators 43
賦值運算符
4.6 The Conditional Operator 44
條件運算符
4.7 The Instanceof Operator 44
instanceof運算符
4.8 Special Operators 45
特殊運算符
4.8.1 Object Member Access (.) 45
對象成員訪問符(.)
4.8.2 Array Element Access ([ ]) 45
數組元素訪問符([ ])
4.8.3 Method Invocation (( )) 46
方法調用操作符
4.8.4 Object Creation (new) 46
對象創建運算符
4.9 Type Conversion or Casting 46
數據類型轉換
4.10 Sample Program Practice 46
程序實例
4.11 Exercise for you 49
課后習題
Chapter 5 Flowing Control 50
控制流
5.1 Control Statements 50
控制表達式
5.2 Selection Statements 50
分支表達式
5.2.1 If Statement 50
if表達式
5.2.2 If-else Statement 51
if-else表達式
5.2.3 Switch Statement 51
switch表達式
5.3 Repetition Statements 52
循環表達式
5.3.1 While Loop Statement 52
while循環表達式
5.3.2 Do-while Loop Statement 53
do-while循環表達式
5.3.3 For Loop Statement 54
for循環表達式
5.4 Branching Statements 54
分支跳轉表達式
5.4.1 Break Statement 54
break表達式
5.4.2 Continue Statement 55
continue表達式
5.4.3 Return Statement 55
return表達式
5.5 Sample Program Practice 56
程序實例
5.6 Exercise for you 58
課后習題
Chapter 6 Class 59
類
6.1 Class Definition 59
類定義
6.1.1 A Simple Class Definition 60
簡單類定義示例
6.1.2 Defining a Class 60
定義類
6.2 Declaring and Instantiating an Object 62
對象定義與初始化
6.2.1 Fields and Methods 65
成員和方法
6.2.2 Default Values for Primitive Members 66
基本類型數據成員的缺省值
6.2.3 Methods, Arguments, and Return Values 66
方法、參數和返回值
6.2.4 The Argument List 67
參數列表
6.3 Constructor 68
構造方法
6.3.1 Calling Constructors from Constructors 70
構造方法中調用構造方法
6.3.2 Default Constructors 71
缺省構造方法
6.4 Keyword “this” 72
this關鍵字
6.5 Garbage Collection 74
垃圾回收
6.5.1 The Use of finalize( ) 75
finalize方法的使用
6.5.2 Cleanup 76
垃圾清理
6.6 Static Methods and Static Variables 79
靜態方法和靜態變量
6.6.1 Static Methods 79
靜態方法
6.6.2 Static Variables 80
靜態變量
6.7 Sample Examples 82
程序實例
6.8 Exercise for you 84
課后習題
Chapter 7 Method 85
方法
7.1 Method Overloading 85
方法重載
7.1.1 Distinguishing Overloaded Methods 87
方法重載匹配
7.1.2 Overloading with Primitives 87
基本數據類型參數重載
7.1.3 Overloading on Return Values 91
基于返回值重載
7.1.4 Overriding with Constructors 92
構造方法重載
7.2 Parameter Passing in Java-By Reference or By Value 93
Java參數傳遞:引用傳遞和值傳遞
7.2.1 Passing Named Arguments to Java Programs 94
給Java程序傳遞參數
7.2.2 Passing Information into a Method 95
方法信息傳遞
7.2.3 Pass by Value 97
值傳遞
7.2.4 Passing Primitive Types 100
傳遞基本類型參數
7.2.5 Return Values 101
返回值
7.2.6 Passing Object References 101
傳遞對象引用
7.2.7 Passing Strings 102
傳遞字符串
7.2.8 Passing Arrays 103
傳遞數組
7.3 Recursion 103
遞歸
7.4 Controlling Access to Members of a Class 105
類成員訪問控制
7.4.1 Class Access Level 106
類級別訪問
7.4.2 Package Access Level 107
包級別訪問
7.5 Static Import 108
靜態導入
7.6 Arrays 109
數組
7.6.1 Array Overview 109
數組概述
7.6.2 Java Arrays 114
Java數組
7.7 String 116
字符串
7.7.1 Creating a String 116
字符串創建
7.7.2 Strings Operation 117
字符串操作
7.7.3 Alter Strings 117
字符串修改
7.8 Command Line Arguments 117
命令行參數
7.9 Sample Examples 118
程序實例
7.10 Exercise for you 122
課后習題
Chapter 8 Inheritance 123
繼承
8.1 Derived Classes 123
派生類
8.2 Abstract Classes 128
抽象類
8.3 Keyword “final” 130
final關鍵字
8.3.1 Final Data 130
final數據
8.3.2 Final Methods 133
final方法
8.3.3 Final Classes 135
final類
8.4 Sample Example 136
程序實例
8.5 Exercise for you 140
課后習題
Chapter 9 Packages and Interfaces 141
包和接口
9.1 Package 141
包
9.1.1 Packages Overview 141
包概述
9.1.2 Packages in Java 142
Java包
9.1.3 Access Specifiers 142
訪問標志符
9.1.4 How to Create a Package 144
包的創建
9.1.5 Setting Up the CLASSPATH 145
類路徑設置
9.1.6 Subpackage (Package inside Another Package) 146
子包(一個包在另一個包中)
9.1.7 How to Use Package 147
使用包
9.2 Interface 149
接口
9.2.1 Interface Overview 149
接口概述
9.2.2 Creating and Using Interfaces 150
創建和使用接口
9.2.3 Defining an Interface 151
接口的定義
9.2.4 The Interface Body 151
接口體
9.2.5 Implementing an Interface 152
接口的實現
9.2.6 Using an Interface as a Type 153
接口類型
9.3 Sample Example 153
程序實例
9.4 Exercise for you 156
課后習題
Chapter 10 Exception Handling 157
異常處理
10.1 Definition of Exception 157
異常定義
10.1.1 What is an Exception 157
什么是異常
10.1.2 Common Exceptions 157
普通異常
10.1.3 The Throwable Superclass 158
Throwable類
10.1.4 Effectively Using try-catch 159
有效使用try-catch
10.1.5 When should You Use Exceptions 162
何時使用異常
10.1.6 How do You Best Use Exceptions 163
如何*大限度的使用異常處理
10.2 The Throw Statement 166
throw表達式
10.3 The Finally Statement 166
finally表達式
10.4 Runtime Exceptions 167
運行時異常
10.4.1 ArithmeticException 167
ArithmeticException類
10.4.2 PointerException 167
PointerException類
10.4.3 IncompatibleClassChangeException 168
IncompatibleClassChangeException類
10.4.4 ClassCastException 168
ClassCastException類
10.4.5 NegativeArraySizeException 168
NegativeArraySizeException類
10.4.6 OutOfMemoryException 169
OutOfMemoryException類
10.4.7 NoClassDefFoundException 169
NoClassDefFoundException類
10.4.8 IncompatibleTypeException 169
IncompatibleTypeException類
10.4.9 ArrayIndexOutOfBoundsException 170
ArrayIndexOutOfBoundsException類
10.4.10 UnsatisfiedLinkException 170
UnsatisfiedLinkException類
10.5 Sample Examples 170
程序實例
10.6 Exercise for you 174
課后習題
Chapter 11 Multithread 175
多線程
11.1 Multithread Overview 175
多線程概述
11.2 Synchronization 179
同步
11.2.1 Inter-thread Communication 181
線程間通信
11.2.2 Java Thread Scheduling 183
Java線程調度
11.2.3 Thread Priorities 184
線程優先級
11.2.4 Java Synchronization 185
Java線程同步
11.3 The Life Cycle of a Thread 187
線程生命周期
11.3.1 Creating a Thread 187
線程創建
11.3.2 Starting a Thread 188
線程啟動
11.3.3 Making a Thread Not Runnable 189
使線程處于非運行狀態
11.3.4 Stopping a Thread 190
線程停止
11.3.5 Testing Thread State 191
線程狀態測試
11.3.6 Why Pause and Resume Processes 193
線程暫停和繼續
11.4 Sample Examples 194
程序實例
11.5 Exercise for you 198
課后習題
Chapter 12 Input and Output 199
輸入與輸出
12.1 Basic Java I/O 199
Java I/O基礎
12.1.1 Background 200
背景
12.1.2 Exceptions 200
異常
12.1.3 Applications 200
應用
12.1.4 File Attributes 200
文件屬性
12.2 Streams 201
流
12.2.1 Byte Streams 202
字節流
12.2.2 Character Streams 203
字符流
12.2.3 Buffered Streams 206
緩沖流
12.2.4 Data Streams 207
數據流
12.2.5 Class StreamTokenizer 208
StreamTokenizer類
12.2.6 Class StringTokenizer 209
StringTokenizer類
12.3 Class File 210
File類
12.3.1 The PrintWriter Class 211
PrintWriter類
12.3.2 Constructor Method 211
構造方法
12.3.3 File Handling and Input/Output 212
文件處理與輸入輸出
12.3.4 The Basic Input Output 218
基本輸入輸出流類
12.4 Sample Examples 225
程序實例
12.5 Exercise for you 227
課后習題
Chapter 13 String Handling 228
字符串處理
13.1 The String Class 228
String類
13.2 Strings in Java 229
Java字符串
13.2.1 String Basics 229
字符串基礎
13.2.2 Creating a String 230
字符串創建
13.2.3 Comparing Strings 232
字符串比較
13.2.4 Other Operations 233
字符串其他操作
13.2.5 StringBuffer Objects 238
StringBuffer類
13.2.6 String Analyzing 240
字符串分析
13.3 Sample Examples 241
程序實例
13.4 Exercise for you 243
課后習題
Chapter 14 Networking 244
網絡
14.1 Computer Network Basics 244
計算機網絡基礎
14.2 URL Objects in Java 247
Java URL對象
14.2.1 Creating URL Objects 247
創建URL對象
14.2.2 Query Methods on URL Objects 247
URL對象查詢方法
14.2.3 Reading from a URL Connection 248
從URL連接讀取數據
14.2.4 URL Operations 249
URL操作
14.3 Sockets in Java 259
Java套接字
14.3.1 Establishing a Connection 259
建立連接
14.3.2 The Client Side of a Socket Connection 259
套接字連接的客戶端
14.3.3 Socket Operations 262
套接字操作
14.4 Sample Examples 268
程序實例
14.5 Exercise for you 272
課后習題
Chapter 15 Applets 273
Applet小應用程序
15.1 Applet Overview 273
Applet概述
15.2 Life Cycle, Graphics, Fonts, Colors 274
Applet生命周期、圖形、字體、顏色
15.2.1 Life Cycle of an Applet 274
Applet生命周期
15.2.2 Parameter Passing 276
參數傳遞
15.2.3 Graphics Class 276
Graphics類
15.2.4 Font Class 276
Font類
15.2.5 Color Class 277
Color類
15.3 User Interface Components 277
使用組件接口
15.4 Applet Fundamentals 278
Applet基礎
15.4.1 The Applet Class 278
Applet類
15.4.2 Applet Architecture 279
Applet體系結構
15.4.3 Requesting Repainting 280
請求重畫
15.5 Working with URLs and Graphics 283
URL與圖形的應用
15.6 Using the instanceof Keyword in Java 284
Java中instanceof關鍵字應用
15.7 Sample Examples 285
程序實例
15.8 Exercise for you 288
課后習題
Chapter 16 Swing GUI Introduction 289
圖形用戶界面Swing
16.1 Event-Driven Programming 289
基于事件驅動編程
16.2 Event Handling 291
事件處理
16.2.1 The Component Class 291
Component類
16.2.2 The Event Class 292
Event類
16.2.3 Event Handling for the Mouse 293
鼠標事件處理
16.2.4 Keyboard Event Handling 294
鍵盤事件處理
16.3 Buttons, Events, and Other Swing Basics 295
按鈕、事件和其他Swing基礎
16.3.1 Buttons 298
按鈕
16.3.2 Action Listeners and Action Events 298
動作監聽器和動作事件
16.3.3 Labels 300
標簽
16.3.4 Color 301
顏色
16.4 Containers and Layout Managers 303
容器和布局管理器
16.4.1 Border Layout Managers 304
邊界布局管理器
16.4.2 Flow Layout Managers 307
流式布局管理器
16.4.3 Grid Layout Managers 307
格點布局管理器
16.4.4 Panels 309
面板
16.4.5 The Container Class 313
Container類
16.5 Menus and Buttons 314
菜單和按鈕
16.5.1 Menu Bars, Menus, and Menu Items 314
菜單條、菜單和菜單項
16.5.2 The AbstractButton Class 317
AbstractButton類
16.5.3 The setActionCommand Method 318
setActionCommand方法
16.5.4 Listeners as Inner Classes 319
內部類監聽器
16.6 Text Fields and Text Areas 320
文本域和文本區
16.6.1 Text Areas and Text Fields 321
文本域和文本區
16.6.2 Window Listeners 322
窗口監聽器
16.7 Sample Examples 323
程序實例
16.8 Exercise for you 325
課后習題
Chapter 17 Programming with JDBC 326
JDBC編程
17.1 JDBC Introduction 326
JDBC介紹
17.2 Connecting to the Database 327
數據庫連接
17.2.1 A Simple Database Connection 328
簡單的數據庫連接示例
17.2.2 The JDBC Classes for Creating a Connection 329
創建連接的JDBC類
17.3 Basic Database Access 330
數據庫訪問基礎
17.3.1 Basic JDBC Database Access Classes 330
訪問數據庫的JDBC基礎類
17.3.2 SQL versus Java 332
SQL空值與Java空值
17.3.3 Clean Up 332
清理
17.3.4 Modifying the Database 332
修改數據庫
17.4 SQL Data Types and Java Data Types 333
SQL數據類型和Java數據類型
17.5 Scrollable Result Sets 335
滾動結果集
17.5.1 Result Set Types 335
結果集類型
17.5.2 Result Set Navigation 335
結果集導引
17.6 Sample Examples 336
程序實例
17.7 Exercise for you 339
課后習題