Java核心技術 卷II:高級特性(第13版 英文版)
凱·S. 霍斯特曼(Cay S. Horstmann)
相關主題
商品描述
本書是經典的《Java 核心技術 卷Ⅱ:高級特性》的新版。這一版對全書進行了全面修訂,以涵蓋Java 21 的新特性。
本書是 Java 技術權威指南,全面覆蓋 Java 技術的高級主題,包括流、輸入與輸出、XML、網絡API、數據庫編程、日期與時間 API、國際化、編譯與腳本、安全、圖形用戶界面編程、Swing 用戶界面組件、高級 Swing 和圖形編程、本地方法等內容。本書對 Java 技術的闡述精確到位,敘述方式深入淺出,並包含大量程序示例,從而幫助讀者充分理解 Java 語言以及 Java 類庫的相關高級特性。
本書適合想將 Java 應用於實際項目的軟件開發人員、高等院校教師和學生參考閱讀。
作者簡介
凱·S. 霍斯特曼(Cay S. Horstmann)
現任聖何塞州立大學計算機科學榮譽教授,“Java 大師”(Java Champion)。他是《Java核心技術速學版(第 3 版)》《寫給大忙人的現代 JavaScript》《快學 Scala(第 2 版)》以及《寫給大忙人看的 Java SE 8》的作者。他還編寫了很多針對專業程序員和計算機科學專業學生的其他圖書。
目錄大綱
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

