Java Examples in a Nutshell, 3/e
暫譯: Java 範例精要 (第三版)

David Flanagan

  • 出版商: O'Reilly
  • 出版日期: 2004-02-24
  • 定價: $1,380
  • 售價: 5.0$690
  • 語言: 英文
  • 頁數: 720
  • 裝訂: Paperback
  • ISBN: 0596006209
  • ISBN-13: 9780596006204
  • 相關分類: Java 程式語言
  • 立即出貨

買這商品的人也買了...

商品描述

The author of the best-selling Java in a Nutshell has created an entire book of real-world Java programming examples that you can learn from. If you learn best "by example," this is the book for you.

This third edition covers Java 1.4 and contains 193 complete, practical examples: over 21,900 lines of densely commented, professionally written Java code, covering 20 distinct client-side and server-side APIs. It includes new chapters on the Java Sound API and the New I/O API. The chapters on XML and servlets have been rewritten to cover the latest versions of the specifications and to demonstrate best practices for Java 1.4. New and updated examples throughout the book demonstrate many other new Java features and APIs.

Java Examples in a Nutshell is a companion volume to Java in a Nutshell, Java Foundation Classes in a Nutshell, and Java Enterprise in a Nutshell. It picks up where those quick references leave off, providing a wealth of examples for both novices and experts. This book doesn't hold your hand; it simply delivers well-commented working examples with succinct explanations to help you learn and explore Java and its APIs.

Java Examples in a Nutshell contains examples that demonstrate:

  • Core APIs, including I/O, New I/O, threads, networking, security, serialization, and reflection
  • Desktop APIs, highlighting Swing GUIs, Java 2D graphics, preferences, printing, drag-and-drop, JavaBeans, applets, and sound
  • Enterprise APIs, including JDBC (database access), JAXP (XML parsing and transformation), Servlets 2.4, JSP 2.0 (JavaServer Pages), and RMI

The book begins with introductory examples demonstrating structured and object-oriented programming techniques for new Java programmers. A special index at the end of the book makes it easy to look up examples that use a particular Java class or accomplish a desired task. In between, each chapter includes exercises that challenge readers and suggest further avenues for exploration

Table of Contents

Preface

I. Learning Java

1. Java Basics
     Hello World
     FizzBuzz
     The Fibonacci Series
     Using Command-Line Arguments
     Echo in Reverse
     FizzBuzz Switched
     Computing Factorials
     Recursive Factorials
     Caching Factorials
     Computing Big Factorials
     Handling Exceptions
     Interactive Input
     Using a StringBuffer
     Sorting Numbers
     Computing Primes

2. Objects, Classes, and Interfaces
     A Rectangle Class
     Testing the Rect Class
     A Rect Subclass
     Another Subclass
     Complex Numbers
     Computing Statistics
     An Integer List
     Tokenizing Text

II. Core Java APIs

3. Input/Output
     Files and Streams
     Working with Files
     Copying File Contents
     Reading and Displaying Text Files
     Listing Directory and File Information
     Compressing Files and Directories
     Filtering Character Streams
     Tokenizing a Character Stream
     Random Access to Files

4. Threads
     Thread Basics
     Thread-Safe Classes
     Threads and Thread Groups
     Deadlock
     Timers

5. Networking
     Downloading the Contents of a URL
     Using a URLConnection
     Sending Email Through a URLConnection
     A Simple Network Client
     A Generic Client
     An HTTP Client
     A POP Client
     A Simple Web Server
     A Proxy Server
     A Generic Multithreaded Server
     Sending Datagrams
     Receiving Datagrams

6. New I/O
     Locking Files
     Copying Files
     Regular Expressions and Character Decoding
     File Copying with Buffers
     Advanced Byte-to-Character Conversion
     Tokenizing Byte Buffers
     A Simple HTTP Client
     The Daytime Service
     A Multiplexed Server
     A Multiplexed Network Client

7. Security and Cryptography
     Running Untrusted Code
     Loading Untrusted Code
     Message Digests and Digital Signatures
     Cryptography

8. Internationalization
     A Word About Locales
     Unicode
     Character Encodings
     Handling Local Customs
     Localizing User-Visible Messages
     Formatted Messages

9. Reflection
     Obtaining Class and Member Information
     Invoking a Named Method
     Proxy Objects

10. Object Serialization
     Simple Serialization
     Custom Serialization
     Externalizable Classes
     Serialization and Class Versioning

III. Desktop Java APIs

11. Graphical User Interfaces
     Components
     Containers
     Layout Management
     Event Handling
     A Complete GUI
     Actions and Reflection
     Custom Dialogs
     An Error Handler Dialog
     Displaying Tables
     Displaying Trees
     A Simple Web Browser
     Describing GUIs with Properties
     Themes and the Metal Look-and-Feel
     Look-and-Feel Preferences
     The ShowBean Program

