著 者:(美)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编程技能的书籍,而这本恰恰满足了我的需求。从刚开始拿到它的时候,我就被它精炼的语言和深刻的洞察力所吸引。书中的每一个“Effective”建议都经过深思熟虑,并辅以清晰的代码示例,让你不仅知道“是什么”,更重要的是知道“为什么”这样做。它不像许多技术书籍那样枯燥乏味,而是以一种对话式的、循序渐进的方式引导读者深入理解Java的底层原理和最佳实践。我特别喜欢书中关于设计模式、并发编程和API设计的章节,这些内容对于我理解和编写高质量、可维护的Java代码至关重要。它帮助我纠正了很多之前可能认为是理所当然,但实际上存在隐患的编程习惯。每一次重读,我都能从中发现新的闪光点,仿佛在与一位经验丰富的导师交流。这本书的价值远不止于一次阅读,它更像是一本可以伴随开发者整个职业生涯的工具书,帮助我们在不断变化的Java生态系统中保持领先。
评分这本《Effective Java》英文第三版,绝对是那些渴望在Java领域精益求精的开发者们的一份厚礼。它以一种非常直接且实用的方式,将Java语言的精髓展现在读者面前。我注意到书中强调了许多在日常开发中容易被忽视但却至关重要的细节,例如如何正确地使用枚举,如何高效地管理资源,以及如何设计出易于理解和使用的API。这些看似微小的点,却对代码的质量、性能和可维护性有着举足轻重的影响。这本书的英文原文本身就非常地道,充满了技术深度,读起来非常有力量。它不像某些翻译的书籍那样,可能因为语言的转换而丢失了原有的韵味和精确性。我经常会翻阅书中的某个章节,当我遇到类似的编程场景时,这本书总能为我提供最专业、最可靠的解决方案。它让我对Java的理解不仅仅停留在语法层面,而是上升到了设计和工程实践的高度。
评分我必须说,《Effective Java》英文第三版是一本真正能够改变你编程思维的书。在遇到它之前,我可能对Java的很多特性都有所了解,但总是停留在“知道”的层面,而这本书则让我上升到了“理解”和“掌握”的境界。作者对于Java语言的理解之深,以及他能够将复杂的概念用如此清晰易懂的方式呈现出来,实在令人惊叹。这本书的结构安排也十分合理,每一章都聚焦于一个特定的主题,并提供了 actionable advice,让我可以直接运用到实际工作中。例如,书中关于泛型和注解的章节,让我对这些强大的特性有了全新的认识,也学会了如何更有效地利用它们来编写更健壮、更具表达力的代码。我尤其欣赏作者在书中强调的“面向对象设计原则”以及如何避免常见的陷阱。它不仅仅是一本“如何做”的书,更是一本“为何如此做”的书,这对于建立扎实的编程功底至关重要。如果你想从一个普通的Java程序员蜕变为一个能够写出优雅、高效、可维护代码的资深开发者,那么这本书绝对是你不可错过的选择。
评分说实话,一开始我有些犹豫是否要购买这本《Effective Java》英文第三版,毕竟市面上Java相关的书籍琳琅满目。但最终的决定是我最明智的选择之一。这本书的英文表达本身就极具专业性和简洁性,配合着作者对Java语言深刻的理解,使得每一页都充满了信息量。它不是那种可以快速翻阅的书籍,而是需要你坐下来,静下心来,仔细品味每一个建议。我尤其对书中关于并行处理和响应式编程的部分印象深刻,这些都是现代Java开发中越来越重要的领域,而这本书则提供了一个非常扎实的基础。它不仅教授了我技术上的知识,更重要的是,它培养了我一种“思考为什么”的编程习惯,让我不再满足于简单地实现功能,而是去思考如何实现得更好,如何避免潜在的问题。这本书的每一个章节都像是一次深入的剖析,让我对Java的理解达到了一个新的高度。如果你真的想要在Java开发领域有所建树,这本书绝对值得你投入时间和精力去钻研。
评分《Effective Java》英文第三版,是一本能让你在Java编程之路上少走弯路的神器。我一直认为,学习一门编程语言,最重要的是学习它的“道”而不是“术”,而这本书恰恰做到了这一点。它没有罗列大堆的API或者语法点,而是通过一系列精心设计的“Item”,深入浅出地剖析Java的哲学和最佳实践。我特别喜欢书中关于“选择正确的集合类”和“避免对象创建的开销”等章节,这些内容直接关系到程序的性能,也是很多开发者容易忽略的地方。它教会我如何写出更高效、更优雅、更具可读性的代码。这本书的英文表达清晰、逻辑严谨,读起来是一种享受。每次阅读,都感觉像是与一位经验丰富的工程师进行了一场深刻的交流,学到了很多宝贵的经验和技巧。它不仅仅是一本技术书籍,更像是一份来自Java社区的智慧结晶,能够帮助你构建更健壮、更可靠的Java应用程序。
本站所有内容均为互联网搜索引擎提供的公开搜索信息,本站不存储任何数据与内容,任何内容与数据均与本站无关,如有需要请联系相关搜索引擎包括但不限于百度,google,bing,sogou 等
© 2025 book.cndgn.com All Rights Reserved. 新城书站 版权所有