Java核心技术 卷I:基础知识(第13版 英文版)

978-7-115-68400-4
作者: 凯•S.霍斯特曼(Cay S. Horstmann)
译者:
编辑: 陈灿然
分类: Java

图书目录:

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 Parameters for Type Matching /

使用 Class参数进行类型匹配 499

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 Parameters for Type Matching /

使用 Class参数进行类型匹配 499

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

详情

本书是经典的《Java 核心技术 卷Ⅰ:基础知识》的新版。这一版对全书进行了全面修订,以涵盖Java21的新特性。 新版延续之前版本的优良传统,囊括了Java的全部基础知识,用数百个实际的工程案例,全面系统地讲解了Java语言的核心概念、语法、重要特性、开发方法。着力让读者在充分理解Java语言和Java类库的基础上,灵活应用Java提供的高级特性,具体包括Java语言基础、面向对象编程、反射和代理、接口和内部类、异常处理、泛型编程、集合类框架、并发编程、注解和 Java 平台模块系统等内容。 本书适合想将Java应用于实际项目的软件开发人员、高等院校教师和学生参考阅读。

图书摘要

相关图书

200问通关Java面试问题详解+实战模拟
200问通关Java面试问题详解+实战模拟
Java代码审计实战
Java代码审计实战
Java核心技术速学版(第3版)
Java核心技术速学版(第3版)
Java编程从入门到精通
Java编程从入门到精通
Java核心技术 卷II:高级特性(第13版 英文版)
Java核心技术 卷II:高级特性(第13版 英文版)
冲刺高薪Offer——Java并发编程进阶及面试指南
冲刺高薪Offer——Java并发编程进阶及面试指南

相关文章

相关课程