12. Graphics
     Graphics Before Java 1.2
     The Java 2D API
     Drawing and Filling Shapes
     Transforms
     Line Styles with BasicStroke
     Stroking Lines
     Filling Shapes with Paint
     Antialiasing
     Combining Colors with AlphaComposite
     Image Processing
     Image I/O
     Custom Shapes
     Custom Strokes
     Custom Paint
     Advanced Animation
     Displaying Graphics Examples

13. Printing
     Printing with the Java 1.1 API
     Printing with the Java 1.2 API
     Printing with the Java 1.4 API
     Printing Multipage Text Documents
     Advanced Printing with Java 1.4

14. Data Transfer
     Simple Swing Data Transfer
     A Clock with Drag and Copy Support
     Data Transfer Architecture
     Dropping Multiple Datatypes
     A Transferable Shape
     Custom Data Transfer

15. JavaBeans
     Bean Basics
     A Simple Bean
     A More Complex Bean
     Custom Events
     Specifying Bean Information
     Defining a Simple Property Editor
     Defining a Complex Property Editor
     Defining a Bean Customizer
     Manipulating Beans

16. Applets
     Introduction to Applets
     A First Applet
     A Clock Applet
     A Timer Applet
     Applets and the Java 1.0 Event Model

17. Sound
     Ringing the Bell
     Swing Aural Cues
     Playing Sounds with AudioClip
     Playing Sounds with javax.sound
     Streaming Sounds with javax.sound
     Synthesizing a MIDI Sequence
     Real-Time MIDI Sounds

IV. Enterprise Java APIs

18. Database Access with SQL
     Accessing a Database
     Using Database Metadata
     Building a Database
     Using the API Database
     Atomic Transactions

19. XML
     Parsing with JAXP and SAX
     Parsing and Manipulating with JAXP and DOM
     Transforming XML with XSLT
     An XML Pull Parser

20. Servlets and JavaServer Pages
     Servlet Setup
     A Hello World Servlet
     Another Simple Servlet
     Servlet Initialization and Persistence: A Counter Servlet
     Hello JSP
     Hello JSP2
     Hello XML
     The MVC Paradigm for Web Applications
     ListManager Model Classes
     ListManager Controller
     ListManager Views
     Custom Tags in JSP 2.0
     Packaging a Web Application

21. Remote Method Invocation
     Remote Banking
     A Bank Server
     A Persistent Bank Server
     A Multiuser Domain
     Remote MUD Interfaces
     The MUD Server
     The MudPlace Class
     The MudPerson Class
     A MUD Client
     Advanced RMI

22. Example Index

Index

商品描述(中文翻譯)

最佳暢銷書《Java in a Nutshell》的作者創作了一本完整的真實世界 Java 程式設計範例書,讓你可以從中學習。如果你最擅長「透過範例學習」,那麼這本書就是為你而寫的。

這第三版涵蓋了 Java 1.4,並包含 193 個完整的實用範例:超過 21,900 行密集註解、專業編寫的 Java 代碼,涵蓋 20 種不同的客戶端和伺服器端 API。它包括有關 Java Sound API 和新 I/O API 的新章節。XML 和 Servlet 的章節已重新編寫,以涵蓋最新版本的規範並展示 Java 1.4 的最佳實踐。全書中的新範例和更新範例展示了許多其他新的 Java 特性和 API。

《Java Examples in a Nutshell》是《Java in a Nutshell》、《Java Foundation Classes in a Nutshell》和《Java Enterprise in a Nutshell》的伴隨卷。它接續那些快速參考的內容,為新手和專家提供了豐富的範例。本書不會手把手教你;它僅僅提供了註解良好的可運行範例,並附上簡潔的解釋,幫助你學習和探索 Java 及其 API。

《Java Examples in a Nutshell》包含展示以下內容的範例:
- 核心 API,包括 I/O、新 I/O、執行緒、網路、安全性、序列化和反射
- 桌面 API,重點介紹 Swing GUI、Java 2D 圖形、偏好設定、列印、拖放、JavaBeans、小應用程式和聲音
- 企業 API,包括 JDBC(資料庫存取)、JAXP(XML 解析和轉換)、Servlets 2.4、JSP 2.0(JavaServer Pages)和 RMI

本書以介紹範例開始,展示結構化和物件導向程式設計技術,適合新手 Java 程式設計師。書末的特別索引使查找使用特定 Java 類別或完成特定任務的範例變得簡單。在各章之間,每章都包含挑戰讀者的練習,並建議進一步探索的方向。

目錄
前言

I. 學習 Java
1. Java 基礎
- Hello World
- FizzBuzz
- Fibonacci 數列
- 使用命令列參數
- 反向回音
- FizzBuzz 交換
- 計算階乘
- 遞迴階乘
- 快取階乘
- 計算大階乘
- 處理例外
- 互動輸入
- 使用 StringBuffer
- 排序數字
- 計算質數

2. 物件、類別和介面
- 矩形類別
- 測試 Rect 類別
- Rect 子類別
- 另一個子類別
- 複數
- 計算統計
- 整數列表
- 文字標記化

