Java核心技術 卷I:基礎知識(第13版 英文版)
凱·S.霍斯特曼(Cay S. Horstmann)
相關主題
商品描述
本書是經典的《Java 核心技術 卷Ⅰ:基礎知識》的新版。這一版對全書進行了全面修訂,以涵蓋Java21的新特性。
新版延續之前版本的優良傳統,囊括了Java的全部基礎知識,用數百個實際的工程案例,全面系統地講解了Java語言的核心概念、語法、重要特性、開發方法。著力讓讀者在充分理解Java語言和Java類庫的基礎上,靈活應用Java提供的高級特性,具體包括Java語言基礎、面向對象編程、反射和代理、接口和內部類、異常處理、泛型編程、集合類框架、並發編程、註解和 Java 平臺模塊系統等內容。
本書適合想將Java應用於實際項目的軟件開發人員、高等院校教師和學生參考閱讀。
作者簡介
凱·S. 霍斯特曼(Cay S. Horstmann)
現任聖何塞州立大學計算機科學榮譽教授,“Java 大師”(Java Champion)。他是《Java核心技術速學版(第 3 版)》《寫給大忙人的現代 JavaScript》《快學 Scala(第 2 版)》以及《寫給大忙人看的 Java SE 8》的作者。他還編寫了很多針對專業程序員和計算機科學專業學生的其他圖書。
目錄大綱
Chapter 1: An Introduction to Java / Java 概述 1
1.1 Java as a Programming Platform / Java 程序設計平臺 1
1.2 The Java“White Paper”Buzzwords / Java“白皮書”中的口號 2
1.2.1 Simple / 簡單 2
1.2.2 Object-Oriented / 面向對象 3
1.2.3 Distributed / 分布式 3
1.2.4 Robust / 健壯 3
1.2.5 Secure / 安全 4
1.2.6 Architecture-Neutral / 體系結構中立 4
1.2.7 Portable / 可移植 5
1.2.8 Interpreted / 解釋型 6
1.2.9 High-Performance / 高性能 6
1.2.10 Multithreaded / 多線程 6
1.2.11 Dynamic / 動態 7
1.3 Java Applets and the Internet / Java Applet 與 Internet 7
1.4 A Short History of Java / Java 簡史 8
1.5 Common Misconceptions about Java / 對 Java 的常見誤解 12
Chapter 2: The Java Programming Environment /Java 編程環境 15
2.1 Installing the Java Development Kit / 安裝 Java 開發工具包(JDK) 15
2.1.1 Downloading the JDK / 下載 JDK 15
2.1.2 Setting Up the JDK / 設置 JDK 16
2.1.3 Installing Source Files and Documentation /
安裝源文件和文檔 18
2.2 Using the Command-Line Tools / 使用命令行工具 19
2.3 Using an Integrated Development Environment /
使用集成開發環境 24
2.4 JShell 25
目錄
i
目錄 ii
Chapter 3: Fundamental Programming Structures in Java /
Java 的基本編程結構 31
3.1 A Simple Java Program / 一個簡單的 Java 程序 31
3.2 Comments / 註釋 35
3.3 Data Types / 數據類型 36
3.3.1 Integer Types / 整型 36
3.3.2 Floating-Point Types / 浮點類型 38
3.3.3 The char Type / char 類型 39
3.3.4 Unicode and the char Type / Unicode 與 char 類型 41
3.3.5 The boolean Type / boolean 類型 43
3.4 Variables and Constants / 變量與常量 43
3.4.1 Declaring Variables / 聲明變量 43
3.4.2 Initializing Variables/ 初始化變量 45
3.4.3 Constants / 常量 46
3.4.4 Enumerated Types / 枚舉類型 47
3.5 Operators / 運算符 48
3.5.1 Arithmetic Operators / 算術運算符 48
3.5.2 Mathematical Functions and Constants /
數學函數與常量 49
3.5.3 Conversions between Numeric Types /
數值類型之間的轉換 51
3.5.4 Casts / 強制類型轉換 52
3.5.5 Assignment / 賦值 53
3.5.6 Increment and Decrement Operators /
自增與自減運算符 54
3.5.7 Relational and boolean Operators /
關系與 boolean 運算符 54
3.5.8 The Conditional Operator /條件運算符 55
3.5.9 Switch Expressions / switch 表達式 55
3.5.10 Bitwise Operators / 位運算符 57
3.5.11 Parentheses and Operator Hierarchy /
括號與運算符優先級 58
目錄 iii
3.6 Strings / 字符串 59
3.6.1 Concatenation / 拼接 60
3.6.2 Splitting Strings / 分割字符串 61
3.6.3 Indexes and Substrings / 索引與子串 62
3.6.4 Strings Are Immutable / String 是不可變的 63
3.6.5 Testing Strings for Equality / 測試字符串是否相等 65
3.6.6 Empty and Null Strings / 空串與 null 串 66
3.6.7 The String API / String API 66
3.6.8 Reading the Online API Documentation /
閱讀在線 API 文檔 68
3.6.9 Building Strings / 構建字符串 70
3.6.10 Text Blocks / 文本塊 73
3.7 Input and Output / 輸入與輸出 76
3.7.1 Reading Input / 讀取輸入 76
3.7.2 Formatting Output / 格式化輸出 79
3.7.3 File Input and Output / 文件輸入與輸出 83
3.8 Control Flow / 控制流 85
3.8.1 Block Scope / 塊作用域 86
3.8.2 Conditional Statements / 條件語句 86
3.8.3 Loops / 循環 90
3.8.4 Determinate Loops / 確定性循環 95
3.8.5 Multiple Selections with switch /
使用 switch 實現多重選擇 99
3.8.6 Statements That Break Control Flow /
用於跳出控制流的語句 104
3.9 Big Numbers / 大數 107
3.10 Arrays / 數組 110
3.10.1 Declaring Arrays / 聲明數組 111
3.10.2 Accessing Array Elements / 訪問數組元素 112
3.10.3 The“for each”Loop /“for each”循環 113
3.10.4 Array Copying / 數組復制 114
3.10.5 Command-Line Arguments / 命令行參數 116
3.10.6 Array Sorting / 數組排序 117
目錄 ii
Chapter 3: Fundamental Programming Structures in Java /
Java 的基本編程結構 31
3.1 A Simple Java Program / 一個簡單的 Java 程序 31
3.2 Comments / 註釋 35
3.3 Data Types / 數據類型 36
3.3.1 Integer Types / 整型 36
3.3.2 Floating-Point Types / 浮點類型 38
3.3.3 The char Type / char 類型 39
3.3.4 Unicode and the char Type / Unicode 與 char 類型 41
3.3.5 The boolean Type / boolean 類型 43
3.4 Variables and Constants / 變量與常量 43
3.4.1 Declaring Variables / 聲明變量 43
3.4.2 Initializing Variables/ 初始化變量 45
3.4.3 Constants / 常量 46
3.4.4 Enumerated Types / 枚舉類型 47
3.5 Operators / 運算符 48
3.5.1 Arithmetic Operators / 算術運算符 48
3.5.2 Mathematical Functions and Constants /
數學函數與常量 49
3.5.3 Conversions between Numeric Types /
數值類型之間的轉換 51
3.5.4 Casts / 強制類型轉換 52
3.5.5 Assignment / 賦值 53
3.5.6 Increment and Decrement Operators /
自增與自減運算符 54
3.5.7 Relational and boolean Operators /
關系與 boolean 運算符 54
3.5.8 The Conditional Operator /條件運算符 55
3.5.9 Switch Expressions / switch 表達式 55
3.5.10 Bitwise Operators / 位運算符 57
3.5.11 Parentheses and Operator Hierarchy /
括號與運算符優先級 58
目錄 iii
3.6 Strings / 字符串 59
3.6.1 Concatenation / 拼接 60
3.6.2 Splitting Strings / 分割字符串 61
3.6.3 Indexes and Substrings / 索引與子串 62
3.6.4 Strings Are Immutable / String 是不可變的 63
3.6.5 Testing Strings for Equality / 測試字符串是否相等 65
3.6.6 Empty and Null Strings / 空串與 null 串 66
3.6.7 The String API / String API 66
3.6.8 Reading the Online API Documentation /
閱讀在線 API 文檔 68
3.6.9 Building Strings / 構建字符串 70
3.6.10 Text Blocks / 文本塊 73
3.7 Input and Output / 輸入與輸出 76
3.7.1 Reading Input / 讀取輸入 76
3.7.2 Formatting Output / 格式化輸出 79
3.7.3 File Input and Output / 文件輸入與輸出 83
3.8 Control Flow / 控制流 85
3.8.1 Block Scope / 塊作用域 86
3.8.2 Conditional Statements / 條件語句 86
3.8.3 Loops / 循環 90
3.8.4 Determinate Loops / 確定性循環 95
3.8.5 Multiple Selections with switch /
使用 switch 實現多重選擇 99
3.8.6 Statements That Break Control Flow /
用於跳出控制流的語句 104
3.9 Big Numbers / 大數 107
3.10 Arrays / 數組 110
3.10.1 Declaring Arrays / 聲明數組 111
3.10.2 Accessing Array Elements / 訪問數組元素 112
3.10.3 The“for each”Loop /“for each”循環 113
3.10.4 Array Copying / 數組復制 114
3.10.5 Command-Line Arguments / 命令行參數 116
3.10.6 Array Sorting / 數組排序 117
目錄 iv
3.10.7 Multidimensional Arrays / 多維數組 119
3.10.8 Ragged Arrays / 不規則數組 122
Chapter 4: Objects and Classes / 對象與類 127
4.1 Introduction to Object-Oriented Programming /
面向對象編程概述 127
4.1.1 Classes / 類 128
4.1.2 Objects / 對象 129
4.1.3 Identifying Classes / 識別類 130
4.1.4 Relationships between Classes / 類之間的關系 130
4.2 Using Predefined Classes / 使用預定義的類 132
4.2.1 Objects and Object Variables / 對象與對象變量 132
4.2.2 The LocalDate Class of the Java Library /
Java 類庫中的 LocalDate 類 136
4.2.3 Mutator and Accessor Methods /
更改器方法與訪問器方法 138
4.3 Defining Your Own Classes / 定義自己的類 142
4.3.1 An Employee Class / Employee 類 142
4.3.2 Use of Multiple Source Files / 使用多個源文件 145
4.3.3 Dissecting the Employee Class / 剖析 Employee 類 146
4.3.4 First Steps with Constructors / 從構造器開始 147
4.3.5 Declaring Local Variables with var/
使用 var 聲明局部變量 148
4.3.6 Working with null References / 使用 null 引用 149
4.3.7 Implicit and Explicit Parameters /
隱式參數與顯式參數 151
4.3.8 Benefits of Encapsulation / 封裝的好處 152
4.3.9 Class-Based Access Privileges / 基於類的訪問權限 154
4.3.10 Private Methods / 私有方法 155
4.3.11 Final Instance Fields / final 實例字段 156
4.4 Static Fields and Methods / 靜態字段與靜態方法 157
4.4.1 Static Fields / 靜態字段 157
4.4.2 Static Constants / 靜態常量 158
目錄 v
4.4.3 Static Methods / 靜態方法 159
4.4.4 Factory Methods / 工廠方法 160
4.4.5 The main Method / main 方法 161
4.5 Method Parameters / 方法參數 164
4.6 Object Construction / 對象構建 171
4.6.1 Overloading / 重載 171
4.6.2 Default Field Initialization / 默認字段初始化 172
4.6.3 The Constructor with No Arguments / 無參構造器 173
4.6.4 Explicit Field Initialization / 顯式字段初始化 174
4.6.5 Parameter Names / 參數名 175
4.6.6 Calling Another Constructor / 調用另一個構造器 176
4.6.7 Initialization Blocks / 初始化塊 176
4.6.8 Object Destruction and the finalize Method /
對象析構與 finalize 方法 182
4.7 Records / 記錄類型 182
4.7.1 The Record Concept / 記錄類型的概念 183
4.7.2 Constructors: Canonical, Compact, and Custom /
規範構造器、緊湊構造器和自定義構造器 185
4.8 Packages / 包 188
4.8.1 Package Names / 包名 188
4.8.2 Class Importation / 導入類 189
4.8.3 Static Imports / 靜態導入 191
4.8.4 Addition of a Class into a Package /
將類添加到某個包中 192
4.8.5 Package Access / 包訪問權限 195
4.8.6 The Class Path / 類路徑 197
4.8.7 Setting the Class Path / 設置類路徑 199
4.9 JAR Files / JAR 文件 200
4.9.1 Creating JAR files / 創建 JAR 文件 200
4.9.2 The Manifest / 清單文件 201
4.9.3 Executable JAR Files / 可執行 JAR 文件 202
4.9.4 Multi-Release JAR Files /
支持多個 Java 版本的 JAR 文件 203
目錄 iv
3.10.7 Multidimensional Arrays / 多維數組 119
3.10.8 Ragged Arrays / 不規則數組 122
Chapter 4: Objects and Classes / 對象與類 127
4.1 Introduction to Object-Oriented Programming /
面向對象編程概述 127
4.1.1 Classes / 類 128
4.1.2 Objects / 對象 129
4.1.3 Identifying Classes / 識別類 130
4.1.4 Relationships between Classes / 類之間的關系 130
4.2 Using Predefined Classes / 使用預定義的類 132
4.2.1 Objects and Object Variables / 對象與對象變量 132
4.2.2 The LocalDate Class of the Java Library /
Java 類庫中的 LocalDate 類 136
4.2.3 Mutator and Accessor Methods /
更改器方法與訪問器方法 138
4.3 Defining Your Own Classes / 定義自己的類 142
4.3.1 An Employee Class / Employee 類 142
4.3.2 Use of Multiple Source Files / 使用多個源文件 145
4.3.3 Dissecting the Employee Class / 剖析 Employee 類 146
4.3.4 First Steps with Constructors / 從構造器開始 147
4.3.5 Declaring Local Variables with var/
使用 var 聲明局部變量 148
4.3.6 Working with null References / 使用 null 引用 149
4.3.7 Implicit and Explicit Parameters /
隱式參數與顯式參數 151
4.3.8 Benefits of Encapsulation / 封裝的好處 152
4.3.9 Class-Based Access Privileges / 基於類的訪問權限 154
4.3.10 Private Methods / 私有方法 155
4.3.11 Final Instance Fields / final 實例字段 156
4.4 Static Fields and Methods / 靜態字段與靜態方法 157
4.4.1 Static Fields / 靜態字段 157
4.4.2 Static Constants / 靜態常量 158
目錄 v
4.4.3 Static Methods / 靜態方法 159
4.4.4 Factory Methods / 工廠方法 160
4.4.5 The main Method / main 方法 161
4.5 Method Parameters / 方法參數 164
4.6 Object Construction / 對象構建 171
4.6.1 Overloading / 重載 171
4.6.2 Default Field Initialization / 默認字段初始化 172
4.6.3 The Constructor with No Arguments / 無參構造器 173
4.6.4 Explicit Field Initialization / 顯式字段初始化 174
4.6.5 Parameter Names / 參數名 175
4.6.6 Calling Another Constructor / 調用另一個構造器 176
4.6.7 Initialization Blocks / 初始化塊 176
4.6.8 Object Destruction and the finalize Method /
對象析構與 finalize 方法 182
4.7 Records / 記錄類型 182
4.7.1 The Record Concept / 記錄類型的概念 183
4.7.2 Constructors: Canonical, Compact, and Custom /
規範構造器、緊湊構造器和自定義構造器 185
4.8 Packages / 包 188
4.8.1 Package Names / 包名 188
4.8.2 Class Importation / 導入類 189
4.8.3 Static Imports / 靜態導入 191
4.8.4 Addition of a Class into a Package /
將類添加到某個包中 192
4.8.5 Package Access / 包訪問權限 195
4.8.6 The Class Path / 類路徑 197
4.8.7 Setting the Class Path / 設置類路徑 199
4.9 JAR Files / JAR 文件 200
4.9.1 Creating JAR files / 創建 JAR 文件 200
4.9.2 The Manifest / 清單文件 201
4.9.3 Executable JAR Files / 可執行 JAR 文件 202
4.9.4 Multi-Release JAR Files /
支持多個 Java 版本的 JAR 文件 203
目錄 vi
4.9.5 A Note about Command-Line Options /
關於命令行選項的說明 205
4.10 Documentation Comments / 文檔註釋 206
4.10.1 Comment Insertion / 插入註釋 207
4.10.2 Class Comments / 類註釋 207
4.10.3 Method Comments / 方法註釋 208
4.10.4 Field Comments / 字段註釋 209
4.10.5 Package Comments / 包註釋 209
4.10.6 HTML Markup / HTML 標記 210
4.10.7 Links / 鏈接 210
4.10.8 General Comments / 通用註釋 212
4.10.9 Code Snippets / 代碼片段 212
4.10.10 Comment Extraction / 提取註釋 213
4.11 Class Design Hints / 類設計建議 214
Chapter 5: Inheritance / 繼承 217
5.1 Classes, Superclasses, and Subclasses / 類、超類與子類 217
5.1.1 Defining Subclasses / 定義子類 218
5.1.2 Overriding Methods / 覆蓋方法 219
5.1.3 Subclass Constructors / 子類構造器 221
5.1.4 Inheritance Hierarchies / 繼承層次 225
5.1.5 Polymorphism / 多態 226
5.1.6 Understanding Method Calls / 理解方法調用 228
5.1.7 Preventing Inheritance: Final Classes and Methods /
阻止繼承:final 修飾的類和方法 231
5.1.8 Casting / 強制類型轉換 234
5.1.9 Pattern Matching for instanceof /
instanceof 的模式匹配 236
5.1.10 Protected Access / 受保護訪問 239
5.2 Object: The Cosmic Superclass / Object:所有類的超類 240
5.2.1 Variables of Type Object / Object 類型的變量 240
5.2.2 The equals Method / equals 方法 241
5.2.3 Equality Testing and Inheritance / 相等性測試與繼承 242
目錄 vii
5.2.4 The hashCode Method / hashCode 方法 246
5.2.5 The toString Method / toString 方法 250
5.3 Generic Array Lists / 泛型數組列表 257
5.3.1 Declaring Array Lists / 聲明數組列表 258
5.3.2 Accessing Array List Elements / 訪問數組列表元素 260
5.3.3 Compatibility between Typed and Raw Array Lists /
類型化數組列表和原始數組列表的兼容性 264
5.4 Object Wrappers and Autoboxing / 對象包裝器與自動裝箱 265
5.5 Methods with a Variable Number of Arguments /
參數數量可變的方法 270
5.6 Abstract Classes / 抽象類 271
5.7 Enumeration Classes / 枚舉類 277
5.8 Sealed Classes / 密封類 282
5.9 Pattern Matching / 模式匹配 288
5.9.1 Null Handling / null 的處理 289
5.9.2 Guards / 守衛 290
5.9.3 Exhaustiveness / 可窮盡性 290
5.9.4 Dominance / 支配性 292
5.9.5 Patterns and Constants / 模式與常量 293
5.9.6 Variable Scope and Fallthrough /
變量作用域與貫穿執行 293
5.10 Reflection / 反射 296
5.10.1 The Class Class / Class 類 297
5.10.2 A Primer on Declaring Exceptions / 異常聲明初探 300
5.10.3 Resources / 資源 301
5.10.4 Using Reflection to Analyze the Capabilities of Classes /
使用反射分析類的功能 304
5.10.5 Using Reflection to Analyze Objects at Runtime /
使用反射在運行時分析對象 311
5.10.6 Using Reflection to Write Generic Array Code /
使用反射編寫泛型數組代碼 316
5.10.7 Invoking Arbitrary Methods and Constructors /
調用任意方法和構造器 320
目錄 vi
4.9.5 A Note about Command-Line Options /
關於命令行選項的說明 205
4.10 Documentation Comments / 文檔註釋 206
4.10.1 Comment Insertion / 插入註釋 207
4.10.2 Class Comments / 類註釋 207
4.10.3 Method Comments / 方法註釋 208
4.10.4 Field Comments / 字段註釋 209
4.10.5 Package Comments / 包註釋 209
4.10.6 HTML Markup / HTML 標記 210
4.10.7 Links / 鏈接 210
4.10.8 General Comments / 通用註釋 212
4.10.9 Code Snippets / 代碼片段 212
4.10.10 Comment Extraction / 提取註釋 213
4.11 Class Design Hints / 類設計建議 214
Chapter 5: Inheritance / 繼承 217
5.1 Classes, Superclasses, and Subclasses / 類、超類與子類 217
5.1.1 Defining Subclasses / 定義子類 218
5.1.2 Overriding Methods / 覆蓋方法 219
5.1.3 Subclass Constructors / 子類構造器 221
5.1.4 Inheritance Hierarchies / 繼承層次 225
5.1.5 Polymorphism / 多態 226
5.1.6 Understanding Method Calls / 理解方法調用 228
5.1.7 Preventing Inheritance: Final Classes and Methods /
阻止繼承:final 修飾的類和方法 231
5.1.8 Casting / 強制類型轉換 234
5.1.9 Pattern Matching for instanceof /
instanceof 的模式匹配 236
5.1.10 Protected Access / 受保護訪問 239
5.2 Object: The Cosmic Superclass / Object:所有類的超類 240
5.2.1 Variables of Type Object / Object 類型的變量 240
5.2.2 The equals Method / equals 方法 241
5.2.3 Equality Testing and Inheritance / 相等性測試與繼承 242
目錄 vii
5.2.4 The hashCode Method / hashCode 方法 246
5.2.5 The toString Method / toString 方法 250
5.3 Generic Array Lists / 泛型數組列表 257
5.3.1 Declaring Array Lists / 聲明數組列表 258
5.3.2 Accessing Array List Elements / 訪問數組列表元素 260
5.3.3 Compatibility between Typed and Raw Array Lists /
類型化數組列表和原始數組列表的兼容性 264
5.4 Object Wrappers and Autoboxing / 對象包裝器與自動裝箱 265
5.5 Methods with a Variable Number of Arguments /
參數數量可變的方法 270
5.6 Abstract Classes / 抽象類 271
5.7 Enumeration Classes / 枚舉類 277
5.8 Sealed Classes / 密封類 282
5.9 Pattern Matching / 模式匹配 288
5.9.1 Null Handling / null 的處理 289
5.9.2 Guards / 守衛 290
5.9.3 Exhaustiveness / 可窮盡性 290
5.9.4 Dominance / 支配性 292
5.9.5 Patterns and Constants / 模式與常量 293
5.9.6 Variable Scope and Fallthrough /
變量作用域與貫穿執行 293
5.10 Reflection / 反射 296
5.10.1 The Class Class / Class 類 297
5.10.2 A Primer on Declaring Exceptions / 異常聲明初探 300
5.10.3 Resources / 資源 301
5.10.4 Using Reflection to Analyze the Capabilities of Classes /
使用反射分析類的功能 304
5.10.5 Using Reflection to Analyze Objects at Runtime /
使用反射在運行時分析對象 311
5.10.6 Using Reflection to Write Generic Array Code /
使用反射編寫泛型數組代碼 316
5.10.7 Invoking Arbitrary Methods and Constructors /
調用任意方法和構造器 320
目錄 viii
5.11 Design Hints for Inheritance / 繼承的設計建議 324
Chapter 6: Interfaces, Lambda Expressions, and Inner Classes /
接口、Lambda 表達式和內部類 327
6.1 Interfaces / 接口 327
6.1.1 The Interface Concept / 接口的概念 327
6.1.2 Properties of Interfaces / 接口的特性 335
6.1.3 Interfaces and Abstract Classes / 接口與抽象類 337
6.1.4 Static and Private Methods / 靜態方法與私有方法 338
6.1.5 Default Methods / 默認方法 339
6.1.6 Resolving Default Method Conflicts /
解決默認方法沖突 340
6.1.7 Interfaces and Callbacks / 接口與回調 342
6.1.8 The Comparator Interface / Comparator 接口 345
6.1.9 Object Cloning / 對象克隆 347
6.2 Lambda Expressions / Lambda 表達式 354
6.2.1 Why Lambdas / 為什麼要引入 Lambda 表達式 354
6.2.2 The Syntax of Lambda Expressions /
Lambda 表達式的語法 355
6.2.3 Functional Interfaces / 函數式接口 358
6.2.4 Function Types / 函數類型 359
6.2.5 Method References / 方法引用 361
6.2.6 Constructor References / 構造器引用 365
6.2.7 Variable Scope / 變量作用域 366
6.2.8 Processing Lambda Expressions /
處理 Lambda 表達式 369
6.2.9 Creating Comparators / 創建比較器 373
6.3 Inner Classes / 內部類 375
6.3.1 Use of an Inner Class to Access Object State /
使用內部類訪問對象狀態 376
6.3.2 Special Syntax Rules for Inner Classes /
內部類的特殊語法規則 380
目錄 ix
6.3.3 Are Inner Classes Useful Actually Necessary Secure /
內部類是否有用、必要和安全 381
6.3.4 Local Inner Classes / 局部內部類 382
6.3.5 Accessing Variables from Outer Methods /
從外部方法訪問變量 383
6.3.6 Anonymous Inner Classes / 匿名內部類 385
6.3.7 Static Classes / 靜態內部類 389
6.4 Service Loaders / 服務加載器 393
6.5 Proxies / 代理 395
6.5.1 When to Use Proxies / 何時使用代理 396
6.5.2 Creating Proxy Objects / 創建代理對象 396
6.5.3 Properties of Proxy Classes / 代理類的特性 400
Chapter 7: Exceptions, Assertions, and Logging / 異常、斷言和日誌 403
7.1 Dealing with Errors / 處理錯誤 403
7.1.1 The Classification of Exceptions / 異常分類 405
7.1.2 Declaring Checked Exceptions / 聲明檢查型異常 407
7.1.3 How to Throw an Exception / 如何拋出異常 409
7.1.4 Creating Exception Classes / 創建異常類 411
7.2 Catching Exceptions / 捕獲異常 412
7.2.1 Catching an Exception / 捕獲一個異常 412
7.2.2 Catching Multiple Exceptions / 捕獲多個異常 414
7.2.3 Rethrowing and Chaining Exceptions /
再次拋出異常與異常鏈 417
7.2.4 The finally Clause/ finally 子句 418
7.2.5 The try-with-Resources Statement /
try-with-Resources 語句 421
7.2.6 Analyzing Stack Trace Elements / 分析棧軌跡元素 423
7.3 Tips for Using Exceptions / 使用異常的技巧 427
7.4 Using Assertions / 使用斷言 431
7.4.1 The Assertion Concept / 斷言的概念 431
7.4.2 Assertion Enabling and Disabling / 啟用和禁用斷言 432
目錄 viii
5.11 Design Hints for Inheritance / 繼承的設計建議 324
Chapter 6: Interfaces, Lambda Expressions, and Inner Classes /
接口、Lambda 表達式和內部類 327
6.1 Interfaces / 接口 327
6.1.1 The Interface Concept / 接口的概念 327
6.1.2 Properties of Interfaces / 接口的特性 335
6.1.3 Interfaces and Abstract Classes / 接口與抽象類 337
6.1.4 Static and Private Methods / 靜態方法與私有方法 338
6.1.5 Default Methods / 默認方法 339
6.1.6 Resolving Default Method Conflicts /
解決默認方法沖突 340
6.1.7 Interfaces and Callbacks / 接口與回調 342
6.1.8 The Comparator Interface / Comparator 接口 345
6.1.9 Object Cloning / 對象克隆 347
6.2 Lambda Expressions / Lambda 表達式 354
6.2.1 Why Lambdas / 為什麼要引入 Lambda 表達式 354
6.2.2 The Syntax of Lambda Expressions /
Lambda 表達式的語法 355
6.2.3 Functional Interfaces / 函數式接口 358
6.2.4 Function Types / 函數類型 359
6.2.5 Method References / 方法引用 361
6.2.6 Constructor References / 構造器引用 365
6.2.7 Variable Scope / 變量作用域 366
6.2.8 Processing Lambda Expressions /
處理 Lambda 表達式 369
6.2.9 Creating Comparators / 創建比較器 373
6.3 Inner Classes / 內部類 375
6.3.1 Use of an Inner Class to Access Object State /
使用內部類訪問對象狀態 376
6.3.2 Special Syntax Rules for Inner Classes /
內部類的特殊語法規則 380
目錄 ix
6.3.3 Are Inner Classes Useful Actually Necessary Secure /
內部類是否有用、必要和安全 381
6.3.4 Local Inner Classes / 局部內部類 382
6.3.5 Accessing Variables from Outer Methods /
從外部方法訪問變量 383
6.3.6 Anonymous Inner Classes / 匿名內部類 385
6.3.7 Static Classes / 靜態內部類 389
6.4 Service Loaders / 服務加載器 393
6.5 Proxies / 代理 395
6.5.1 When to Use Proxies / 何時使用代理 396
6.5.2 Creating Proxy Objects / 創建代理對象 396
6.5.3 Properties of Proxy Classes / 代理類的特性 400
Chapter 7: Exceptions, Assertions, and Logging / 異常、斷言和日誌 403
7.1 Dealing with Errors / 處理錯誤 403
7.1.1 The Classification of Exceptions / 異常分類 405
7.1.2 Declaring Checked Exceptions / 聲明檢查型異常 407
7.1.3 How to Throw an Exception / 如何拋出異常 409
7.1.4 Creating Exception Classes / 創建異常類 411
7.2 Catching Exceptions / 捕獲異常 412
7.2.1 Catching an Exception / 捕獲一個異常 412
7.2.2 Catching Multiple Exceptions / 捕獲多個異常 414
7.2.3 Rethrowing and Chaining Exceptions /
再次拋出異常與異常鏈 417
7.2.4 The finally Clause/ finally 子句 418
7.2.5 The try-with-Resources Statement /
try-with-Resources 語句 421
7.2.6 Analyzing Stack Trace Elements / 分析棧軌跡元素 423
7.3 Tips for Using Exceptions / 使用異常的技巧 427
7.4 Using Assertions / 使用斷言 431
7.4.1 The Assertion Concept / 斷言的概念 431
7.4.2 Assertion Enabling and Disabling / 啟用和禁用斷言 432
目錄 x
7.4.3 Using Assertions for Parameter Checking /
使用斷言檢查參數 434
7.4.4 Using Assertions for Documenting Assumptions /
使用斷言保證文檔中假定成立的條件 435
7.5 Logging / 日誌 436
7.5.1 Should You Use the Java Logging Framework /
應該使用 Java 日誌框架嗎 436
7.5.2 Logging 101 / 日誌入門 437
7.5.3 The Platform Logging API / 平臺日誌 API 438
7.5.4 Logging Configuration / 日誌配置 440
7.5.5 Log Handlers / 日誌處理器 441
7.5.6 Filters and Formatters / 過濾器和格式化器 444
7.5.7 A Logging Recipe / 常見日誌操作總結 445
7.6 Debugging Tips / 調試技巧 452
Chapter 8: Generic Programming / 泛型編程 459
8.1 Why Generic Programming / 為什麼要使用泛型編程 459
8.1.1 The Advantage of Type Parameters / 類型參數的優勢 459
8.1.2 Who Wants to Be a Generic Programmer /
哪些人想成為泛型程序員 461
8.2 Defining a Simple Generic Class / 定義簡單的泛型類 462
8.3 Generic Methods / 泛型方法 464
8.4 Bounds for Type Variables / 類型變量的綁定 465
8.5 Generic Code and the Virtual Machine / 泛型代碼與虛擬機 468
8.5.1 Type Erasure / 類型擦除 468
8.5.2 Translating Generic Expressions / 轉換泛型表達式 469
8.5.3 Translating Generic Methods / 轉換泛型方法 470
8.5.4 Calling Legacy Code / 調用遺留代碼 472
8.5.5 Generic Record Patterns / 泛型記錄模式 474
8.6 Inheritance Rules for Generic Types / 泛型類型的繼承規則 474
8.7 Wildcard Types / 通配符類型 477
8.7.1 The Wildcard Concept/ 通配符的概念 477
8.7.2 Supertype Bounds for Wildcards / 通配符的超類型限定 478
目錄 xi
8.7.3 Unbounded Wildcards/ 無限定通配符 482
8.7.4 Wildcard Capture / 通配符捕獲 482
8.8 Restrictions and Limitations / 限制 485
8.8.1 Type Parameters Cannot Be Instantiated with Primitive
Types /類型參數不能用基本類型來實例化 485
8.8.2 Runtime Type Inquiry Only Works with Raw Types /
運行時類型查詢只適用於原始類型 485
8.8.3 You Cannot Create Arrays of Parameterized Types /
不能創建參數化類型的數組 486
8.8.4 Varargs Warnings / 可變參數警告 487
8.8.5 Generic Varargs Do Not Spread Primitive Arrays /
泛型可變參數不會展開基本類型數組 488
8.8.6 You Cannot Instantiate Type Variables /
不能實例化類型變量 489
8.8.7 You Cannot Construct a Generic Array /
不能構造泛型數組 490
8.8.8 Type Variables Are Not Valid in Static Contexts of
Generic Classes /類型變量在泛型類的靜態上下文中
無效 492
8.8.9 You Cannot Throw or Catch Instances of a Generic Class /
不能拋出或捕獲泛型類的實例 492
8.8.10 You Can Defeat Checked Exception Checking /
可以打破“檢查型異常必須進行檢查”這個規則 493
8.8.11 Beware of Clashes after Erasure /
註意類型擦除後的沖突 495
8.8.12 Type Inference in Generic Record Patterns is Limited /
泛型記錄模式中的類型推斷是有限制的 496
8.9 Reflection and Generics / 反射與泛型 498
8.9.1 The Generic Class Class / 泛型的 Class 類 498
8.9.2 Using Class
使用 Class
8.9.3 Generic Type Information in the Virtual Machine /
虛擬機中的泛型類型信息 500
目錄 x
7.4.3 Using Assertions for Parameter Checking /
使用斷言檢查參數 434
7.4.4 Using Assertions for Documenting Assumptions /
使用斷言保證文檔中假定成立的條件 435
7.5 Logging / 日誌 436
7.5.1 Should You Use the Java Logging Framework /
應該使用 Java 日誌框架嗎 436
7.5.2 Logging 101 / 日誌入門 437
7.5.3 The Platform Logging API / 平臺日誌 API 438
7.5.4 Logging Configuration / 日誌配置 440
7.5.5 Log Handlers / 日誌處理器 441
7.5.6 Filters and Formatters / 過濾器和格式化器 444
7.5.7 A Logging Recipe / 常見日誌操作總結 445
7.6 Debugging Tips / 調試技巧 452
Chapter 8: Generic Programming / 泛型編程 459
8.1 Why Generic Programming / 為什麼要使用泛型編程 459
8.1.1 The Advantage of Type Parameters / 類型參數的優勢 459
8.1.2 Who Wants to Be a Generic Programmer /
哪些人想成為泛型程序員 461
8.2 Defining a Simple Generic Class / 定義簡單的泛型類 462
8.3 Generic Methods / 泛型方法 464
8.4 Bounds for Type Variables / 類型變量的綁定 465
8.5 Generic Code and the Virtual Machine / 泛型代碼與虛擬機 468
8.5.1 Type Erasure / 類型擦除 468
8.5.2 Translating Generic Expressions / 轉換泛型表達式 469
8.5.3 Translating Generic Methods / 轉換泛型方法 470
8.5.4 Calling Legacy Code / 調用遺留代碼 472
8.5.5 Generic Record Patterns / 泛型記錄模式 474
8.6 Inheritance Rules for Generic Types / 泛型類型的繼承規則 474
8.7 Wildcard Types / 通配符類型 477
8.7.1 The Wildcard Concept/ 通配符的概念 477
8.7.2 Supertype Bounds for Wildcards / 通配符的超類型限定 478
目錄 xi
8.7.3 Unbounded Wildcards/ 無限定通配符 482
8.7.4 Wildcard Capture / 通配符捕獲 482
8.8 Restrictions and Limitations / 限制 485
8.8.1 Type Parameters Cannot Be Instantiated with Primitive
Types /類型參數不能用基本類型來實例化 485
8.8.2 Runtime Type Inquiry Only Works with Raw Types /
運行時類型查詢只適用於原始類型 485
8.8.3 You Cannot Create Arrays of Parameterized Types /
不能創建參數化類型的數組 486
8.8.4 Varargs Warnings / 可變參數警告 487
8.8.5 Generic Varargs Do Not Spread Primitive Arrays /
泛型可變參數不會展開基本類型數組 488
8.8.6 You Cannot Instantiate Type Variables /
不能實例化類型變量 489
8.8.7 You Cannot Construct a Generic Array /
不能構造泛型數組 490
8.8.8 Type Variables Are Not Valid in Static Contexts of
Generic Classes /類型變量在泛型類的靜態上下文中
無效 492
8.8.9 You Cannot Throw or Catch Instances of a Generic Class /
不能拋出或捕獲泛型類的實例 492
8.8.10 You Can Defeat Checked Exception Checking /
可以打破“檢查型異常必須進行檢查”這個規則 493
8.8.11 Beware of Clashes after Erasure /
註意類型擦除後的沖突 495
8.8.12 Type Inference in Generic Record Patterns is Limited /
泛型記錄模式中的類型推斷是有限制的 496
8.9 Reflection and Generics / 反射與泛型 498
8.9.1 The Generic Class Class / 泛型的 Class 類 498
8.9.2 Using Class
使用 Class
8.9.3 Generic Type Information in the Virtual Machine /
虛擬機中的泛型類型信息 500
目錄 xii
8.9.4 Type Literals / 類型字面常量 504
Chapter 9: Collections / 集合類 511
9.1 The Java Collections Framework / Java 集合類框架 511
9.1.1 Separating Collection Interfaces and Implementation /
將集合類的接口與實現分離 511
9.1.2 The Collection Interface/ Collection 接口 514
9.1.3 Iterators / 疊代器 515
9.1.4 Generic Utility Methods / 泛型工具方法 518
9.2 Interfaces in the Collections Framework / 集合類框架中的接口 521
9.3 Concrete Collections / 具體的集合類 525
9.3.1 Linked Lists / 鏈表 526
9.3.2 Array Lists / 數組列表 537
9.3.3 Hash Sets / 哈希集 537
9.3.4 Tree Sets / 樹集 542
9.3.5 Queues and Deques / 隊列與雙端隊列 545
9.3.6 Priority Queues / 優先級隊列 547
9.4 Maps / 映射 548
9.4.1 Basic Map Operations / 基本映射操作 549
9.4.2 Updating Map Entries / 更新映射條目 552
9.4.3 Map Views / 映射視圖 554
9.4.4 Weak Hash Maps / 弱哈希映射 557
9.4.5 Linked Hash Sets and Maps /
LinkedHashSet 與 LinkedHashMap 557
9.4.6 Enumeration Sets and Maps / EmumSet 與 EmumMap 559
9.4.7 Identity Hash Maps / IdentityHashMap 560
9.5 Copies and Views / 副本與視圖 562
9.5.1 Small Collections / 小型集合 562
9.5.2 Unmodifiable Copies and Views /
不可修改的副本和視圖 565
9.5.3 Subranges / 子範圍 566
9.5.4 Sets From Boolean-Valued Maps / 從布爾值映射創建集 567
9.5.5 Reversed Views / 逆向視圖 568
目錄 xiii
9.5.6 Checked Views / 檢查型視圖 568
9.5.7 Synchronized Views / 同步視圖 569
9.5.8 A Note on Optional Operations / 關於可選操作的說明 569
9.6 Algorithms / 算法 574
9.6.1 Why Generic Algorithms / 為什麼使用泛型算法 574
9.6.2 Sorting and Shuffling / 排序與混排 576
9.6.3 Binary Search / 二分查找 578
9.6.4 Simple Algorithms / 簡單算法 580
9.6.5 Bulk Operations / 主要操作 582
9.6.6 Converting between Collections and Arrays /
集合與數組的轉換 583
9.6.7 Writing Your Own Algorithms / 編寫自己的算法 584
9.7 Legacy Collections / 遺留的集合類 586
9.7.1 The Hashtable Class / Hashtable 類 587
9.7.2 Enumerations / 枚舉 587
9.7.3 Property Maps / 屬性映射 588
9.7.4 System Properties / 系統屬性 590
9.7.5 Stacks / 棧 593
9.7.6 Bit Sets / 位集 593
Chapter 10: Concurrency / 並發 599
10.1 Running Threads / 運行線程 599
10.2 Thread States / 線程狀態 605
10.2.1 New Threads / 新創建線程 605
10.2.2 Runnable Threads / 可運行線程 605
10.2.3 Blocked and Waiting Threads / 被阻塞線程和等待線程 606
10.2.4 Terminated Threads / 被終止線程 608
10.3 Thread Properties / 線程屬性 608
10.3.1 Virtual Threads / 虛擬線程 608
10.3.2 Thread Interruption / 線程中斷 609
10.3.3 Daemon Threads / 守護線程 613
10.3.4 Thread Names and Ids / 線程的名稱與 ID 613
目錄 xii
8.9.4 Type Literals / 類型字面常量 504
Chapter 9: Collections / 集合類 511
9.1 The Java Collections Framework / Java 集合類框架 511
9.1.1 Separating Collection Interfaces and Implementation /
將集合類的接口與實現分離 511
9.1.2 The Collection Interface/ Collection 接口 514
9.1.3 Iterators / 疊代器 515
9.1.4 Generic Utility Methods / 泛型工具方法 518
9.2 Interfaces in the Collections Framework / 集合類框架中的接口 521
9.3 Concrete Collections / 具體的集合類 525
9.3.1 Linked Lists / 鏈表 526
9.3.2 Array Lists / 數組列表 537
9.3.3 Hash Sets / 哈希集 537
9.3.4 Tree Sets / 樹集 542
9.3.5 Queues and Deques / 隊列與雙端隊列 545
9.3.6 Priority Queues / 優先級隊列 547
9.4 Maps / 映射 548
9.4.1 Basic Map Operations / 基本映射操作 549
9.4.2 Updating Map Entries / 更新映射條目 552
9.4.3 Map Views / 映射視圖 554
9.4.4 Weak Hash Maps / 弱哈希映射 557
9.4.5 Linked Hash Sets and Maps /
LinkedHashSet 與 LinkedHashMap 557
9.4.6 Enumeration Sets and Maps / EmumSet 與 EmumMap 559
9.4.7 Identity Hash Maps / IdentityHashMap 560
9.5 Copies and Views / 副本與視圖 562
9.5.1 Small Collections / 小型集合 562
9.5.2 Unmodifiable Copies and Views /
不可修改的副本和視圖 565
9.5.3 Subranges / 子範圍 566
9.5.4 Sets From Boolean-Valued Maps / 從布爾值映射創建集 567
9.5.5 Reversed Views / 逆向視圖 568
目錄 xiii
9.5.6 Checked Views / 檢查型視圖 568
9.5.7 Synchronized Views / 同步視圖 569
9.5.8 A Note on Optional Operations / 關於可選操作的說明 569
9.6 Algorithms / 算法 574
9.6.1 Why Generic Algorithms / 為什麼使用泛型算法 574
9.6.2 Sorting and Shuffling / 排序與混排 576
9.6.3 Binary Search / 二分查找 578
9.6.4 Simple Algorithms / 簡單算法 580
9.6.5 Bulk Operations / 主要操作 582
9.6.6 Converting between Collections and Arrays /
集合與數組的轉換 583
9.6.7 Writing Your Own Algorithms / 編寫自己的算法 584
9.7 Legacy Collections / 遺留的集合類 586
9.7.1 The Hashtable Class / Hashtable 類 587
9.7.2 Enumerations / 枚舉 587
9.7.3 Property Maps / 屬性映射 588
9.7.4 System Properties / 系統屬性 590
9.7.5 Stacks / 棧 593
9.7.6 Bit Sets / 位集 593
Chapter 10: Concurrency / 並發 599
10.1 Running Threads / 運行線程 599
10.2 Thread States / 線程狀態 605
10.2.1 New Threads / 新創建線程 605
10.2.2 Runnable Threads / 可運行線程 605
10.2.3 Blocked and Waiting Threads / 被阻塞線程和等待線程 606
10.2.4 Terminated Threads / 被終止線程 608
10.3 Thread Properties / 線程屬性 608
10.3.1 Virtual Threads / 虛擬線程 608
10.3.2 Thread Interruption / 線程中斷 609
10.3.3 Daemon Threads / 守護線程 613
10.3.4 Thread Names and Ids / 線程的名稱與 ID 613
目錄 xiv
10.3.5 Handlers for Uncaught Exceptions /
未捕獲異常的處理器 614
10.3.6 Thread Priorities / 線程優先級 615
10.3.7 Thread Factories and Builders / 線程工廠和生成器 616
10.4 Coordinating Tasks / 協調任務 618
10.4.1 Callables and Futures / Callable 和 Future 618
10.4.2 Executors / 執行器 621
10.4.3 Invoking a Group of Tasks / 調用任務組 625
10.4.4 Thread-Local Variables / 線程局部變量 631
10.4.5 The Fork-Join Framework / Fork-Join 框架 632
10.5 Synchronization / 同步 635
10.5.1 An Example of a Race Condition / 競爭條件示例 636
10.5.2 The Race Condition Explained / 競爭條件詳解 638
10.5.3 Lock Objects / 鎖對象 640
10.5.4 Condition Objects / 條件對象 644
10.5.5 Deadlocks / 死鎖 649
10.5.6 The synchronized Keyword / synchronized 關鍵字 652
10.5.7 Synchronized Blocks / 同步塊 657
10.5.8 The Monitor Concept / 監視器概念 659
10.5.9 Volatile Fields / volatile 字段 660
10.5.10 Final Fields / final 字段 661
10.5.11 Atomics / 原子 662
10.5.12 On-Demand Initialization / 按需初始化 664
10.5.13 Safe Publication / 安全發布 665
10.5.14 Sharing with Thread-Local Variables /
通過線程局部變量共享 666
10.6 Thread-Safe Collections / 線程安全的集合 667
10.6.1 Blocking Queues / 阻塞隊列 668
10.6.2 Efficient Maps, Sets, and Queues /
高效的映射、集和隊列 674
10.6.3 Atomic Update of Map Entries / 映射條目的原子更新 676
10.6.4 Bulk Operations on Concurrent Hash Maps /
並發哈希映射的主要操作 679
目錄 xv
10.6.5 Concurrent Set Views / 並發集視圖 682
10.6.6 Copy on Write Arrays / 寫時復制數組 682
10.6.7 Parallel Array Algorithms / 並行數組算法 682
10.6.8 Older Thread-Safe Collections / 較早的線程安全集合 684
10.7 Asynchronous Computations / 異步計算 685
10.7.1 Completable Futures / CompletableFuture 685
10.7.2 Composing Completable Futures /
組合 CompletableFuture 687
10.7.3 Long-Running Tasks in User-Interface Callbacks /
用戶界面回調中的長時間運行任務 694
10.8 Processes / 進程 702
10.8.1 Building a Process / 構建進程 702
10.8.2 Running a Process / 運行進程 704
10.8.3 Process Handles / 進程句柄 706
Chapter 11: Annotations / 註解 711
11.1 Using Annotations / 使用註解 711
11.1.1 Annotation Elements / 註解元素 712
11.1.2 Multiple and Repeated Annotations /
多個註解與重復註解 713
11.1.3 Annotating Declarations / 對聲明進行註解 713
11.1.4 Annotating Type Uses / 對類型的使用進行註解 714
11.1.5 Making Receivers Explicit / 使接收者參數變為顯式的 716
11.2 Defining Annotations / 定義註解 717
11.3 Annotations in the Java API / Java API 中的註解 720
11.3.1 Annotations for Compilation / 用於編譯的註解 721
11.3.2 Meta-Annotations / 元註解 723
11.4 Processing Annotations at Runtime / 在運行時處理註解 725
11.5 Source-Level Annotation Processing / 源代碼級註解處理 729
11.5.1 Annotation Processors / 註解處理器 729
11.5.2 The Language Model API / 語言默寫 API 730
11.5.3 Using Annotations to Generate Source Code /
使用註解來生成源代碼 731
目錄 xiv
10.3.5 Handlers for Uncaught Exceptions /
未捕獲異常的處理器 614
10.3.6 Thread Priorities / 線程優先級 615
10.3.7 Thread Factories and Builders / 線程工廠和生成器 616
10.4 Coordinating Tasks / 協調任務 618
10.4.1 Callables and Futures / Callable 和 Future 618
10.4.2 Executors / 執行器 621
10.4.3 Invoking a Group of Tasks / 調用任務組 625
10.4.4 Thread-Local Variables / 線程局部變量 631
10.4.5 The Fork-Join Framework / Fork-Join 框架 632
10.5 Synchronization / 同步 635
10.5.1 An Example of a Race Condition / 競爭條件示例 636
10.5.2 The Race Condition Explained / 競爭條件詳解 638
10.5.3 Lock Objects / 鎖對象 640
10.5.4 Condition Objects / 條件對象 644
10.5.5 Deadlocks / 死鎖 649
10.5.6 The synchronized Keyword / synchronized 關鍵字 652
10.5.7 Synchronized Blocks / 同步塊 657
10.5.8 The Monitor Concept / 監視器概念 659
10.5.9 Volatile Fields / volatile 字段 660
10.5.10 Final Fields / final 字段 661
10.5.11 Atomics / 原子 662
10.5.12 On-Demand Initialization / 按需初始化 664
10.5.13 Safe Publication / 安全發布 665
10.5.14 Sharing with Thread-Local Variables /
通過線程局部變量共享 666
10.6 Thread-Safe Collections / 線程安全的集合 667
10.6.1 Blocking Queues / 阻塞隊列 668
10.6.2 Efficient Maps, Sets, and Queues /
高效的映射、集和隊列 674
10.6.3 Atomic Update of Map Entries / 映射條目的原子更新 676
10.6.4 Bulk Operations on Concurrent Hash Maps /
並發哈希映射的主要操作 679
目錄 xv
10.6.5 Concurrent Set Views / 並發集視圖 682
10.6.6 Copy on Write Arrays / 寫時復制數組 682
10.6.7 Parallel Array Algorithms / 並行數組算法 682
10.6.8 Older Thread-Safe Collections / 較早的線程安全集合 684
10.7 Asynchronous Computations / 異步計算 685
10.7.1 Completable Futures / CompletableFuture 685
10.7.2 Composing Completable Futures /
組合 CompletableFuture 687
10.7.3 Long-Running Tasks in User-Interface Callbacks /
用戶界面回調中的長時間運行任務 694
10.8 Processes / 進程 702
10.8.1 Building a Process / 構建進程 702
10.8.2 Running a Process / 運行進程 704
10.8.3 Process Handles / 進程句柄 706
Chapter 11: Annotations / 註解 711
11.1 Using Annotations / 使用註解 711
11.1.1 Annotation Elements / 註解元素 712
11.1.2 Multiple and Repeated Annotations /
多個註解與重復註解 713
11.1.3 Annotating Declarations / 對聲明進行註解 713
11.1.4 Annotating Type Uses / 對類型的使用進行註解 714
11.1.5 Making Receivers Explicit / 使接收者參數變為顯式的 716
11.2 Defining Annotations / 定義註解 717
11.3 Annotations in the Java API / Java API 中的註解 720
11.3.1 Annotations for Compilation / 用於編譯的註解 721
11.3.2 Meta-Annotations / 元註解 723
11.4 Processing Annotations at Runtime / 在運行時處理註解 725
11.5 Source-Level Annotation Processing / 源代碼級註解處理 729
11.5.1 Annotation Processors / 註解處理器 729
11.5.2 The Language Model API / 語言默寫 API 730
11.5.3 Using Annotations to Generate Source Code /
使用註解來生成源代碼 731
目錄 xvi
11.6 Bytecode Engineering / 字節碼工程 736
11.6.1 Modifying Class Files / 修改類文件 736
11.6.2 Modifying Bytecodes at Load Time /
在加載時修改字節碼 743
Chapter 12: The Java Platform Module System /Java 平臺模塊系統 747
12.1 The Module Concept / 模塊的概念 747
12.2 Naming Modules / 命名模塊 748
12.3 The Modular "Hello, World!" Program /
模塊化的“Hello,World!”程序 749
12.4 Requiring Modules / 導入模塊 751
12.5 Exporting Packages / 導出包 753
12.6 Modular JARs / 模塊化的 JAR 文件 757
12.7 Modules and Reflective Access / 模塊與反射訪問 759
12.8 Automatic Modules / 自動模塊 762
12.9 The Unnamed Module / 未命名模塊 764
12.10 Command-Line Flags for Migration /
用於遷移的命令行選項 765
12.11 Transitive and Static Requirements / 傳遞和靜態導入 766
12.12 Qualified Exporting and Opening / 限制導出和打開 768
12.13 Service Loading / 服務加載 769
12.14 Tools for Working with Modules / 處理模塊的工具 772
Appendix / 附錄 775

