Java高手是怎樣煉成的:原理、方法與實踐

高永強 盧晨

  • 出版商: 清華大學
  • 出版日期: 2021-01-01
  • 售價: $708
  • 貴賓價: 9.5$673
  • 語言: 簡體中文
  • ISBN: 7302563845
  • ISBN-13: 9787302563846

立即出貨 (庫存 < 4)

  • Java高手是怎樣煉成的:原理、方法與實踐-preview-1
  • Java高手是怎樣煉成的:原理、方法與實踐-preview-2
  • Java高手是怎樣煉成的:原理、方法與實踐-preview-3
Java高手是怎樣煉成的:原理、方法與實踐-preview-1

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

相關主題

商品描述

《Java高手是怎樣煉成的:原理、方法與實踐》是作者20多年工作經驗的結晶。內容由淺入深,循序漸進,通過500多個簡單易懂、可運行的完整實例,幫助讀者理解Java編程的邏輯、概念及實操。本書內容豐富,講解接地氣,從理論到實踐,從基礎到高級,幫助讀者建立學習信心,在實踐中學會Java編程。 《Java高手是怎樣煉成的:原理、方法與實踐》分五部分,共23章。第一部分(第1~5章)主要介紹Java基本語法,包括Java語言概述和發展、編程和開發環境及設置等。第二部分(第6~9章)通過生動實例介紹類、對象、繼承、多態、內部類以及接口等Java編程概念和技術。第三部分(第10~15章)走進數組和字符串,深入講解它們的應用、異常處理,並深入討論更多面向對象技術。第四部分(第16~20章)介紹20多種GUI組件、字體、顏色、圖像以及音頻編程。第五部分(第21~23章)詳細講解數據流、文件I/O、數據庫編程以及網絡編程等。 《Java高手是怎樣煉成的:原理、方法與實踐》專為不同層次的Java程序員精心編寫,既適合編程初學者入門,又適合程序員進階,還可以作為高等院校講授面向對象程序設計語言以及Java語言的參考教材。

目錄大綱

目  錄

第一部分 新手上路

第1章 初識Java ·································2

1.1 什麽是Java ················································2

1.2 Java能做什麽 ············································3

1.3 Java軟件包 ················································3

1.3.1 什麽是Java SE ···································3

1.3.2 什麽是JDK ·········································4

1.4 為什麽Java可以在任何電腦上運行 ····4

1.5 Java和其他語言比較 ································4

1.5.1 Java和C++的比較 ····························5

1.5.2 Java和C#的比較 ······························5

1.6 為什麽學Java ············································5

1.6.1 新手常遇到的困難 ·····························5

1.6.2 為什麽選擇這本書 ·····························6

1.7 免費下載、安裝和測試學習Java需要的軟件 ············6

1.7.1 免費下載JDK軟件包 ························7

1.7.2 JDK的安裝步驟 ·································7

1.7.3 安裝成功我知道 ·································8

1.8 新手使用Java開發工具Eclipse ············10

1.8.1 什麽是IDE········································10

1.8.2 為什麽用Eclipse ······························10

1.8.3 免費下載、安裝和測試Eclipse ······11

1.8.4 新手須知Eclipse常用功能 ·············14

1.9 編寫和運行第一個Java程序 ·················17

1.10 什麽是Java API ······································19

鞏固提高練習和編程實踐 ·······························19

第2章 開始Java編程 ························20

2.1 一切從基礎開始 ······································20

2.1.1 Java語句 ···········································20

2.1.2 註釋,還是註釋 ·······························21

2.1.3 什麽是標識符和怎樣使用 ···············22

2.2 Java基本數據 ··········································23

2.2.1 8種基本數據類型 ····························23

2.2.2 如何定義變量 ···································24

2.2.3 什麽是變量初始化 ···························25

2.2.4 變量與存儲器有什麽關系 ···············26

2.2.5 常量必須初始化 ·······························27

2.3 賦值語句 ··················································27

2.3.1 算術表達式 ·······································27

2.3.2 快捷賦值操作符 ·······························29

2.4 初識字符串 ··············································30

2.4.1 菜鳥理解字符串 ·······························30

2.4.2 什麽是字符串引用 ···························31

2.4.3 如何實現字符串連接 ·······················31

2.4.4 如何處理特殊字符——轉義符 ·······33

2.5 初識數組 ··················································34

2.5.1 菜鳥理解數組 ···································34

2.5.2 一個例子教會你使用數組 ···············34

鞏固提高練習和編程實踐 ·······························35

第3章 新手須知類和對象 ····················37

3.1 初識類和對象 ··········································37

3.1.1 類到底是什麽 ···································37

3.1.2 對象又是什麽 ···································38

3.1.3 編寫你的第一個類 ···························38

3.1.4 創建你的第一個對象 ·······················40

