Effective Java(第2版)英文版

Effective Java(第2版)英文版

《Effective Java(第2版)英文版》是2016年4月電子工業出版社出版的圖書,作者是【美】Joshua Bloch(約書亞·布洛赫)。

基本介紹

  • 書名:Effective Java(第2版)英文版
  • 作者:【美】Joshua Bloch(約書亞·布洛赫)
  • ISBN:978-7-121-27314-8
  • 頁數:368
  • 定價:65.00元 
  • 出版社電子工業出版社
  • 出版時間:2016年4月
  • 開本:16
內容簡介,內容提要,目錄,精彩節摘,前言,

內容簡介

《Effective Java(第2版)英文版》介紹了在Java編程中的78條非常具有實用價值的經驗規則,這些經驗規則涵蓋了大部分開發人員每天所面臨的問題的解決方案。通過對Java平台設計專家所使用的技術的全面描述,揭示了應該做什麼,不應該做什麼,以及怎樣才能編寫出清晰、健壯和高效的代碼。《Effective Java(第2版)英文版》中的每條規則都以簡短、獨立的小文章形式出現,並通過示例代碼進一步進行說明。本書內容全面,結構清晰,講解詳細,可作為技術人員的參考用書。

內容提要

《Effective Java(第2版)英文版》介紹了在Java編程中的78條非常具有實用價值的經驗規則,這些經驗規則涵蓋了大部分開發人員每天所面臨的問題的解決方案。通過對Java平台設計專家所使用的技術的全面描述,揭示了應該做什麼,不應該做什麼,以及怎樣才能編寫出清晰、健壯和高效的代碼。《Effective Java(第2版)英文版》中的每條規則都以簡短、獨立的小文章形式出現,並通過示例代碼進一步進行說明。本書內容全面,結構清晰,講解詳細,可作為技術人員的參考用書。

目錄

推薦序
前言
1 Introduction
2 Creating and Destroying Objects
Item 1: Consider static factory methods instead of constructors
Item 2: Consider a builder when faced with many constructor parameters
Item 3: Enforce the singleton property with a private constructor or an enum type
Item 4: Enforce noninstantiability with a private constructor
Item 5: Avoid creating unnecessary objects
Item 6: Eliminate obsolete object references
Item 7: Avoid finalizers
3 Methods Common to All Objects
Item 8: Obey the general contract when overriding equals
Item 9: Always override hashCode when you override equals
Item 10: Always override toString
Item 11: Override clone judiciously
Item 12: Consider implementing Comparable
4 Classes and Interfaces
Item 13: Minimize the accessibility of classes and members
Item 14: In public classes, use accessor methods, not public fields
Item 15: Minimize mutability
Item 16: Favor composition over inheritance
Item 17: Design and document for inheritance or else prohibit it
Item 18: Prefer interfaces to abstract classes
Item 19: Use interfaces only to define types
Item 20: Prefer class hierarchies to tagged classes
Item 21: Use function objects to represent strategies
Item 22: Favor static member classes over nonstatic
5 Generics
Item 23: Don’t use raw types in new code
Item 24: Eliminate unchecked warnings
Item 25: Prefer lists to arrays
Item 26: Favor generic types
Item 27: Favor generic methods
Item 28: Use bounded wildcards to increase API flexibility
Item 29: Consider typesafe heterogeneous containers
6 Enums and Annotations
Item 30: Use enums instead of int constants
Item 31: Use instance fields instead of ordinals
Item 32: Use EnumSet instead of bit fields
Item 33: Use EnumMap instead of ordinal indexing
Item 34: Emulate extensible enums with interfaces
Item 35: Prefer annotations to naming patterns
Item 36: Consistently use the Override annotation
Item 37: Use marker interfaces to define types
7 Methods
Item 38: Check parameters for validity
Item 39: Make defensive copies when needed
Item 40: Design method signatures carefully
Item 41: Use overloading judiciously
Item 42: Use varargs judiciously
Item 43: Return empty arrays or collections, not nulls
Item 44: Write doc comments for all exposed API elements
8 General Programming
Item 45: Minimize the scope of local variables
Item 46: Prefer for-each loops to traditional for loops
Item 47: Know and use the libraries
Item 48: Avoid float and double if exact answers are required
Item 49: Prefer primitive types to boxed primitives
Item 50: Avoid strings where other types are more appropriate
Item 51: Beware the performance of string concatenation
Item 52: Refer to objects by their interfaces
Item 53: Prefer interfaces to reflection
Item 54: Use native methods judiciously
Item 55: Optimize judiciously
Item 56: Adhere to generally accepted naming conventions
9 Exceptions
Item 57: Use exceptions only for exceptional conditions
Item 58: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors
Item 59: Avoid unnecessary use of checked exceptions
Item 60: Favor the use of standard exceptions
Item 61: Throw exceptions appropriate to the abstraction
Item 62: Document all exceptions thrown by each method
Item 63: Include failure-capture information in detail messages
Item 64: Strive for failure atomicity
Item 65: Don’t ignore exceptions
10 Concurrency
Item 66: Synchronize access to shared mutable data
Item 67: Avoid excessive synchronization
Item 68: Prefer executors and tasks to threads
Item 69: Prefer concurrency utilities to wait and notify
Item 70: Document thread safety
Item 71: Use lazy initialization judiciously
Item 72: Don’t depend on the thread scheduler
Item 73: Avoid thread groups
11 Serialization
Item 74: Implement Serializable judiciously
Item 75: Consider using a custom serialized form
Item 76: Write readObject methods defensively
Item 77: For instance control, prefer enum types to readResolve
Item 78: Consider serialization proxies instead of serialized instances
Appendix: Items Corresponding to First Edition
References
Index