II. 核心 Java API
3. 輸入/輸出
- 檔案和串流
- 操作檔案
- 複製檔案內容
- 讀取和顯示文字檔
- 列出目錄和檔案資訊
- 壓縮檔案和目錄
- 過濾字元串流
- 標記化字元串流
- 隨機存取檔案

4. 執行緒
- 執行緒基礎
- 執行緒安全類別
- 執行緒和執行緒群組
- 死鎖
- 計時器

5. 網路
- 下載 URL 的內容
- 使用 URLConnection
- 通過 URLConnection 發送電子郵件
- 簡單的網路客戶端
- 通用客戶端
- HTTP 客戶端
- POP 客戶端
- 簡單的網頁伺服器
- 代理伺服器
- 通用多執行緒伺服器
- 發送數據報
- 接收數據報

6. 新 I/O
- 鎖定檔案
- 複製檔案
- 正規表達式和字元解碼
- 使用緩衝區複製檔案
- 進階位元組到字元轉換
- 標記化位元組緩衝區
- 簡單的 HTTP 客戶端
- 日間服務
- 多路複用伺服器
- 多路複用網路客戶端

7. 安全性和密碼學
- 執行不受信任的代碼
- 載入不受信任的代碼
- 訊息摘要和數位簽章
- 密碼學

8. 國際化
- 關於地區的說明
- Unicode
- 字元編碼
- 處理當地習俗
- 本地化用戶可見訊息
- 格式化訊息

9. 反射
- 獲取類別和成員資訊
- 調用命名方法
- 代理物件

10. 物件序列化
- 簡單序列化
- 自定義序列化
- 可外部化類別
- 序列化和類別版本控制

III. 桌面 Java API
11. 圖形用戶介面
- 元件
- 容器
- 佈局管理
- 事件處理
- 完整的 GUI
- 動作和反射
- 自定義對話框
- 錯誤處理對話框
- 顯示表格
- 顯示樹狀結構
- 簡單的網頁瀏覽器
- 使用屬性描述 GUI
- 主題和金屬外觀
- 外觀偏好設定
- ShowBean 程式

12. 圖形
- Java 1.2 之前的圖形
- Java 2D API
- 繪製和填充形狀
- 變換
- 使用 BasicStroke 的線條樣式
- 描邊線條
- 使用顏料填充形狀
- 抗鋸齒
- 使用 AlphaComposite 組合顏色
- 圖像處理
- 圖像 I/O
- 自定義形狀
- 自定義描邊
- 自定義繪製
- 進階動畫
- 顯示圖形範例

13. 列印
- 使用 Java 1.1 API 列印
- 使用 Java 1.2 API 列印
- 使用 Java 1.4 API 列印
- 列印多頁文字文件
- 使用 Java 1.4 進行進階列印

14. 數據傳輸
- 簡單的 Swing 數據傳輸
- 支援拖放和複製的時鐘
- 數據傳輸架構
- 拖放多種數據類型
- 可傳輸的形狀
- 自定義數據傳輸

15. JavaBeans
- Bean 基礎
- 簡單的 Bean
- 更複雜的 Bean
- 自定義事件
- 指定 Bean 資訊
- 定義簡單的屬性編輯器
- 定義複雜的屬性編輯器
- 定義 Bean 自定義器
- 操作 Beans

16. 小應用程式
- 小應用程式介紹
- 第一個小應用程式
- 時鐘小應用程式
- 計時器小應用程式
- 小應用程式和 Java 1.0 事件模型

17. 聲音
- 鈴聲
- Swing 聲音提示
- 使用 AudioClip 播放聲音
- 使用 javax.sound 播放聲音
- 使用 javax.sound 串流聲音
- 合成 MIDI 序列
- 實時 MIDI 聲音

IV. 企業 Java API
18. 使用 SQL 的資料庫存取
- 存取資料庫
- 使用資料庫元資料
- 建立資料庫
- 使用 API 資料庫
- 原子交易

19. XML
- 使用 JAXP 和 SAX 解析
- 使用 JAXP 和 DOM 解析和操作
- 使用 XSLT 轉換 XML
- XML 拉取解析器

20. Servlets 和 JavaServer Pages
- Servlet 設定
- Hello World Servlet
- 另一個簡單的 Servlet
- Servlet 初始化和持久性:計數器 Servlet
- Hello JSP
- Hello JSP2
- Hello XML
- 網頁應用程式的 MVC 範式
- ListManager 模型類別
- ListManager 控制器
- ListManager 視圖
- JSP 2.0 中的自定義標籤
- 打包網頁應用程式

21. 遠端方法調用
- 遠端銀行
- 銀行伺服器
- 持久性銀行伺服器
- 多用戶域
- 遠端 MUD 介面
- MUD 伺服器
- MudPlace 類別
- MudPerson 類別
- MUD 客戶端
- 進階 RMI

22. 範例索引

索引