著 者:(美)Joshua Bloch(約書亞·布洛剋)
作 譯 者:Joshua Bloch(約書亞·布洛剋)
齣版時間:2018-06 韆 字 數:506
版 次:01-01 頁 數:404
開 本:16開
裝 幀:
I S B N :9787121342608
換 版:
所屬分類:科技 >> 計算機 >> 編程語言
紙質書定價:¥99.0
自從Java 6發布之後,Java又有瞭翻天覆地的變化。本書涵蓋瞭Java 7、Java 8和Java 9中語言和庫的各種新特性。讓你能夠深入瞭解Java平颱的細微之處。通過對每一個項目的全麵描述和解釋,告訴你應該做什麼、不應該做什麼,以及為什麼要這樣做。1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Creating and Destroying Objects . . . . . . . . . . . . . . . . . . . . . 5
Item 1: Consider static factory methods instead of constructors . . . 5
Item 2: Consider a builder when faced with many constructor parameters . .. . . . . . . . 10
Item 3: Enforce the singleton property with a private constructor or an enum type . . . . . . . . . . . . . . . 17
Item 4: Enforce noninstantiability with a private constructor . . . . 19
Item 5: Prefer dependency injection to hardwiring resources . . . . 20
Item 6: Avoid creating unnecessary objects . . . . . . . . . . . . . . . . . 22
Item 7: Eliminate obsolete object references . . . . . . . . . . . . . . . . . 26
Item 8: Avoid finalizers and cleaners . . . . . . . . . . . . . . . . . . . . . . 29
Item 9: Prefer try-with-resources to try-finally. . . . . . . . . . . . 34
3 Methods Common to All Objects . . . . . . . . . . . . . . . . . . . . 37
Item 10: Obey the general contract when overriding equals . . . . . 37
Item 11: Always override hashCode when you override equals . . 50
Item 12: Always override toString . . . . . . . . . . . . . . . . . . . . . . . . 55
Item 13: Override clone judiciously . . . . . . . . . . . . . . . . . . . . . . . . 58
Item 14: Consider implementing Comparable . . . . . . . . . . . . . . . . 66
4 Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Item 15: Minimize the accessibility of classes and members . . . . . 73
Item 16: In public classes, use accessor methods, not public fields 78
Item 17: Minimize mutability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Item 18: Favor composition over inheritance . . . . . . . . . . . . . . . . . 87
Item 19: Design and document for inheritance or else prohibit it 93
Item 20: Prefer interfaces to abstract classes . . . . . . . . . . . . . . . . . 99
Item 21: Design interfaces for posterity . . . . . . . . . . . . . . . . . . . . 104
Item 22: Use interfaces only to define types. . . . . . . . . . . . . . . . . 107
Item 23: Prefer class hierarchies to tagged classes . . . . . . . . . . . . 109
Item 24: Favor static member classes over nonstatic . . . . . . . . . . 112
Item 25: Limit source files to a single top-level class . . . . . . . . . 115
5 Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Item 26: Don’t use raw types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Item 27: Eliminate unchecked warnings. . . . . . . . . . . . . . . . . . . . 123
Item 28: Prefer lists to arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Item 29: Favor generic types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Item 30: Favor generic methods . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Item 31: Use bounded wildcards to increase API flexibility . . . . 139
Item 32: Combine generics and varargs judiciously. . . . . . . . . . . 146
Item 33: Consider typesafe heterogeneous containers . . . . . . . . . 151
6 Enums and Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Item 34: Use enums instead of int constants. . . . . . . . . . . . . . . . 157
Item 35: Use instance fields instead of ordinals . . . . . . . . . . . . . . 168
Item 36: Use EnumSet instead of bit fields . . . . . . . . . . . . . . . . . . 169
Item 37: Use EnumMap instead of ordinal indexing. . . . . . . . . . . . 171
Item 38: Emulate extensible enums with interfaces . . . . . . . . . . . 176
Item 39: Prefer annotations to naming patterns . . . . . . . . . . . . . . 180
Item 40: Consistently use the Override annotation. . . . . . . . . . . 188
Item 41: Use marker interfaces to define types . . . . . . . . . . . . . . 191
7 Lambdas and Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Item 42: Prefer lambdas to anonymous classes . . . . . . . . . . . . . . 193
Item 43: Prefer method references to lambdas . . . . . . . . . . . . . . . 197
Item 44: Favor the use of standard functional interfaces . . . . . . . 199
Item 45: Use streams judiciously . . . . . . . . . . . . . . . . . . . . . . . . . 203
Item 46: Prefer side-effect-free functions in streams . . . . . . . . . . 210
Item 47: Prefer Collection to Stream as a return type. . . . . . . . . . 216
Item 48: Use caution when making streams parallel . . . . . . . . . . 222
8 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Item 49: Check parameters for validity . . . . . . . . . . . . . . . . . . . . . 227
Item 50: Make defensive copies when needed . . . . . . . . . . . . . . . 231
Item 51: Design method signatures carefully . . . . . . . . . . . . . . . . 236
Item 52: Use overloading judiciously . . . . . . . . . . . . . . . . . . . . . . 238
Item 53: Use varargs judiciously . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Item 54: Return empty collections or arrays, not nulls . . . . . . . . . 247
Item 55: Return optionals judiciously . . . . . . . . . . . . . . . . . . . . . . 249
Item 56: Write doc comments for all exposed API elements . . . . 254
9 General Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Item 57: Minimize the scope of local variables . . . . . . . . . . . . . . . 261
Item 58: Prefer for-each loops to traditional for loops . . . . . . . . . 264
Item 59: Know and use the libraries . . . . . . . . . . . . . . . . . . . . . . . 267
Item 60: Avoid float and double if exact answers are required . 270
Item 61: Prefer primitive types to boxed primitives . . . . . . . . . . . 273
Item 62: Avoid strings where other types are more appropriate . . 276
Item 63: Beware the performance of string concatenation . . . . . . 279
Item 64: Refer to objects by their interfaces . . . . . . . . . . . . . . . . . 280
Item 65: Prefer interfaces to reflection . . . . . . . . . . . . . . . . . . . . . 282
Item 66: Use native methods judiciously. . . . . . . . . . . . . . . . . . . . 285
Item 67: Optimize judiciously . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Item 68: Adhere to generally accepted naming conventions . . . . . 289
10 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Item 69: Use exceptions only for exceptional conditions . . . . . . . 293
Item 70: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors . . 296
Item 71: Avoid unnecessary use of checked exceptions . . . . . . . . 298
Item 72: Favor the use of standard exceptions. . . . . . . . . . . . . . . . 300
Item 73: Throw exceptions appropriate to the abstraction. . . . . . . 302
Item 74: Document all exceptions thrown by each method. . . . . . 304
Item 75: Include failure-capture information in detail messages. . 306
Item 76: Strive for failure atomicity . . . . . . . . . . . . . . . . . . . . . . . 308
Item 77: Don’t ignore exceptions . . . . . . . . . . . . . . . . . . . . . . . . . 310
11 Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Item 78: Synchronize access to shared mutable data . . . . . . . . . . 311
Item 79: Avoid excessive synchronization . . . . . . . . . . . . . . . . . . 317
Item 80: Prefer executors, tasks, and streams to threads . . . . . . . 323
Item 81: Prefer concurrency utilities to wait and notify . . . . . . 325
Item 82: Document thread safety . . . . . . . . . . . . . . . . . . . . . . . . . 330
Item 83: Use lazy initialization judiciously . . . . . . . . . . . . . . . . . 333
Item 84: Don’t depend on the thread scheduler . . . . . . . . . . . . . . 336
12 Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Item 85: Prefer alternatives to Java serialization . . . . . . . . . . . . . 339
Item 86: Implement Serializable with great caution . . . . . . . . 343
Item 87: Consider using a custom serialized form . . . . . . . . . . . . 346
Item 88: Write readObject methods defensively . . . . . . . . . . . . 353
Item 89: For instance control, prefer enum types to readResolve . . . . . . . . . 359
Item 90: Consider serialization proxies instead of serialized instances . . . . . . . . . . 363
Items Corresponding to Second Edition . . . . . . . . . . . . . . . 367
References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Effective Java(第3版)(英文版)
Effective Java(第3版)(英文版)
這本《Effective Java》英文第三版,絕對是那些渴望在Java領域精益求精的開發者們的一份厚禮。它以一種非常直接且實用的方式,將Java語言的精髓展現在讀者麵前。我注意到書中強調瞭許多在日常開發中容易被忽視但卻至關重要的細節,例如如何正確地使用枚舉,如何高效地管理資源,以及如何設計齣易於理解和使用的API。這些看似微小的點,卻對代碼的質量、性能和可維護性有著舉足輕重的影響。這本書的英文原文本身就非常地道,充滿瞭技術深度,讀起來非常有力量。它不像某些翻譯的書籍那樣,可能因為語言的轉換而丟失瞭原有的韻味和精確性。我經常會翻閱書中的某個章節,當我遇到類似的編程場景時,這本書總能為我提供最專業、最可靠的解決方案。它讓我對Java的理解不僅僅停留在語法層麵,而是上升到瞭設計和工程實踐的高度。
評分說實話,一開始我有些猶豫是否要購買這本《Effective Java》英文第三版,畢竟市麵上Java相關的書籍琳琅滿目。但最終的決定是我最明智的選擇之一。這本書的英文錶達本身就極具專業性和簡潔性,配閤著作者對Java語言深刻的理解,使得每一頁都充滿瞭信息量。它不是那種可以快速翻閱的書籍,而是需要你坐下來,靜下心來,仔細品味每一個建議。我尤其對書中關於並行處理和響應式編程的部分印象深刻,這些都是現代Java開發中越來越重要的領域,而這本書則提供瞭一個非常紮實的基礎。它不僅教授瞭我技術上的知識,更重要的是,它培養瞭我一種“思考為什麼”的編程習慣,讓我不再滿足於簡單地實現功能,而是去思考如何實現得更好,如何避免潛在的問題。這本書的每一個章節都像是一次深入的剖析,讓我對Java的理解達到瞭一個新的高度。如果你真的想要在Java開發領域有所建樹,這本書絕對值得你投入時間和精力去鑽研。
評分這本《Effective Java》英文第三版,簡直是Java開發者的聖經。我一直在尋找一本能夠真正提升我Java編程技能的書籍,而這本恰恰滿足瞭我的需求。從剛開始拿到它的時候,我就被它精煉的語言和深刻的洞察力所吸引。書中的每一個“Effective”建議都經過深思熟慮,並輔以清晰的代碼示例,讓你不僅知道“是什麼”,更重要的是知道“為什麼”這樣做。它不像許多技術書籍那樣枯燥乏味,而是以一種對話式的、循序漸進的方式引導讀者深入理解Java的底層原理和最佳實踐。我特彆喜歡書中關於設計模式、並發編程和API設計的章節,這些內容對於我理解和編寫高質量、可維護的Java代碼至關重要。它幫助我糾正瞭很多之前可能認為是理所當然,但實際上存在隱患的編程習慣。每一次重讀,我都能從中發現新的閃光點,仿佛在與一位經驗豐富的導師交流。這本書的價值遠不止於一次閱讀,它更像是一本可以伴隨開發者整個職業生涯的工具書,幫助我們在不斷變化的Java生態係統中保持領先。
評分我必須說,《Effective Java》英文第三版是一本真正能夠改變你編程思維的書。在遇到它之前,我可能對Java的很多特性都有所瞭解,但總是停留在“知道”的層麵,而這本書則讓我上升到瞭“理解”和“掌握”的境界。作者對於Java語言的理解之深,以及他能夠將復雜的概念用如此清晰易懂的方式呈現齣來,實在令人驚嘆。這本書的結構安排也十分閤理,每一章都聚焦於一個特定的主題,並提供瞭 actionable advice,讓我可以直接運用到實際工作中。例如,書中關於泛型和注解的章節,讓我對這些強大的特性有瞭全新的認識,也學會瞭如何更有效地利用它們來編寫更健壯、更具錶達力的代碼。我尤其欣賞作者在書中強調的“麵嚮對象設計原則”以及如何避免常見的陷阱。它不僅僅是一本“如何做”的書,更是一本“為何如此做”的書,這對於建立紮實的編程功底至關重要。如果你想從一個普通的Java程序員蛻變為一個能夠寫齣優雅、高效、可維護代碼的資深開發者,那麼這本書絕對是你不可錯過的選擇。
評分《Effective Java》英文第三版,是一本能讓你在Java編程之路上少走彎路的神器。我一直認為,學習一門編程語言,最重要的是學習它的“道”而不是“術”,而這本書恰恰做到瞭這一點。它沒有羅列大堆的API或者語法點,而是通過一係列精心設計的“Item”,深入淺齣地剖析Java的哲學和最佳實踐。我特彆喜歡書中關於“選擇正確的集閤類”和“避免對象創建的開銷”等章節,這些內容直接關係到程序的性能,也是很多開發者容易忽略的地方。它教會我如何寫齣更高效、更優雅、更具可讀性的代碼。這本書的英文錶達清晰、邏輯嚴謹,讀起來是一種享受。每次閱讀,都感覺像是與一位經驗豐富的工程師進行瞭一場深刻的交流,學到瞭很多寶貴的經驗和技巧。它不僅僅是一本技術書籍,更像是一份來自Java社區的智慧結晶,能夠幫助你構建更健壯、更可靠的Java應用程序。
本站所有內容均為互聯網搜尋引擎提供的公開搜索信息,本站不存儲任何數據與內容,任何內容與數據均與本站無關,如有需要請聯繫相關搜索引擎包括但不限於百度,google,bing,sogou 等
© 2025 book.cndgn.com All Rights Reserved. 新城书站 版權所有