精彩節摘

推薦序
如果有同事對你說,“Spouse of me this night today manufactures the unusual meal in a home. You will join?”這時候你腦子裡可能會浮現出三件事情:同事在邀請你參加他的家庭晚宴,英語肯定不是你這位同事的母語,更多的則是滿腦子的疑惑。
如果你曾經學習過第二種語言,並且嘗試過在課堂之外使用這種語言,你就該知道有三件事情是必須掌握的:這門語言的結構如何(語法)、如何命名你想談論的事物(辭彙),以及如何以慣用和高效的方式來表達日常的事物(用法)。在課堂上大多只涉及到前面兩點,當你使出渾身解數想讓對方明白你的意思時,常常會發現當地人對你的表述忍俊不禁。
程式設計語言也是如此。你需要理解語言的核心:它是面向算法的,還是面向函式的,或者是面向對象的?你需要知道辭彙表:標準類庫提供了哪些數據結構、操作和功能設施(Facility)?你還需要熟悉如何用習慣和高效的方式來構建代碼。也許是因為前面兩點比較容易編寫,所以關於程式設計語言的書籍通常只涉及這兩點,或者只是蜻蜓點水般地介紹一下用法。語法和辭彙是語言本身固有的特性,但是用法則反映了使用這門語言的群體特徵。
例如,Java程式設計語言是一門支持單繼承的面向對象程式設計語言,在每個方法的內部,它都支持命令式的(面向語句的,Statement-Oriented)編碼風格。Java類庫提供了對圖形顯示、網路、分散式計算和安全性的支持。但是,如何把這門語言以最佳的方式運用到實踐中呢?
還有一點,程式與口頭的句子以及大多數書籍和雜誌都不同,它會隨著時間的推移而發生變化。僅僅編寫出能夠有效地工作並且能夠被別人理解的代碼往往是不夠的,我們還必須把代碼組織成易於修改的形式。針對某個任務可能會有10種不同的編碼方法,而在這10種編碼方法中,有7種編碼方法是笨拙的、低效的或者是難以理解的。而在剩下的3種編碼方法中,哪一種會是最接近該任務的下一年度發行版本的代碼呢?
本書解決了你的第三種需求,即如何以慣用和高效的方式來表達日常的事物(用法)。多年來,作者Joshua Bloch在Sun Microsystems公司一直從事Java語言的擴展、實現和使用的工作;他還大量地閱讀了其他人的代碼,包括我的代碼。他在本書中提出了許多很好的建議,他系統地把這些建議組織起來,旨在告訴讀者如何更好地構造代碼以便它們能工作得更好,也便於其他人能夠理解這些代碼,而且將來對代碼進行修改和改善時也不至於那么頭疼。甚至,你的程式也會因此而變得更加令人愉悅、更加優美和雅致。
Guy L. Steele Jr
Burlington, Massachusetts
2001年4月

前言

我於2001年寫了本書的第一版之後,Java平台又發生了很多變化,所以是該出第二版的時候了。Java 5中最為重要的變化是增加了泛型、枚舉類型、註解、自動裝箱和for-each循環。然後是增加了新的並發類庫:java.util.concurrent,並且在Java 5中進行了發布。我和Gilad Bracha一起,有幸帶領團隊設計了最新的語言特性,還參加了設計和開發並發類庫的團隊,這個團隊由Doug Lea領導。
Java平台中另一個大的變化在於廣泛採用了現代的IDE(Integrated Development Environment),例如Eclipse、IntelliJ IDEA和NetBeans,以及靜態分析工具的IDE,如FindBugs。雖然我未參與這部分工作,但已經從中受益匪淺,並且很清楚它們對Java開發體驗所帶來的影響。
2004年,我從Sun公司換到了Google公司,但在過去的4年中,我仍然繼續參與Java平台的開發,在Google公司和JCP(Java Community Process)的大力幫助下,繼續並發和集合API的開發。我還有幸利用Java平台去開發供Google內部使用的類庫。現在我了解了作為一名用戶的感受。
我在2001年編寫第一版的時候,主要目的是與讀者分享我的經驗,以便讓大家避免我所走過的彎路,幫助大家更容易地走向成功。第二版仍然大量採用來自Java平台類庫的真實範例。
第一版所帶來的反應遠遠超出了我最大的預期。我在收集所有新的資料以使本書保持最新時,儘可能地保持了資料的真實。毫無疑問,本書的篇幅肯定會增加,從57個條目發展到了78個。我不僅增加了23個條目,並且修改了原來的所有資料,並刪去了一些已經過時的條目。在附錄中,你可以看到本書內容與第一版內容的對照情況。
在第一版的前言中,我說過:Java程式設計語言和它的類庫非常有益於代碼質量和效率的提高,並且使得用Java進行編碼成為一種樂趣。Java 5和Java 6發行版本中的變化是好事,也使得Java平台日趨完善。現在這個平台比2001年的要大得多,也複雜得多,但是一旦掌握了使用新特性的模式和慣用模式,它們就會使你的程式變得更完美,使你的工作變得更輕鬆。我希望第二版能夠體現出我對Java平台持續的熱情,並將這種熱情傳遞給你,幫助你更加高效和愉快地使用Java平台及其新的特性。
San Jose, California
2008年4月

相關詞條

熱門詞條

聯絡我們