3.1.5 怎樣調用方法 ···································41

3.1.6 怎樣測試自己編寫的類 ···················41

3.1.7 站在巨人的肩膀——使用API類 ············43

3.1.8 給程序帶來五彩繽紛——細說JOptionPane ·········45

3.2 學習更多輸入、輸出API類 ·················48

3.2.1 回到黑白——System.out ·················49

3.2.2 掃描輸入——Scanner ······················50

3.3 編寫用戶友好與人機互動程序 ··············52

實戰項目:里程轉換應用開發 ·······················53

鞏固提高練習和實戰項目大練兵 ···················55

第4章 走進控制語句 ··························57

4.1 條件表達式 ··············································57

4.1.1 關系表達式 ·······································57

4.1.2 比較基本型數據 ·······························58

4.1.3 比較字符串 ·······································59

4.2 邏輯表達式和應用 ··································61

4.2.1 邏輯表 ···············································61

4.2.2 復合表達式及運算次序 ···················61

4.2.3 你的程序邏輯清楚嗎 ·······················62

4.3 簡單if語句 ·············································63

4.4 簡單if-else語句 ······································65

4.5 嵌套if-else語句 ······································67

4.5.1 用多種格式編寫 ·······························67

4.5.2 應用實例 ···········································68

4.6 條件運算符?: ··········································69

4.7 多項選擇——switch語句 ······················69

4.7.1 典型switch語句格式 ·······················69

4.7.2 應用實例 ···········································71

4.7.3 JDK14新增的switch-case語句及其應用 ········72

4.8 你的程序需要繼續運行嗎——循環語句 ················72

4.8.1 走進while循環 ································72

4.8.2 走進do-while循環 ···························75

4.8.3 走進for循環·····································77

4.8.4 走進嵌套循環 ···································79

4.9 更多控制語句 ··········································81

4.9.1 break語句 ·········································81

4.9.2 continue語句 ····································82

實戰項目:投資回報應用開發(1) ···············83

鞏固提高練習和實戰項目大練兵 ···················86

第5章 數據控制和質量保證初探 ···········89

5.1 垃圾進、垃圾出——誓將錯誤消滅在開始 ··········89

5.2 Java的異常處理 ······································90

5.2.1 系統自動拋出的異常 ·······················90

5.2.2 初識try-catch ····································90

5.2.3 API標準異常類 ································92

5.2.4 怎樣處理系統自動拋出的異常 ·······92

5.2.5 為什麽需要拋出和處理異常 ···········93

5.2.6 異常處理應用實例 ···························95

5.3 格式化輸出控制 ······································98

5.3.1 貨幣輸出格式化 ·······························98

5.3.2 國際貨幣輸出格式化 ·······················99

5.3.3 百分比輸出格式化 ·························100

5.3.4 其他數值輸出格式化 ·····················101

5.3.5 利用DecimalFormat控制數值輸出格式化 ·······102

5.4 數據類型轉換 ········································102

5.4.1 自動類型轉換 ·································103

5.4.2 強制性類型轉換cast ······················103

5.5 怎樣利用Math類 ·································104

5.6 處理超值數字——BigDecimal類 ·······105

5.6.1 BigDecimal的數學運算 ·················106

5.6.2 BigDecimal的格式化輸出 ·············107

實戰項目:投資回報應用開發(2) ·············108

鞏固提高練習和實戰項目大練兵 ·················110

第二部分 告別菜鳥

第6章 走進類和對象 ·························114

6.1 面向對象編程——原來如此 ················114

6.1.1 類和對象剖析——源於生活,高於生活 ·········115

6.1.2 封裝性 ·············································115

6.1.3 繼承性 ·············································116

6.1.4 多態性 ·············································117

6.1.5 抽象性 ·············································117

6.2 類為什麽是編程模塊 ····························117

6.2.1 類就是軟件工廠產品藍圖 ·············117

6.2.2 如何描述對象——確定其屬性並賦值 ···········118

6.2.3 構造方法製造對象 ·························119

6.2.4 更靈活地製造對象——構造方法重載 ··············121

6.3 走進方法 ················································122

6.3.1 方法就是對象的具體操作 ·············122

6.3.2 什麽是傳遞值的參數和傳遞引用的參數 ············123

6.3.3 方法重載 ·········································125

6.3.4 this是什麽意思 ······························126

6.4 走進靜態數據 ········································129

6.4.1 屬於全體對象的數據就是靜態數據 ··················129

6.4.2 靜態數據是怎樣工作的 ·················130

6.4.3 應用靜態數據原則 ·························130

6.5 走進靜態方法 ········································131

6.5.1 有靜態數據就有靜態方法——此話有理 ···········131

6.5.2 靜態方法怎樣工作——不同於一般方法 ················132

