Chapter 1: Streams / 流 1
1.1 From Iterating to Stream Operations / 从迭代到流操作 1
1.2 Stream Creation / 流的创建 4
1.3 The filter, map, and flatMap Methods / filter、map 和
flatMap 方法 10
1.4 Extracting Substreams and Combining Streams/提取子流和
组合流 13
1.5 Other Stream Transformations/其他流变换 14
1.6 Simple Reductions / 简单规约 15
1.7 The Optional Type /Optional 类型 17
1.7.1 Getting an Optional Value / 获得 Optional 值 17
1.7.2 Consuming an Optional Value / 消耗 Optional 值 17
1.7.3 Pipelining Optional Values / 以流水线方式使用
Optional 值 18
1.7.4 How Not to Work with Optional Values/避免错误
使用 Optional 值 19
1.7.5 Creating Optional Values / 创建 Optional 值 20
1.7.6 Composing Optional Value Functions with flatMap/
使用 flatMap 组合 Optional 值函数 21
1.7.7 Turning an Optional into a Stream / 将 Optional 值
变到流中 22
1.8 Collecting Results/收集结果 25
1.9 Collecting into Maps / 将结果收集到映射中 29
1.10 Grouping and Partitioning / 分组与分区 33
1.11 Downstream Collectors / 下游收集器 34
1.12 Reduction Operations / 规约操作 40
1.13 Primitive Type Streams / 基本类型流 42
目录
i
目录 ii
1.14 Parallel Streams / 并行流 47
Chapter 2: Input and Output / 输入与输出 53
2.1 Input/Output Streams / 输入/输出流 53
2.1.1 Reading and Writing Bytes / 读写字节 53
2.1.2 The Complete Stream Zoo / 流谱系概览 56
2.1.3 Combining Input/Output Stream Filters /
组合输入/输出流过滤器 61
2.1.4 Text Input and Output /文本输入与输出 65
2.1.5 How to Read Text Input / 输入文本 65
2.1.6 How to Write Text Output / 输出文本 67
2.1.7 Saving Objects in Text Format / 以文本格式保存对象 69
2.1.8 Character Encodings / 字符编码 72
2.1.9 Reading Character Input / 读取字符输入 76
2.2 Reading and Writing Binary Data / 读写二进制数据 77
2.2.1 The DataInput and DataOutput Interfaces /
DataInput 和 DataOutput 接口 77
2.2.2 Random-Access Files / 随机访问文件 80
2.2.3 ZIP Archives / ZIP 文档 84
2.3 Object Input/Output Streams and Serialization/
对象输入/输出流与序列化 87
2.3.1 Saving and Loading Serializable Objects/
序列化对象的保存与加载 87
2.3.2 Understanding the Object Serialization File Format/
理解对象序列化文件格式 93
2.3.3 Transient Fields / transient 字段 101
2.3.4 The readObject and writeObject Methods /
readObject 与 writeObject 方法 101
2.3.5 The readExternal and writeExternal Methods /
readExternal 与 writeExternal 方法 103
2.3.6 The readResolve and writeReplace Methods /
readResolve 与 writeReplace 方法 104
2.3.7 Versioning / 版本管理 106
目录 iii
2.3.8 Using Serialization for Cloning / 将序列化用于克隆 109
2.3.9 Deserialization and Security / 反序列化与安全 111
2.4 Working with Files / 处理文件 113
2.4.1 Paths /路径 113
2.4.2 Reading and Writing Files / 读写文件 116
2.4.3 Creating Files and Directories / 创建文件和目录 117
2.4.4 Copying, Moving, and Deleting Files /
复制、移动和删除文件 119
2.4.5 Getting File Information / 获取文件信息 121
2.4.6 Visiting Directory Entries / 访问目录条目 123
2.4.7 Using Directory Streams / 使用目录流 124
2.4.8 ZIP File Systems / ZIP 文件系统 128
2.5 Memory-Mapped Files / 内存映射文件 129
2.5.1 Memory-Mapped File Performance /
内存映射文件的性能 129
2.5.2 The Buffer Data Structure / 缓冲区数据结构 137
2.6 File Locking / 文件锁定 139
2.7 Regular Expressions / 正则表达式 144
2.7.1 The Regular Expression Syntax / 正则表达式语法 144
2.7.2 Testing a Match / 测试匹配 150
2.7.3 Finding All Matches in a String /
寻找字符串中所有匹配情况 151
2.7.4 Groups / 分组 152
2.7.5 Splitting along Delimiters / 使用分隔符进行分割 155
2.7.6 Replacing Matches / 替换匹配部分 156
2.7.7 Flags / 标志 157
Chapter3: XML 161
3.1 Introducing XML / XML 概述 161
3.2 The Structure of an XML Document / XML 文档的结构 163
3.3 Parsing an XML Document / 解析 XML 文档 167
3.4 Validating XML Documents / 验证 XML 文档 176
3.4.1 Document Type Definitions / 文档类型定义 177
目录 ii
1.14 Parallel Streams / 并行流 47
Chapter 2: Input and Output / 输入与输出 53
2.1 Input/Output Streams / 输入/输出流 53
2.1.1 Reading and Writing Bytes / 读写字节 53
2.1.2 The Complete Stream Zoo / 流谱系概览 56
2.1.3 Combining Input/Output Stream Filters /
组合输入/输出流过滤器 61
2.1.4 Text Input and Output /文本输入与输出 65
2.1.5 How to Read Text Input / 输入文本 65
2.1.6 How to Write Text Output / 输出文本 67
2.1.7 Saving Objects in Text Format / 以文本格式保存对象 69
2.1.8 Character Encodings / 字符编码 72
2.1.9 Reading Character Input / 读取字符输入 76
2.2 Reading and Writing Binary Data / 读写二进制数据 77
2.2.1 The DataInput and DataOutput Interfaces /
DataInput 和 DataOutput 接口 77
2.2.2 Random-Access Files / 随机访问文件 80
2.2.3 ZIP Archives / ZIP 文档 84
2.3 Object Input/Output Streams and Serialization/
对象输入/输出流与序列化 87
2.3.1 Saving and Loading Serializable Objects/
序列化对象的保存与加载 87
2.3.2 Understanding the Object Serialization File Format/
理解对象序列化文件格式 93
2.3.3 Transient Fields / transient 字段 101
2.3.4 The readObject and writeObject Methods /
readObject 与 writeObject 方法 101
2.3.5 The readExternal and writeExternal Methods /
readExternal 与 writeExternal 方法 103
2.3.6 The readResolve and writeReplace Methods /
readResolve 与 writeReplace 方法 104
2.3.7 Versioning / 版本管理 106
目录 iii
2.3.8 Using Serialization for Cloning / 将序列化用于克隆 109
2.3.9 Deserialization and Security / 反序列化与安全 111
2.4 Working with Files / 处理文件 113
2.4.1 Paths /路径 113
2.4.2 Reading and Writing Files / 读写文件 116
2.4.3 Creating Files and Directories / 创建文件和目录 117
2.4.4 Copying, Moving, and Deleting Files /
复制、移动和删除文件 119
2.4.5 Getting File Information / 获取文件信息 121
2.4.6 Visiting Directory Entries / 访问目录条目 123
2.4.7 Using Directory Streams / 使用目录流 124
2.4.8 ZIP File Systems / ZIP 文件系统 128
2.5 Memory-Mapped Files / 内存映射文件 129
2.5.1 Memory-Mapped File Performance /
内存映射文件的性能 129
2.5.2 The Buffer Data Structure / 缓冲区数据结构 137
2.6 File Locking / 文件锁定 139
2.7 Regular Expressions / 正则表达式 144
2.7.1 The Regular Expression Syntax / 正则表达式语法 144
2.7.2 Testing a Match / 测试匹配 150
2.7.3 Finding All Matches in a String /
寻找字符串中所有匹配情况 151
2.7.4 Groups / 分组 152
2.7.5 Splitting along Delimiters / 使用分隔符进行分割 155
2.7.6 Replacing Matches / 替换匹配部分 156
2.7.7 Flags / 标志 157
Chapter3: XML 161
3.1 Introducing XML / XML 概述 161
3.2 The Structure of an XML Document / XML 文档的结构 163
3.3 Parsing an XML Document / 解析 XML 文档 167
3.4 Validating XML Documents / 验证 XML 文档 176
3.4.1 Document Type Definitions / 文档类型定义 177
目录 iv
3.4.2 XML Schema / XML 模式 186
3.4.3 A Practical Example / 实用示例 189
3.5 Locating Information with XPath / 使用 XPath 定位信息 195
3.6 Using Namespaces / 使用命名空间 200
3.7 Streaming Parsers / 流解析器 203
3.7.1 Using the SAX Parser / 使用 SAX 解析器 204
3.7.2 Using the StAX Parser / 使用 StAX 解析器 208
3.8 Generating XML Documents / 生成 XML 文档 212
3.8.1 Documents without Namespaces / 不带命名空间的文档 212
3.8.2 Documents with Namespaces / 带命名空间的文档 213
3.8.3 Writing Documents / 写入文档 214
3.8.4 Writing an XML Document with StAX /
使用 StAX 写入 XML 文档 216
3.9 XSL Transformations / XSL 转换 223
Chapter4: Networking / 网络 235
4.1 Connecting to a Server / 连接到服务器 235
4.1.1 Using Telnet / 使用 Telnet 235
4.1.2 Connecting to a Server with Java / 使用 Java 连接到服务器 238
4.1.3 Socket Timeouts / 套接字超时 240
4.1.4 Internet Addresses / Internet 地址 241
4.2 Implementing Servers / 实现服务器 243
4.2.1 Server Sockets / 服务器套接字 243
4.2.2 Serving Multiple Clients / 服务多个客户端 246
4.2.3 Half-Close / 半关闭 249
4.2.4 Interruptible Sockets / 可中断套接字 250
4.2.5 Secure Socket Communication / 安全套接字通信 255
4.3 Getting Web Data / 获取 Web 数据 259
4.3.1 URLs and URIs / URL 和 URI 259
4.3.2 Using a URLConnection to Retrieve Information /
使用 URLConnection 获取信息 262
4.3.3 Posting Form Data / 提交表单数据 269
4.4 The HTTP Client / HTTP 客户端 278
目录 v
4.4.1 The HttpClient Class / HttpClient 类 278
4.4.2 The HttpRequest class and Body Publishers /
HttpRequest 类与正文发布器 279
4.4.3 The HttpResponse Interface and Body Handlers /
HttpResponse 接口与正文处理器 280
4.4.4 Asynchronous Processing / 异步处理 281
4.5 The Simple HTTP Server / 简单 HTTP 服务器 287
4.5.1 The Command-Line Tool / 命令行工具 287
4.5.2 The HTTP Server API / HTTP 服务器 API 288
4.5.3 Handlers / 处理程序 289
4.5.4 Filters / 过滤器 290
4.6 Sending E-Mail / 发送电子邮件 292
Chapter5: Database Programming / 数据库编程 297
5.1 The Design of JDBC / JDBC 的设计 297
5.1.1 JDBC Driver Types / JDBC 驱动程序分类 298
5.1.2 Typical Uses of JDBC / JDBC 的典型用法 299
5.2 The Structured Query Language / 结构化查询语言 300
5.3 JDBC Configuration / JDBC 配置 306
5.3.1 Database URLs / 数据库 URL 307
5.3.2 Driver JAR Files / 驱动程序 JAR 文件 307
5.3.3 Starting the Database / 启动数据库 307
5.3.4 Connecting to the Database / 连接到数据库 308
5.4 Working with JDBC Statements / 使用 JDBC 语句 311
5.4.1 Executing SQL Statements / 执行 SQL 语句 312
5.4.2 Managing Connections, Statements, and Result Sets /
管理连接、语句和结果集 315
5.4.3 Analyzing SQL Exceptions / 分析 SQL 异常 316
5.4.4 Populating a Database / 填充数据库 318
5.5 Query Execution / 执行查询 322
5.5.1 Prepared Statements / 预备语句 322
5.5.2 Reading and Writing LOBs / 读写 LOB 329
5.5.3 SQL Escapes / SQL 转义 331
目录 iv
3.4.2 XML Schema / XML 模式 186
3.4.3 A Practical Example / 实用示例 189
3.5 Locating Information with XPath / 使用 XPath 定位信息 195
3.6 Using Namespaces / 使用命名空间 200
3.7 Streaming Parsers / 流解析器 203
3.7.1 Using the SAX Parser / 使用 SAX 解析器 204
3.7.2 Using the StAX Parser / 使用 StAX 解析器 208
3.8 Generating XML Documents / 生成 XML 文档 212
3.8.1 Documents without Namespaces / 不带命名空间的文档 212
3.8.2 Documents with Namespaces / 带命名空间的文档 213
3.8.3 Writing Documents / 写入文档 214
3.8.4 Writing an XML Document with StAX /
使用 StAX 写入 XML 文档 216
3.9 XSL Transformations / XSL 转换 223
Chapter4: Networking / 网络 235
4.1 Connecting to a Server / 连接到服务器 235
4.1.1 Using Telnet / 使用 Telnet 235
4.1.2 Connecting to a Server with Java / 使用 Java 连接到服务器 238
4.1.3 Socket Timeouts / 套接字超时 240
4.1.4 Internet Addresses / Internet 地址 241
4.2 Implementing Servers / 实现服务器 243
4.2.1 Server Sockets / 服务器套接字 243
4.2.2 Serving Multiple Clients / 服务多个客户端 246
4.2.3 Half-Close / 半关闭 249
4.2.4 Interruptible Sockets / 可中断套接字 250
4.2.5 Secure Socket Communication / 安全套接字通信 255
4.3 Getting Web Data / 获取 Web 数据 259
4.3.1 URLs and URIs / URL 和 URI 259
4.3.2 Using a URLConnection to Retrieve Information /
使用 URLConnection 获取信息 262
4.3.3 Posting Form Data / 提交表单数据 269
4.4 The HTTP Client / HTTP 客户端 278
目录 v
4.4.1 The HttpClient Class / HttpClient 类 278
4.4.2 The HttpRequest class and Body Publishers /
HttpRequest 类与正文发布器 279
4.4.3 The HttpResponse Interface and Body Handlers /
HttpResponse 接口与正文处理器 280
4.4.4 Asynchronous Processing / 异步处理 281
4.5 The Simple HTTP Server / 简单 HTTP 服务器 287
4.5.1 The Command-Line Tool / 命令行工具 287
4.5.2 The HTTP Server API / HTTP 服务器 API 288
4.5.3 Handlers / 处理程序 289
4.5.4 Filters / 过滤器 290
4.6 Sending E-Mail / 发送电子邮件 292
Chapter5: Database Programming / 数据库编程 297
5.1 The Design of JDBC / JDBC 的设计 297
5.1.1 JDBC Driver Types / JDBC 驱动程序分类 298
5.1.2 Typical Uses of JDBC / JDBC 的典型用法 299
5.2 The Structured Query Language / 结构化查询语言 300
5.3 JDBC Configuration / JDBC 配置 306
5.3.1 Database URLs / 数据库 URL 307
5.3.2 Driver JAR Files / 驱动程序 JAR 文件 307
5.3.3 Starting the Database / 启动数据库 307
5.3.4 Connecting to the Database / 连接到数据库 308
5.4 Working with JDBC Statements / 使用 JDBC 语句 311
5.4.1 Executing SQL Statements / 执行 SQL 语句 312
5.4.2 Managing Connections, Statements, and Result Sets /
管理连接、语句和结果集 315
5.4.3 Analyzing SQL Exceptions / 分析 SQL 异常 316
5.4.4 Populating a Database / 填充数据库 318
5.5 Query Execution / 执行查询 322
5.5.1 Prepared Statements / 预备语句 322
5.5.2 Reading and Writing LOBs / 读写 LOB 329
5.5.3 SQL Escapes / SQL 转义 331
目录 vi
5.5.4 Multiple Results / 多结果集 332
5.5.5 Retrieving Autogenerated Keys / 获取自动生成的主键 333
5.6 Scrollable and Updatable Result Sets / 可滚动和可更新的结果集 334
5.6.1 Scrollable Result Sets / 可滚动的结果集 334
5.6.2 Updatable Result Sets/ 可更新的结果集 336
5.7 Row Sets / 行集 340
5.7.1 Constructing Row Sets / 构建行集 341
5.7.2 Cached Row Sets / 缓存的行集 341
5.8 Metadata / 元数据 344
5.9 Transactions / 事务 353
5.9.1 Programming Transactions with JDBC /
使用 JDBC 编程实现事务 353
5.9.2 Save Points / 保存点 354
5.9.3 Batch Updates / 批量更新 354
5.9.4 Advanced SQL Types / 高级 SQL 类型 356
5.10 Connection Management in Web and Enterprise Applications /
Web 与企业级应用中的连接管理 358
Chapter6: The Date and Time API / 日期与时间 API 361
6.1 The Time Line / 时间线 361
6.2 Local Dates / 本地日期 365
6.3 Date Adjusters / 日期调整 370
6.4 Local Time / 本地时间 372
6.5 Zoned Time / 时区时间 373
6.6 Formatting and Parsing / 格式化与解析 377
6.7 Interoperating with Legacy Code / 与遗留代码互操作 383
Chapter7: Internationalization / 国际化 385
7.1 Locales / 地域 385
7.1.1 Why Locales / 为什么要引入地域类 385
7.1.2 Specifying Locales / 指定地域 386
7.1.3 The Default Locale / 默认地域 389
7.1.4 Display Names / 显示地域名 390
目录 vii
7.2 Number Formats / 数字格式 392
7.2.1 Formatting Numeric Values / 格式化数字值 392
7.2.2 The DecimalFormat Class / DecimalFormat 类 396
7.2.3 Currencies / 货币 399
7.3 Date and Time / 日期与时间 401
7.4 Collation and Normalization / 排序规则与标准化 405
7.5 Message Formatting / 消息格式化 410
7.5.1 Formatting Numbers and Dates / 格式化数字和日期 410
7.5.2 Choice Formats / choice 格式化选项 413
7.6 Text Boundaries / 文本边界 415
7.7 Text Input and Output / 文本输入与输出 416
7.7.1 Text Files / 文本文件 416
7.7.2 Line Endings / 文本行结尾符号 416
7.7.3 The Console / 控制台 417
7.7.4 The UTF-8 Byte Order Mark / UTF-8 字节顺序标记 418
7.7.5 Character Encoding of Source Files / 源文件的字符编码 418
7.8 Resource Bundles / 资源包 419
7.8.1 Locating Resource Bundles / 定位资源包 419
7.8.2 Property Files / 属性文件 421
7.8.3 Bundle Classes / 包类 421
7.9 A Complete Example / 完整示例 424
Chapter8: Compiling and Scripting / 编译与脚本 429
8.1 The Compiler API / 编译器 API 429
8.1.1 Invoking the Compiler / 调用编译器 429
8.1.2 Launching a Compilation Task / 启动编译任务 429
8.1.3 Capturing Diagnostics / 捕获诊断信息 430
8.1.4 Reading Source Files from Memory /
从内存中读取源文件 431
8.1.5 Writing Byte Codes to Memory / 将字节码写入内存 432
8.1.6 An Example: Dynamic Java Code Generation/
示例:动态 Java 代码生成 433
8.2 Scripting for the Java Platform / Java 平台的脚本 438
目录 vi
5.5.4 Multiple Results / 多结果集 332
5.5.5 Retrieving Autogenerated Keys / 获取自动生成的主键 333
5.6 Scrollable and Updatable Result Sets / 可滚动和可更新的结果集 334
5.6.1 Scrollable Result Sets / 可滚动的结果集 334
5.6.2 Updatable Result Sets/ 可更新的结果集 336
5.7 Row Sets / 行集 340
5.7.1 Constructing Row Sets / 构建行集 341
5.7.2 Cached Row Sets / 缓存的行集 341
5.8 Metadata / 元数据 344
5.9 Transactions / 事务 353
5.9.1 Programming Transactions with JDBC /
使用 JDBC 编程实现事务 353
5.9.2 Save Points / 保存点 354
5.9.3 Batch Updates / 批量更新 354
5.9.4 Advanced SQL Types / 高级 SQL 类型 356
5.10 Connection Management in Web and Enterprise Applications /
Web 与企业级应用中的连接管理 358
Chapter6: The Date and Time API / 日期与时间 API 361
6.1 The Time Line / 时间线 361
6.2 Local Dates / 本地日期 365
6.3 Date Adjusters / 日期调整 370
6.4 Local Time / 本地时间 372
6.5 Zoned Time / 时区时间 373
6.6 Formatting and Parsing / 格式化与解析 377
6.7 Interoperating with Legacy Code / 与遗留代码互操作 383
Chapter7: Internationalization / 国际化 385
7.1 Locales / 地域 385
7.1.1 Why Locales / 为什么要引入地域类 385
7.1.2 Specifying Locales / 指定地域 386
7.1.3 The Default Locale / 默认地域 389
7.1.4 Display Names / 显示地域名 390
目录 vii
7.2 Number Formats / 数字格式 392
7.2.1 Formatting Numeric Values / 格式化数字值 392
7.2.2 The DecimalFormat Class / DecimalFormat 类 396
7.2.3 Currencies / 货币 399
7.3 Date and Time / 日期与时间 401
7.4 Collation and Normalization / 排序规则与标准化 405
7.5 Message Formatting / 消息格式化 410
7.5.1 Formatting Numbers and Dates / 格式化数字和日期 410
7.5.2 Choice Formats / choice 格式化选项 413
7.6 Text Boundaries / 文本边界 415
7.7 Text Input and Output / 文本输入与输出 416
7.7.1 Text Files / 文本文件 416
7.7.2 Line Endings / 文本行结尾符号 416
7.7.3 The Console / 控制台 417
7.7.4 The UTF-8 Byte Order Mark / UTF-8 字节顺序标记 418
7.7.5 Character Encoding of Source Files / 源文件的字符编码 418
7.8 Resource Bundles / 资源包 419
7.8.1 Locating Resource Bundles / 定位资源包 419
7.8.2 Property Files / 属性文件 421
7.8.3 Bundle Classes / 包类 421
7.9 A Complete Example / 完整示例 424
Chapter8: Compiling and Scripting / 编译与脚本 429
8.1 The Compiler API / 编译器 API 429
8.1.1 Invoking the Compiler / 调用编译器 429
8.1.2 Launching a Compilation Task / 启动编译任务 429
8.1.3 Capturing Diagnostics / 捕获诊断信息 430
8.1.4 Reading Source Files from Memory /
从内存中读取源文件 431
8.1.5 Writing Byte Codes to Memory / 将字节码写入内存 432
8.1.6 An Example: Dynamic Java Code Generation/
示例:动态 Java 代码生成 433
8.2 Scripting for the Java Platform / Java 平台的脚本 438
目录 viii
8.2.1 Getting a Scripting Engine / 获得脚本引擎 439
8.2.2 Script Evaluation and Bindings / 脚本求值与绑定 440
8.2.3 Redirecting Input and Output / 重定向输入输出 442
8.2.4 Calling Scripting Functions and Methods /
调用脚本函数和方法 443
8.2.5 Compiling a Script / 编译脚本 445
8.2.6 An Example: Script Sheets / 示例:脚本练习 446
Chapter9: Security / 安全 449
9.1 Class Loaders / 类加载器 449
9.1.1 The Class-Loading Process / 类加载流程 450
9.1.2 The Class Loader Hierarchy / 类加载器层次结构 451
9.1.3 Using Class Loaders as Namespaces /
将类加载器作为命名空间 453
9.1.4 Writing Your Own Class Loader / 编写自己的类加载器 454
9.1.5 Bytecode Verification / 字节码验证 459
9.2 User Authentication / 用户认证 464
9.2.1 The JAAS Framework / JAAS 框架 464
9.2.2 JAAS Login Modules / JAAS 登录模块 467
9.3 Digital Signatures / 数字签名 475
9.3.1 Message Digests / 消息摘要 476
9.3.2 Message Signing / 消息签名 479
9.3.3 Verifying a Signature / 验证签名 482
9.3.4 The Authentication Problem / 认证问题 484
9.3.5 Certificate Signing / 证书签名 487
9.3.6 Certificate Requests / 证书请求 488
9.3.7 Code Signing / 代码签名 489
9.3.8 Password Hashing / 密码哈希 491
9.4 Encryption / 加密 492
9.4.1 Symmetric Ciphers / 对称密码 492
9.4.2 Key Generation / 生成密钥 494
9.4.3 Cipher Streams / 加密流 498
9.4.4 Public Key Ciphers / 公钥密码 500
目录 ix
Chapter10: Graphical User Interface Programming / 图形用户界面编程 505
10.1 A History of Java User Interface Toolkits /
Java 用户界面工具包发展历史 505
10.2 Displaying Frames / 显示框架 506
10.2.1 Creating a Frame / 创建框架 507
10.2.2 Frame Properties / 框架属性 509
10.3 Displaying Information in a Component / 在组件中显示信息 513
10.3.1 Working with 2D Shapes / 处理 2D 图形 518
10.3.2 Using Color / 使用颜色 526
10.3.3 Using Fonts / 使用字体 527
10.3.4 Displaying Images / 显示图片 534
10.4 Event Handling / 事件处理 537
10.4.1 Basic Event Handling Concepts / 事件处理的基本概念 537
10.4.2 Example: Handling a Button Click /
示例:处理按钮点击事件 538
10.4.3 Specifying Listeners Concisely / 设置监听器的简洁方法 543
10.4.4 Adapter Classes / 适配器类 544
10.4.5 Actions / 动作 546
10.4.6 Mouse Events / 鼠标事件 552
10.4.7 The AWT Event Hierarchy / AWT 事件层次 558
10.5 The Preferences API / Preferences API 562
Chapter11: User Interface Components with Swing /
Swing 用户界面组件 569
11.1 Swing and the Model-View-Controller Design Pattern /
Swing 和模型-视图-控制器设计模式 569
11.2 Introduction to Layout Management / 布局管理概述 574
11.2.1 Layout Managers / 布局管理器 574
11.2.2 Border Layout / 边框布局 576
11.2.3 Grid Layout / 网格布局 579
11.3 Text Input / 文本输入 580
11.3.1 Text Fields / 文本框 580
目录 viii
8.2.1 Getting a Scripting Engine / 获得脚本引擎 439
8.2.2 Script Evaluation and Bindings / 脚本求值与绑定 440
8.2.3 Redirecting Input and Output / 重定向输入输出 442
8.2.4 Calling Scripting Functions and Methods /
调用脚本函数和方法 443
8.2.5 Compiling a Script / 编译脚本 445
8.2.6 An Example: Script Sheets / 示例:脚本练习 446
Chapter9: Security / 安全 449
9.1 Class Loaders / 类加载器 449
9.1.1 The Class-Loading Process / 类加载流程 450
9.1.2 The Class Loader Hierarchy / 类加载器层次结构 451
9.1.3 Using Class Loaders as Namespaces /
将类加载器作为命名空间 453
9.1.4 Writing Your Own Class Loader / 编写自己的类加载器 454
9.1.5 Bytecode Verification / 字节码验证 459
9.2 User Authentication / 用户认证 464
9.2.1 The JAAS Framework / JAAS 框架 464
9.2.2 JAAS Login Modules / JAAS 登录模块 467
9.3 Digital Signatures / 数字签名 475
9.3.1 Message Digests / 消息摘要 476
9.3.2 Message Signing / 消息签名 479
9.3.3 Verifying a Signature / 验证签名 482
9.3.4 The Authentication Problem / 认证问题 484
9.3.5 Certificate Signing / 证书签名 487
9.3.6 Certificate Requests / 证书请求 488
9.3.7 Code Signing / 代码签名 489
9.3.8 Password Hashing / 密码哈希 491
9.4 Encryption / 加密 492
9.4.1 Symmetric Ciphers / 对称密码 492
9.4.2 Key Generation / 生成密钥 494
9.4.3 Cipher Streams / 加密流 498
9.4.4 Public Key Ciphers / 公钥密码 500
目录 ix
Chapter10: Graphical User Interface Programming / 图形用户界面编程 505
10.1 A History of Java User Interface Toolkits /
Java 用户界面工具包发展历史 505
10.2 Displaying Frames / 显示框架 506
10.2.1 Creating a Frame / 创建框架 507
10.2.2 Frame Properties / 框架属性 509
10.3 Displaying Information in a Component / 在组件中显示信息 513
10.3.1 Working with 2D Shapes / 处理 2D 图形 518
10.3.2 Using Color / 使用颜色 526
10.3.3 Using Fonts / 使用字体 527
10.3.4 Displaying Images / 显示图片 534
10.4 Event Handling / 事件处理 537
10.4.1 Basic Event Handling Concepts / 事件处理的基本概念 537
10.4.2 Example: Handling a Button Click /
示例:处理按钮点击事件 538
10.4.3 Specifying Listeners Concisely / 设置监听器的简洁方法 543
10.4.4 Adapter Classes / 适配器类 544
10.4.5 Actions / 动作 546
10.4.6 Mouse Events / 鼠标事件 552
10.4.7 The AWT Event Hierarchy / AWT 事件层次 558
10.5 The Preferences API / Preferences API 562
Chapter11: User Interface Components with Swing /
Swing 用户界面组件 569
11.1 Swing and the Model-View-Controller Design Pattern /
Swing 和模型-视图-控制器设计模式 569
11.2 Introduction to Layout Management / 布局管理概述 574
11.2.1 Layout Managers / 布局管理器 574
11.2.2 Border Layout / 边框布局 576
11.2.3 Grid Layout / 网格布局 579
11.3 Text Input / 文本输入 580
11.3.1 Text Fields / 文本框 580
目录 x
11.3.2 Labels and Labeling Components / 标签与标签组件 582
11.3.3 Password Fields / 密码框 584
11.3.4 Text Areas / 文本区域 584
11.3.5 Scroll Panes / 滚动窗格 585
11.4 Choice Components / 选择组件 588
11.4.1 Checkboxes / 复选框 588
11.4.2 Radio Buttons / 单选按钮 591
11.4.3 Borders / 边框 594
11.4.4 Combo Boxes / 组合框 597
11.4.5 Sliders / 滑动条 600
11.5 Menus / 菜单 607
11.5.1 Menu Building / 菜单构建 607
11.5.2 Icons in Menu Items / 菜单项中的图标 610
11.5.3 Checkbox and Radio Button Menu Items /
复选框和单选按钮菜单项 611
11.5.4 Pop-Up Menus / 弹出菜单 612
11.5.5 Keyboard Mnemonics and Accelerators /
键盘助记符与快捷键 614
11.5.6 Enabling and Disabling Menu Items /
启用和禁用菜单项 616
11.5.7 Toolbars / 工具栏 621
11.5.8 Tooltips / 工具提示 623
11.6 The Grid Bag Layout / 网格袋布局 625
11.6.1 Grid Bag Basics / 网格袋基础 625
11.6.2 The gridx, gridy, gridwidth, and gridheight Parameters /
gridx、gridy、gridwidth 和 gridheight 参数 627
11.6.3 Weight Fields / weight 字段 628
11.6.4 The fill and anchor Parameters / fill 和 anchor 参数 628
11.6.5 Padding / 填充 628
11.6.6 Alternative Method to Specify the gridx, gridy, gridwidth,
and gridheight Parameters / 指定 gridx、gridy、
gridwidth 和 gridheight 参数的另一种方法 629
11.6.7 A Grid Bag Layout Recipe / 网格袋布局使用总结 629
目录 xi
11.6.8 A Helper Class to Tame the Grid Bag Constraints /
驯服网格包约束的辅助类 629
11.7 Custom Layout Managers / 定制布局管理器 635
11.8 Dialog Boxes / 对话框 640
11.8.1 Option Panes / 选项面板 640
11.8.2 Creating Dialogs / 创建对话框 645
11.8.3 Data Exchange / 数据交换 649
11.8.4 File Dialogs / 文件对话框 656
Chapter12: Advanced Swing and Graphics / 高级 Swing 和图形编程 665
12.1 Tables / 表格 665
12.1.1 A Simple Table / 简单表格 665
12.1.2 Table Models / 表格模式 670
12.2 Working with Rows and Columns / 行列操作 673
12.2.1 Column Classes / 列类 674
12.2.2 Accessing Table Columns / 访问表列 674
12.2.3 Resizing Columns / 调整列 674
12.2.4 Resizing Rows / 调整行 677
12.2.5 Selecting Rows, Columns, and Cells /
选择行、列和单元格 677
12.2.6 Sorting Rows / 对行进行排序 678
12.2.7 Filtering Rows / 对列进行过滤 680
12.2.8 Hiding and Displaying Columns / 隐藏或显示列 682
12.3 Cell Rendering and Editing / 单元格的绘制和编辑 690
12.3.1 Rendering Cells / 绘制单元格 690
12.3.2 Rendering the Header / 绘制表头 691
12.3.3 Editing Cells / 编辑单元格 692
12.3.4 Custom Editors / 定制编辑器 694
12.4 Trees / 树 702
12.4.1 Simple Trees / 简单的树 703
12.4.2 Editing Trees and Tree Paths / 编辑树和树路径 714
12.4.3 Node Enumeration / 节点枚举 721
12.4.4 Rendering Nodes / 绘制节点 723
目录 x
11.3.2 Labels and Labeling Components / 标签与标签组件 582
11.3.3 Password Fields / 密码框 584
11.3.4 Text Areas / 文本区域 584
11.3.5 Scroll Panes / 滚动窗格 585
11.4 Choice Components / 选择组件 588
11.4.1 Checkboxes / 复选框 588
11.4.2 Radio Buttons / 单选按钮 591
11.4.3 Borders / 边框 594
11.4.4 Combo Boxes / 组合框 597
11.4.5 Sliders / 滑动条 600
11.5 Menus / 菜单 607
11.5.1 Menu Building / 菜单构建 607
11.5.2 Icons in Menu Items / 菜单项中的图标 610
11.5.3 Checkbox and Radio Button Menu Items /
复选框和单选按钮菜单项 611
11.5.4 Pop-Up Menus / 弹出菜单 612
11.5.5 Keyboard Mnemonics and Accelerators /
键盘助记符与快捷键 614
11.5.6 Enabling and Disabling Menu Items /
启用和禁用菜单项 616
11.5.7 Toolbars / 工具栏 621
11.5.8 Tooltips / 工具提示 623
11.6 The Grid Bag Layout / 网格袋布局 625
11.6.1 Grid Bag Basics / 网格袋基础 625
11.6.2 The gridx, gridy, gridwidth, and gridheight Parameters /
gridx、gridy、gridwidth 和 gridheight 参数 627
11.6.3 Weight Fields / weight 字段 628
11.6.4 The fill and anchor Parameters / fill 和 anchor 参数 628
11.6.5 Padding / 填充 628
11.6.6 Alternative Method to Specify the gridx, gridy, gridwidth,
and gridheight Parameters / 指定 gridx、gridy、
gridwidth 和 gridheight 参数的另一种方法 629
11.6.7 A Grid Bag Layout Recipe / 网格袋布局使用总结 629
目录 xi
11.6.8 A Helper Class to Tame the Grid Bag Constraints /
驯服网格包约束的辅助类 629
11.7 Custom Layout Managers / 定制布局管理器 635
11.8 Dialog Boxes / 对话框 640
11.8.1 Option Panes / 选项面板 640
11.8.2 Creating Dialogs / 创建对话框 645
11.8.3 Data Exchange / 数据交换 649
11.8.4 File Dialogs / 文件对话框 656
Chapter12: Advanced Swing and Graphics / 高级 Swing 和图形编程 665
12.1 Tables / 表格 665
12.1.1 A Simple Table / 简单表格 665
12.1.2 Table Models / 表格模式 670
12.2 Working with Rows and Columns / 行列操作 673
12.2.1 Column Classes / 列类 674
12.2.2 Accessing Table Columns / 访问表列 674
12.2.3 Resizing Columns / 调整列 674
12.2.4 Resizing Rows / 调整行 677
12.2.5 Selecting Rows, Columns, and Cells /
选择行、列和单元格 677
12.2.6 Sorting Rows / 对行进行排序 678
12.2.7 Filtering Rows / 对列进行过滤 680
12.2.8 Hiding and Displaying Columns / 隐藏或显示列 682
12.3 Cell Rendering and Editing / 单元格的绘制和编辑 690
12.3.1 Rendering Cells / 绘制单元格 690
12.3.2 Rendering the Header / 绘制表头 691
12.3.3 Editing Cells / 编辑单元格 692
12.3.4 Custom Editors / 定制编辑器 694
12.4 Trees / 树 702
12.4.1 Simple Trees / 简单的树 703
12.4.2 Editing Trees and Tree Paths / 编辑树和树路径 714
12.4.3 Node Enumeration / 节点枚举 721
12.4.4 Rendering Nodes / 绘制节点 723
目录 xii
12.4.5 Listening to Tree Events / 监听树事件 726
12.4.6 Custom Tree Models / 定制树模型 733
12.5 Advanced AWT / 高级 AWT 742
12.5.1 The Rendering Pipeline / 绘制图形的流程 742
12.5.2 The Shape Class Hierarchy/Shape 类层次结构 745
12.5.3 Constructing Shapes / 构造图形 747
12.5.4 Areas / 区域 762
12.5.5 Strokes / 画笔 764
12.5.6 Paint / 着色 772
12.5.7 Coordinate Transformations / 坐标变换 774
12.5.8 Clipping / 剪切 780
12.5.9 Transparency and Composition / 透明和组合 783
12.6 Raster Images / 光栅图像 791
12.6.1 Readers and Writers for Images /
图像的读取器和写入器 792
12.6.2 Obtaining Readers and Writers for Image File Types /
获取不同图像文件类型的读取器和写入器 792
12.6.3 Reading and Writing Files with Multiple Images /
读写包含多个图像的文件 794
12.6.4 Image Manipulation / 图像处理 802
12.6.5 Filtering Images / 图像过滤 809
12.7 Printing / 打印 818
12.7.1 Graphics Printing / 图形打印 818
12.7.2 Multiple-Page Printing / 多页打印 827
12.7.3 Print Services / 打印服务 837
12.7.4 Stream Print Services / 流打印服务 840
12.7.5 Printing Attributes / 打印属性 843
Chapter13: Native Methods / 本地方法 853
13.1 Calling a C Function from a Java Program/
从 Java 程序中调用 C 函数 854
13.2 Numeric Parameters and Return Values / 数值参数与返回值 860
13.3 String Parameters / 字符串参数 862
目录 xiii
13.4 Accessing Fields / 访问字段 868
13.4.1 Accessing Instance Fields / 访问实例字段 868
13.4.2 Accessing Static Fields / 访问静态字段 872
13.5 Encoding Signatures / 编码签名 873
13.6 Calling Java Methods / 调用 Java 方法 875
13.6.1 Instance Methods / 实例方法 875
13.6.2 Static Methods / 静态方法 876
13.6.3 Constructors / 构造器 877
13.6.4 Alternative Method Invocations / 其他调用方法的手段 878
13.7 Accessing Array Elements / 访问数组元素 882
13.8 Handling Errors / 处理错误 886
13.9 Using the Invocation API / 使用 Invocation API 891
13.10 A Complete Example: Accessing the Windows Registry /
完整示例:访问 Windows 注册表 896
13.10.1 Overview of the Windows Registry /
Windows 注册表简介 896
13.10.2 A Java Platform Interface for Accessing the Registry /
用于访问注册表的 Java 平台接口 898
13.10.3 Implementation of Registry Access Functions as Native
Methods / 以本地方法实现注册表访问功能 898
13.11 Foreign Functions: A Glimpse into the Future /
外部函数:Java 未来规划一瞥 911
目录 xii
12.4.5 Listening to Tree Events / 监听树事件 726
12.4.6 Custom Tree Models / 定制树模型 733
12.5 Advanced AWT / 高级 AWT 742
12.5.1 The Rendering Pipeline / 绘制图形的流程 742
12.5.2 The Shape Class Hierarchy/Shape 类层次结构 745
12.5.3 Constructing Shapes / 构造图形 747
12.5.4 Areas / 区域 762
12.5.5 Strokes / 画笔 764
12.5.6 Paint / 着色 772
12.5.7 Coordinate Transformations / 坐标变换 774
12.5.8 Clipping / 剪切 780
12.5.9 Transparency and Composition / 透明和组合 783
12.6 Raster Images / 光栅图像 791
12.6.1 Readers and Writers for Images /
图像的读取器和写入器 792
12.6.2 Obtaining Readers and Writers for Image File Types /
获取不同图像文件类型的读取器和写入器 792
12.6.3 Reading and Writing Files with Multiple Images /
读写包含多个图像的文件 794
12.6.4 Image Manipulation / 图像处理 802
12.6.5 Filtering Images / 图像过滤 809
12.7 Printing / 打印 818
12.7.1 Graphics Printing / 图形打印 818
12.7.2 Multiple-Page Printing / 多页打印 827
12.7.3 Print Services / 打印服务 837
12.7.4 Stream Print Services / 流打印服务 840
12.7.5 Printing Attributes / 打印属性 843
Chapter13: Native Methods / 本地方法 853
13.1 Calling a C Function from a Java Program/
从 Java 程序中调用 C 函数 854
13.2 Numeric Parameters and Return Values / 数值参数与返回值 860
13.3 String Parameters / 字符串参数 862
目录 xiii
13.4 Accessing Fields / 访问字段 868
13.4.1 Accessing Instance Fields / 访问实例字段 868
13.4.2 Accessing Static Fields / 访问静态字段 872
13.5 Encoding Signatures / 编码签名 873
13.6 Calling Java Methods / 调用 Java 方法 875
13.6.1 Instance Methods / 实例方法 875
13.6.2 Static Methods / 静态方法 876
13.6.3 Constructors / 构造器 877
13.6.4 Alternative Method Invocations / 其他调用方法的手段 878
13.7 Accessing Array Elements / 访问数组元素 882
13.8 Handling Errors / 处理错误 886
13.9 Using the Invocation API / 使用 Invocation API 891
13.10 A Complete Example: Accessing the Windows Registry /
完整示例:访问 Windows 注册表 896
13.10.1 Overview of the Windows Registry /
Windows 注册表简介 896
13.10.2 A Java Platform Interface for Accessing the Registry /
用于访问注册表的 Java 平台接口 898
13.10.3 Implementation of Registry Access Functions as Native
Methods / 以本地方法实现注册表访问功能 898
13.11 Foreign Functions: A Glimpse into the Future /
外部函数:Java 未来规划一瞥 911