6.5.3 為什麽要用靜態初始化程序塊 ·····133

6.6 我們喜歡再談對象 ································134

6.6.1 對象創建與對象引用 ·····················134

6.6.2 為什麽對象名重用 ·························135

6.6.3 方法鏈式調用就這麽簡單 ·············136

實戰項目:投資回報應用開發(3) ·············136

鞏固提高練習和實戰項目大練兵 ·················138

第7章 繼承 ·····································140

7.1 繼承就是吃現成飯 ································140

7.1.1 怎樣實現繼承——歸類分析 ·········141

7.1.2 怎樣確定繼承是否合理—— “是”和“有”關系 ············142

7.1.3 怎樣體現代碼重用 ·························142

7.1.4 繼承就是站在巨人肩膀上 ·············143

7.1.5 繼承好處多多,你都想到了嗎 ······143

7.1.6 繼承的局限性 ·································143

7.1.7 三種基本繼承類型 ·························143

7.2 實現繼承 ················································145

7.2.1 怎樣寫父類 ·····································145

7.2.2 怎樣寫子類 ·····································146

7.2.3 Like father like son——像爸爸就是兒子 ··············147

7.3 你想讓子類怎樣繼承——訪問修飾符再探 ··················148

7.4 更多繼承應用 ········································149

7.4.1 繼承中如何應用重載 ·····················149

7.4.2 一個實例教會你什麽是覆蓋 ·········150

7.4.3 一個實例教會你什麽是屏蔽 ·········151

7.4.4 細談萬類鼻祖Object和類中類——Class ·············152

7.5 抽象類 ····················································156

7.5.1 抽象類不能創建對象 ·····················156

7.5.2 抽象方法造就了抽象類 ·················156

7.6 最終類 ····················································158

7.6.1 最終類不能被繼承 ·························158

7.6.2 一個例子搞懂最終類 ·····················159

7.6.3 最終方法不能被覆蓋 ·····················159

7.6.4 最終參數的值不能改變 ·················159

7.6.5 所有這一切皆為提高執行速度 ·····159

實戰項目:幾何體面積和體積計算應用開發(1) ···········160

鞏固提高練習和實戰項目大練兵 ·················163

第8章 多態 ·····································165

8.1 我們每天都在用多態 ····························165

8.1.1 多態問題你註意到了嗎 ·················165

8.1.2 讓我們一起走進多態 ·····················166

8.2 實現多態 ················································168

8.2.1 父類提供多態方法和接口 ·············168

8.2.2 子類覆蓋多態方法或完善接口 ······169

8.2.3 一個例子讓你明白應用多態 ·········170

8.3 為什麽剖析方法綁定 ····························171

8.3.1 靜態綁定 ·········································171

8.3.2 動態綁定 ·········································171

8.3.3 綁定時如何處理方法調用 ·············171

8.4 高手特餐——invokespecial和invokevirtual ············172

實戰項目:幾何體面積和體積計算應用開發(2) ··············173

鞏固提高練習和實戰項目大練兵 ·················175

第9章 接口 ·····································177

9.1 接口就是沒有完成的類 ························177

9.1.1 接口只規定命名——如何完善由你 ················177

9.1.2 接口體現最高形式的抽象 ·············178

9.1.3 怎樣編寫接口 ·································179

9.1.4 用接口還是用抽象類 ·····················180

9.1.5 常用API接口 ·································181

9.2 實現接口 ················································181

9.2.1 實現接口就是完善接口中的方法 ···············181

9.2.2 利用接口可以實現多重繼承 ·········183

9.2.3 接口本身也可以繼承 ·····················186

9.2.4 接口也可以作為參數 ·····················187

9.3 應用接口的典型實例——Cloneable接口 ·············188

9.3.1 實現Cloneable接口 ·······················188

9.3.2 引用還是復制——看看這個例子就懂了 ··············189

9.3.3 復制還分深淺——怎麽回事 ·········189

9.3.4 應用實例——利用最高超類實現Cloneable接口 ············192

鞏固提高練習和實戰項目大練兵 ·················193

第三部分 Java提高

第10章 細談數組 ·····························196

10.1 為啥數組就是類 ··································196

10.1.1 理解數組是怎樣工作的 ···············196

10.1.2 創建數組就是創建數組對象 ·······197

10.1.3 揭開數組的內幕 ···························198

10.2 數組的操作 ··········································201

10.2.1 訪問數組成員 ·······························201

10.2.2 數組和循環總是閨蜜 ···················203

10.2.3 訪問數組成員的特殊循環 ···········203

10.2.4 用更多實例掌握數組的應用 ·······204

10.3 高手要掌握的更多數組技術 ··············205

10.3.1 多維數組 ·······································206

10.3.2 非規則多維數組 ···························208

10.3.3 怎樣把數組傳到方法 ···················208

10.3.4 怎樣在方法中返回數組 ···············210

10.4 API的Arrays類可以做些什麽 ··········211

10.4.1 常用方法 ·······································211

10.4.2 排序和搜索 ···································212

10.4.3 數組復制——避免菜鳥常犯的錯誤 ·················213

10.4.4 高手必須掌握的另一個API接口——Comparable ············215

實戰項目:在多級繼承中應用數組進行排序 ·····················216

鞏固提高練習和實戰項目大練兵 ·················218

第11章 為何要再談字符串 ·················220

11.1 為何字符串也是類 ······························220

11.1.1 什麽是字符串引用 ·······················220

11.1.2 什麽是字符串創建 ·······················221

11.1.3 字符串構造方法 ···························221

11.1.4 高手必須掌握的字符串方法 ·······222

11.2 API StringBuilder類 ····························225

11.2.1 字符串內容可變還是不可變 ·······225

11.2.2 StringBuilder的構造方法 ·············225

11.2.3 高手必須掌握的其他常用方法 ···············226

11.2.4 用實例學會StringBuilder應該很容易 ·················227

11.2.5 StringBuilder的大哥——StringBuffer類··················229

11.3 API StringTokenizer類——分解字符串·················229

11.3.1 token就是分解字符串的符號 ·····229

11.3.2 構造方法和其他常用方法 ···········230

11.3.3 用實例學會StringTokenizer ·········231

11.4 正則表達式 ··········································231

11.4.1 高手必須知道的正則表達式 ·······231

11.4.2 正則表達式規則 ···························232

11.4.3 不再是秘密——String中處理正則表達式的方法 ·············234

11.4.4 揭開Pattern和Matcher類的面紗 ·····················234

11.4.5 驗證身份不是難事——實例說明一切 ·······························236

實戰項目:計算器模擬應用開發(1) ·········237

鞏固提高練習和實戰項目大練兵 ·················239

第12章 揭秘異常處理 ·······················241

12.1 高手必須懂的API異常處理類 ·········241

12.2 非檢查性異常 ······································242

12.2.1 出錯第一現場在哪裡 ···················242

12.2.2 高手為什麽要處理非檢查性異常 ·····················242

12.3 檢查性異常 ··········································243

12.3.1 同樣要分析出錯第一現場 ···········243

12.3.2 處理常見檢查性異常——必須 ························243

12.4 高手掌握異常處理機制 ······················243

12.4.1 傳統機制 ·······································244

12.4.2 高手為何要知道異常是怎樣在程序中傳播的 ·················246

12.4.3 怎樣獲取更多異常信息 ···············247

12.4.4 用實例解釋最直觀易懂 ···············248

12.5 高手應用throw直接拋出異常 ··········250

12.5.1 JVM怎樣自動拋出異常 ··············251

12.5.2 你也可以直接拋出異常 ···············251

12.5.3 你還可以重拋異常 ·······················252

12.6 嵌套異常處理 ······································253

12.6.1 什麽是異常機制嵌套方式 ···········253

12.6.2 嵌套異常是怎樣傳播的 ···············254

12.6.3 為什麽討論嵌套異常重拋 ···········255

12.7 高手自己定義異常類 ··························256

12.7.1 編寫自定義異常類原來如此簡單 ··························256

12.7.2 高手掌握的自定義異常處理技巧 ···························257

12.7.3 用實例解釋最直接易懂 ···············258

12.8 異常鏈是什麽 ······································259

12.8.1 異常處理信息不見了——什麽情況 ························259

12.8.2 應用異常鏈保證不會丟失處理信息 ·······················259

12.9 斷言——高手可以斷言可能發生的錯誤——assert ···················261

12.9.1 如何編寫斷言 ·······························261

12.9.2 開啟和關閉斷言 ···························262

實戰項目:利用異常處理機制開發你的數據驗證類 ··················263

鞏固提高練習和實戰項目大練兵 ·················265

第13章 高手掌握更多OOP技術 ·········266

13.1 創建自己的API包 ·····························266

13.1.1 包有哪些命名規範 ·······················267

13.1.2 創建包文件 ···································267

13.1.3 引入包文件 ···································268

13.2 用Eclipse的包管理項目中的文件 ······269

13.3 在Eclipse中創建文件庫 ····················270

13.3.1 什麽是JAR文件 ··························270

13.3.2 創建文件庫 ···································270

13.4 揭秘訪問權 ··········································271

13.5 類的更多應用——你知多少 ··············273

13.5.1 類之間的關系——父子、部下還是親戚 ·····················273

13.5.2 什麽是文件類 ·······························274

13.5.3 內部類怎樣用 ·······························274

13.5.4 為什麽用靜態內部類 ···················276

13.5.5 本地類是什麽 ·······························278

13.5.6 沒有名字的類——匿名類 ···········279

13.5.7 這麽多類——高手攻略 ···············279

13.6 枚舉類是什麽 ······································280

13.6.1 怎樣定義和使用枚舉 ···················280

13.6.2 靜態引入——編寫枚舉類更方便 ························282

13.6.3 高手必須知道的枚舉 ···················283

13.6.4 一個實例教會你應用枚舉 ···········285

13.7 高手須知可變參數 ······························286

13.7.1 可變參數是重載的極致應用 ·······286

13.7.2 揭秘可變參數——它怎樣工作 ···287

13.7.3 可變參數方法可以重載 ···············288

13.8 什麽是javadoc和怎樣用它 ···············288

實戰項目:創建可被任何程序調用的文件庫(JDK9和以後版本) ·················290

鞏固提高練習和實戰項目大練兵 ·················292

第14章 高手須知集合類 ····················293

14.1 用集合類做些什麽 ······························293

14.1.1 集合類與數組的比較 ···················294

14.1.2 集合類都有哪些 ···························294

14.1.3 什麽是Java的泛類型 ··················296

14.1.4 高手怎樣應用泛類型 ···················301

14.1.5 值得註意的類型安全問題 ···········303

14.2 揭秘集合類 ··········································304

14.2.1 可改變大小的數組 ·······················304

14.2.2 鏈接表 ···········································306

14.2.3 哈希集合 ·······································307

14.2.4 元素迭代器 ···································308

14.2.5 用實例教會你集合類應用 ···········309

14.3 Map的集合類 ·····································311

14.3.1 怎樣使用HashMap ·······················311

14.3.2 怎樣使用TreeMap ························312

14.3.3 怎樣對自定義類型TreeMap排序 ·····················314

14.4 集合類和數據結構 ······························315

14.4.1 堆棧 ···············································315

14.4.2 隊列 ···············································315

14.4.3 細說集合中的排序 ·······················316

14.4.4 搜索——我要找到你 ···················318

14.4.5 洗牌——想玩鬥地主 ···················319

14.4.6 集合類應用總結 ···························320

14.4.7 高手理解集合類的同步與不同步 ······················321

實戰項目:利用HashMap開發產品管理應用 ························321

鞏固提高練習和實戰項目大練兵 ·················323

第15章 多線程 ································325

15.1 Java的本質是多線程 ··························325

15.1.1 揭秘多線程怎樣工作 ···················325

15.1.2 多任務和多處理是一回事嗎 ·······326

15.1.3 多線程應用範圍太廣泛了 ···········326

15.1.4 一張圖搞懂線程的5種狀態 ·······327

15.1.5 你的第一個多線程程序 ···············327

15.2 如何創建多線程 ··································329

15.2.1 可以繼承Thread創建線程 ··········329

15.2.2 可以完善Runnable接口來創建線程 ·························330

15.2.3 多線程典型案例:生產-消費線程初探·······················331

15.3 多線程控制 ··········································333

15.3.1 設置優先級——setPriority方法 ·························333

15.3.2 給其他線程讓步——yield方法 ···············································334

15.3.3 讓我的線程休息——sleep方法 ···············································334

15.3.4 讓我的線程加入執行——join方法 ·········································336

15.3.5 打斷我的線程運行——interrupt方法 ···································336

15.3.6 應用實例——線程和數組哪個運行的快 ······························337

15.4 高手必知多線程協調 ··························339

15.4.1 什麽是多線程協調 ·······················339

15.4.2 高手怎樣實現多線程協調 ···········340

15.4.3 什麽是易變數據——volatile ·······340

15.4.4 你的多線程協調嗎——synchronized ··································340

15.4.5 要協調必須等待——wait方法 ·······342

15.4.6 你的線程協調得到通知了嗎——notify或notifyAll ·························343

15.5 高手須知更多多線程 ··························344

15.5.1 一張圖看懂監視器和線程鎖定 ·······344

15.5.2 更多多線程實戰術語和編程技巧 ····························345

15.5.3 並行類包——java.util. concurrent ······················346

實戰項目:利用多線程和並行處理開發生產-消費應用 ···············349

鞏固提高練習和實戰項目大練兵 ·················352

第四部分 GUI和多媒體編程

第16章 GUI——使你的窗口出彩 ········356

16.1 從一個典型例子看懂GUI組件 ·········356

16.1.1 Swing包中的組件從哪裡來 ········357

16.1.2 一張圖看懂組件的繼承關系 ·······357

16.1.3 組件操作功能從Component繼承而來 ····················358

16.2 創建框架就是實例窗口 ······················358

16.2.1 怎樣顯示創建的窗口 ···················358

16.2.2 怎樣關閉顯示的窗口 ···················359

16.2.3 窗口位置和大小控制 ···················360

16.2.4 在屏幕中央顯示窗口實例 ···········361

16.3 用控制面板管理組件——JPanel ·······362

16.3.1 一個例子搞懂控制面板怎樣管理組件 ························362

16.3.2 手把手教會你組件編程步驟 ·······362

16.3.3 揭秘控制面板結構內幕 ···············363

16.4 怎樣創建按鈕——JButton ·················364

16.4.1 創建按鈕舉例 ·······························364

16.4.2 把組件顯示到默認位置——FlowLayout ····································366

16.4.3 按下按鈕要做什麽——按鈕事件處理 ······································367

16.5 標簽和文本字段是閨蜜 ······················368

16.5.1 怎樣編寫標簽——JLabel·············368

16.5.2 怎樣編寫文本字段—— JTextField ······································369

16.5.3 怎樣處理文本字段事件 ···············370

16.5.4 我想讓用戶輸入密碼——JPasswordField ··························372

16.5.5 應用實例——學會這些組件編程 ·········································372

16.6 文本窗口的創建和應用——JTextArea ····································374

16.6.1 文本窗口的創建和方法調用 ·······374

16.6.2 在文本窗口中設置滾動面板——JScrollPane ····················375

16.6.3 應用編程實例 ·······························375

16.7 選項框——JCheckBox ·······················376

16.7.1 選項框事件處理 ···························377

16.7.2 應用編程實例 ·······························378

16.8 單選按鈕——JRadioButton ················380

16.8.1 單選按鈕事件處理 ·······················381

16.8.2 應用編程實例 ·······························381

鞏固提高練習和實戰項目大練兵 ·················384

第17章 GUI組件佈局——安排組件位置和顯示風格 ··················385

17.1 Java的6種佈局管理類 ······················385

17.2 系統預設的流程佈局——FlowLayout ·········································386

17.2.1 3種顯示位置 ································386

17.2.2 編程實例 ·······································386

17.3 圍界佈局管理類——BorderLayout ·······387

17.3.1 5種佈局區域 ································388

17.3.2 高手常用佈局嵌套 ·······················389

17.3.3 如何動態顯示按鈕的位置 ···········389

17.4 給組件加上5種不同風格的邊框 ······390

17.4.1 邊框BorderFactory設計編程步驟 ···············································391

17.4.2 編程實例 ·······································392

17.5 標記板——JTabbedPane ·····················393

17.5.1 如何應用標記板 ···························393

17.5.2 編程實例 ·······································394

17.6 箱式佈局BoxLayout和網格佈局GridLayout ·································396

17.6.1 如何應用箱式佈局管理 ···············396

17.6.2 如何應用網格佈局管理 ···············397

17.6.3 嵌套使用才更靈活 ·······················398

實戰項目:計算器模擬應用開發(2) ·········399

17.7 高手要掌握的最強佈局管理GridBagLayout ·····································400

17.7.1 必須使用設計圖——方法和步驟 ···············································401

17.7.2 編程實例 ·······································402

17.8 用戶接口管理——UIManager可以做啥 ·························404

17.8.1 常用用戶接口管理UIManager ····································405

17.8.2 編程實例 ·······································405

實戰項目:開發西方快餐銷售調查應用(1) ·························406

鞏固提高練習和實戰項目大練兵 ·················407

第18章 更多組件和事件處理 ··············409

18.1 下拉列表——JComboBox ··················409

18.1.1 編程實例 ·······································410

18.1.2 事件處理 ·······································411

18.1.3 ItemListener事件處理接口 ··········411

18.1.4 我怎麽用它——編程實例 ···········413

18.2 列表——JList ······································416

18.2.1 編程實例 ·······································417

18.2.2 ListSelectionListener事件處理接口 ································418

18.2.3 列表的更多編程技巧 ···················419

實戰項目:利用列表開發名詞學習記憶應用 ···································421

18.3 菜單——JMenu ···································422

18.3.1 菜單編寫步驟 ·······························422

18.3.2 編程舉例 ·······································423

18.3.3 如何加入子菜單 ···························423

18.3.4 菜單的事件處理 ···························424

18.3.5 設置鍵盤助記——高手才會這樣做 ······················424

18.3.6 高手設置快捷鍵 ···························425

18.3.7 MenuListener處理菜單事件接口 ································426

實戰項目:開發西方快餐銷售調查應用(2) ······················428

18.4 高手須知彈出式菜單 ··························431

18.4.1 一步步教會你編寫步驟 ···············431

18.4.2 編程實例 ·······································431

18.4.3 PopupMenuListener事件處理接口 ··························433

18.4.4 鼠標右鍵激活彈出式菜單 ···········433

實戰項目:開發西方快餐銷售調查應用(3) ··························434

18.5 高手應掌握更多GUI組件 ·················435

18.5.1 如何應用滑塊——JSlider ············436

18.5.2 如何應用進度條——JProgressBar ··································438

18.5.3 如何應用文件選擇器——JFileChooser ··································439

18.5.4 如何應用顏色選擇器——JColorChooser ·······························441

18.5.5 如何應用製表——JTable ·············442

18.5.6 如何應用樹——JTree ··················443

18.5.7 如何應用桌面板——JDesktopPane·································446

鞏固提高練習和實戰項目大練兵 ·················447

第19章 揭秘事件處理那些事兒 ···········449

19.1 高手須知事件處理內幕 ······················449

19.1.1 事件處理是怎樣工作的 ···············449

19.1.2 常用事件處理接口 ·······················451

19.1.3 為何要用適配器 ···························452

19.1.4 適配器應用實例 ···························453

19.2 高手必知鼠標事件處理 ······················454

19.2.1 都有哪些鼠標事件 ·······················454

19.2.2 鼠標事件處理接口和適配器 ·······454

19.2.3 鼠標事件處理演示程序 ···············454

19.3 高手須知鍵盤事件處理 ······················455

19.3.1 鍵盤事件處理接口和適配器 ·······456

19.3.2 鍵盤事件處理常用方法 ···············456

19.4 高手掌握的GUI組件編程技巧 ·········457

19.4.1 組件編程的6種方式 ···················457

19.4.2 事件處理的6種方式 ···················461

實戰項目:計算器模擬應用開發(3) ·········463

鞏固提高練習和實戰項目大練兵 ·················465

第20章 多媒體編程——高手須知的那些事兒 ·············467

20.1 字體編程 ··············································467

20.1.1 字體編程常用術語 ·······················467

20.1.2 字體編程常用方法和舉例 ···········468

20.1.3 應用實例學會字體編程 ···············469

20.2 顏色編程 ··············································470

20.2.1 顏色編程常用術語 ·······················471

20.2.2 顏色編程常用方法和舉例 ···········471

20.2.3 應用實例學會顏色編程 ···············472

20.3 JavaFX圖形編程 ·································473

20.3.1 JavaFX編程步驟 ··························473

20.3.2 圖形編程常用方法 ·······················474

20.3.3 圖形編程步驟 ·······························474

20.3.4 應用實例學會圖形編程 ···············475

20.4 JavaFX圖像編程 ·································476

20.4.1 Java支持的4種圖像格式 ···········476

20.4.2 圖像編程常用方法 ·······················476

20.4.3 圖像編程步驟 ·······························477

20.4.4 應用實例學會圖像編程 ···············477

20.5 JavaFX音頻編程 ·································478

20.5.1 Java支持的3種音頻格式 ···········478

20.5.2 音頻編程常用方法 ·······················478

20.5.3 音頻編程步驟 ·······························479

20.5.4 播放音樂編程實例 ·······················479

實戰項目:利用多媒體開發英文字母學習游戲應用 ·················480

鞏固提高練習和實戰項目大練兵 ·················483

第五部分 高手進階——數據流處理和編程

第21章 文件I/O ······························486

21.1 數據流和文件 ······································486

21.1.1 文件I/O基本知識須知 ················487

21.1.2 揭秘文件路徑 ·······························487

21.1.3 用實例看懂絕對路徑和規範路徑 ···················488

21.1.4 高手理解URI、URL和URN ······488

21.1.5 文件類常用方法 ···························488

21.1.6 文件I/O中為什麽要緩沖 ············492

21.1.7 文件I/O必須處理異常 ················492

21.2 文本文件I/O ·······································492

21.2.1 文本文件輸出 ·······························493

21.2.2 緩沖和無緩沖的文本輸出 ···········493

21.2.3 文本文件輸入 ·······························495

21.2.4 文本文件輸入實例 ·······················496

實戰項目:開發產品銷售文本文件管理應用 ··················498

21.3 二進制文件I/O ···································502

21.3.1 二進制文件的輸出 ·······················502

21.3.2 二進制文件輸出舉例 ···················503

21.3.3 二進制文件的輸入 ·······················504

21.3.4 二進制文件輸入實例 ···················505

實戰項目:開發產品銷售二進制文件管理應用 ··············507

21.4 高手須知對象序列化I/O ···················510

21.4.1 你的對象序列化了嗎 ···················510

21.4.2 手把手教會你對象序列化 ···········511

21.4.3 對象序列化常用類和方法 ···········511

21.4.4 對象序列化編程步驟 ···················511

實戰項目:利用對象序列化開發產品銷售文件管理應用 ···················512

21.5 隨機文件I/O ·······································517

21.5.1 隨機文件I/O常用方法和訪問模式 ····················517

21.5.2 文件記錄和位置計算 ···················518

21.5.3 用實例學會隨機文件I/O ·············518

21.6 高手須知更多文件I/O編程技術 ······520

21.6.1 細談JFileChooser ·························520

21.6.2 Java支持的壓縮文件I/O ·············521

21.6.3 一步步教會你壓縮文件I/O ·········521

21.6.4 用Scanner讀入文件 ····················527

實戰項目:開發產品銷售隨機文件管理應用 ············528

鞏固提高練習和實戰項目大練兵 ·················534

第22章 數據庫編程 ··························536

22.1 揭秘JDBC ···········································536

22.2 數據庫基本知識 ··································537

22.3 數據庫語言——SQL ··························538

22.3.1 SQL的6種基本指令 ···················538

22.3.2 SQL的基本數據類型 ···················538

22.3.3 創建指令——CREATE ················539

22.3.4 選擇指令——SELECT ·················539

22.3.5 更新指令——UPDATE ················540

22.3.6 插入指令——INSERT ·················540

22.3.7 刪除記錄指令——DELETE ········540

22.3.8 刪除數據表指令——DROP ·········541

22.4 數據庫和JDBC驅動軟件的安裝及測試 ·············541

22.4.1 下載數據庫軟件 ···························541

22.4.2 數據庫安裝 ···································541

22.4.3 數據庫運行測試 ···························542

22.4.4 下載JDBC驅動軟件 ···················543

22.4.5 一步步教會你在Eclipse中連接數據庫 ··········544

22.4.6 一個實例搞懂JDBC是否連接成功 ············545

22.4.7 編寫第一個數據庫程序 ···············545

22.5 Java程序和數據庫對話 ······················547

22.5.1 連接數據庫——高手都會這樣做 ················547

22.5.2 向數據庫發送SQL指令 ··············548

22.5.3 接收從數據庫傳回的記錄 ···········549

22.5.4 提取和更新傳回的記錄 ···············550

22.5.5 預備指令是怎麽回事 ···················551

實戰項目:利用數據庫和GUI開發產品銷售管理應用(1) ··············553

22.6 高手瞭解更多JDBC編程 ··················558

22.6.1 細談元數據是啥和怎樣用 ···········558

22.6.2 什麽是事務處理和怎樣實現 ·······559

22.6.3 三個步驟兩個實例搞懂事務處理編程 ·····················559

實戰項目:利用數據庫和GUI開發產品銷售管理應用(2) ················560

鞏固提高練習和實戰項目大練兵 ·················564

第23章 網絡編程 ·····························565

23.1 為什麽高手必知網絡編程 ··················565

23.1.1 必須遵循通信協議 ·······················565

23.1.2 URL和IP地址是一回事嗎 ·········566

23.1.3 URL和URI ··································566

23.1.4 埠和通信號 ·······························567

23.1.5 一張表看懂埠分配 ···················567

23.1.6 揭秘HTTP ····································568

23.1.7 URL和URLConnection編程實例 ························569

23.2 一步步教會你網絡編程 ······················570

23.2.1 細談Socket ···································570

23.2.2 Stream Sockets和Datagram Sockets ·····················571

23.2.3 用戶-服務器編程步驟 ················571

23.2.4 一個代碼實例教會你用戶-服務器編程 ·························571

23.2.5 單用戶-服務器程序測試運行步驟 ··························574

23.2.6 手把手教你DatagramSocket用戶-服務器編程 ············574

23.3 煉成網絡編程高手從這里起步 ··········578

23.3.1 手把手教你Socket多用戶-服務器編程 ·············578

23.3.2 多用戶-服務器程序測試運行步驟 ·······················580

23.3.3 手把手教你Datagram多用戶-服務器編程 ·························581

23.3.4 多用戶-服務器數據庫編程 ········583

實戰項目:開發多用戶-服務器產品銷售數據庫管理應用 ··············584

23.4 高手必會的高級網絡編程 ··················590

23.4.1 面向連接傳輸與面向傳輸連接 ···························590

23.4.2 怎樣設置Socket超時控制 ··········591

23.4.3 揭秘Socket中斷技術 ··················592

23.4.4 揭秘Socket半關閉技術 ··············593

23.4.5 揭秘java.nio ·································593

23.4.6 數據流和數據塊——網絡編程用哪個 ····················594

23.4.7 數據塊編程需要通道技術——Channel ··························594

23.4.8 一步步教會你通道技術網絡編程 ························594

23.4.9 應用緩沖的通道編程技術 ···········595

23.4.10 數據塊中字符集的定義、編碼和解碼 ····················596

23.4.11 應用選擇器Selector實現多用戶-服務器編程 ··················597

23.4.12 一步步教會你選擇器多用戶-服務器編程 ··················597

23.4.13 通道和選擇器編程實例 ·············598

實戰項目:開發多用戶-服務器聊天室應用 ························602

鞏固提高練習和實戰項目大練兵 ·················606