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 11
item 3: enforce the singleton property with a private constructor or an enum type 17
item 4: enforce noninstantiability with a private constructor 19
· · · · · ·
(更多)
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 11
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: avoid creating unnecessary objects 20
item 6: eliminate obsolete object references 24
item 7: avoid finalizers 27
3 methods common to all objects 33
item 8: obey the general contract when overriding equals 33
item 9: always override hashcode when you overrideequals 45
item 10: always override tostring 51
item 11: override clone judiciously 54
item 12: consider implementing comparable 62
4 classes and interfaces 67
item 13: minimize the accessibility of classes and members 67
item 14: in public classes, use accessor methods, not public fields 71
item 15: minimize mutability 73
item 16: favor composition over inheritance 81
item 17: design and document for inheritance or else prohibit it 87
item 18: prefer interfaces to abstract classes 93
item 19: use interfaces only to define types 98
item 20: prefer class hierarchies to tagged classes 100
item 21: use function objects to represent strategies 103
item 22: favor static member classes over nonstatic 106
5 generics 109
item 23: don't use raw types in new code 109
item 24: eliminate unchecked warnings 116
item 25: prefer lists to arrays 119
item 26: favor generic types 124
item 27: favor generic methods 129
item 28: use bounded wildcards to increase api flexibility 134
item 29: consider typesafe heterogeneous containers 142
6 enums and annotations 147
item 30: use enums instead of int constants 147
item 31: use instance fields instead of ordinals 158
item 32: use enumset instead of bit fields 159
item 33: use enummap instead of ordinal indexing 161
item 34: emulate extensible enums with interfaces 165
item 35: prefer annotations to naming patterns 169
item 36: consistently use the override annotation 176
item 37: use marker interfaces to define types 179
7 methods 181
item 38: check parameters for validity .. 181
item 39: make defensive copies when needed 184
item 40: design method signatures carefully 189
item 41: use overloading judiciously 191
item 42: use varargs judiciously 197
item 43: return empty arrays or collections, not nulls 201
item 44: write doc comments for all exposed api elements 203
8 general programming 209
item 45: minimize the scope of local variables 209
item 46: prefer for-each loops to traditional for loops 212
item 47: know and use the libraries 215
item 48: avoid float and double if exact answers are required 218
item 49: prefer primitive types to boxed primitives 221
item 50: avoid strings where other types are more appropriate 224
item 51: beware the performance of string concatenation 227
item 52: refer to objects by their interfaces 228
item 53: prefer interfaces to reflection 230
item 54: use native methods judiciously 233
item 55: optimize judiciously 234
item 56: adhere to generally accepted naming conventions 237
9 exceptions 241
item 57: use exceptions only for exceptional conditions 241
item 58: use checked exceptions for recoverable conditions and runtime exceptions for programming errors 244
item 59: avoid unnecessary use of checked exceptions 246
item 60: favor the use of standard exceptions 248
item 61: throw exceptions appropriate to the abstraction 250
item 62: document all exceptions thrown by each method 252
item 63: include failure-capture information in detail messages 254
item 64: strive for failure atomicity 256
item 65: don't ignore exceptions 258
10 concurrency 259
item 66: synchronize access to shared mutable data 259
item 67: avoid excessive synchronization 265
item 68: prefer executors and tasks to threads 271
item 69: prefer concurrency utilities to wait and notify 273
item 70: document thread safety 278
item 71: use lazy initialization judiciously 282
item 72: don't depend on the thread scheduler 286
item 73: avoid thread groups 288
11 serialization 289
item 74: implement serializable judiciously 289
item 75: consider using a custom serialized form 295
item 76: write readobject methods defensively 302
item 77: for instance control, prefer enum types toreadresolve 308
item 78: consider serialization proxies instead of serialized instances 312
appendix: items corresponding to first edition 317
references 321
index 327
· · · · · · (收起)
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 (查看原文)
Errors are reserved for use by the JVM to indicate resource defi-ciencies, invariant failures, or other conditions that make it impossible to continue execution (查看原文)
书写的非常好,有条有理论据让人信服,但是不觉得这书需要通篇看第二遍。第四章Classes and Interfaces和第五章Generics是我全书最喜欢的章节,肯定会重看的,非常详细的讲述了java的多态和通用类型的使用,这也算是java的核心思想了,看完对java的设计思想开始有些理解了。总体感觉java是一个很繁琐的语言,特别是它的concurrency这一块,synchronize的使用...书写的非常好,有条有理论据让人信服,但是不觉得这书需要通篇看第二遍。第四章Classes and Interfaces和第五章Generics是我全书最喜欢的章节,肯定会重看的,非常详细的讲述了java的多态和通用类型的使用,这也算是java的核心思想了,看完对java的设计思想开始有些理解了。总体感觉java是一个很繁琐的语言,特别是它的concurrency这一块,synchronize的使用简直awkward到想哭。不过这书第二版是java 1.5的,不是很记得后面几版这块有没有改进。非常好奇Go作为并发语言是怎样高雅的实现并发的。目前就自己所掌握的来看,akka的并发思想是自己最喜欢的。(展开)
Here are some common names for static factory methods: - valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods. - of--A concise alternative to valueOf, popularized by EnumSet. - getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In the c...
2016-07-15 11:19:48
Here are some common names for static factory methods:
- valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods.
- of--A concise alternative to valueOf, popularized by EnumSet.
- getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In the case of a singleton, getInstance takes no parameters and returns the sole instance.
- newInstance--Like getInstance, except that newInstance guarantees that each instance returned is distinct from all others.
- getType--Like getInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method.
- newType--Like newInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method.引自 ITEM 1: CONSIDER STATIC FACTORY METHODS INSTEAD OF CONSTRUCTORS
To make a class immutable, follow these five rules: 1. Don't provide any methods that modify the object's state. 2. Ensure that the class can't be extended. 3. Make all filelds final. 4. Make all fields private. 5. Ensure exclusive access to any mutable components.
2016-07-14 16:32:01
To make a class immutable, follow these five rules:
1. Don't provide any methods that modify the object's state.
2. Ensure that the class can't be extended.
3. Make all filelds final.
4. Make all fields private.
5. Ensure exclusive access to any mutable components.引自 ITEM 15: MINIMIZE MUTABILITY
Here are some common names for static factory methods: - valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods. - of--A concise alternative to valueOf, popularized by EnumSet. - getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In the c...
2016-07-15 11:19:48
Here are some common names for static factory methods:
- valueOf--Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods.
- of--A concise alternative to valueOf, popularized by EnumSet.
- getInstance--Returns an instance that is described by the parameters but cannot be said to have the same value. In the case of a singleton, getInstance takes no parameters and returns the sole instance.
- newInstance--Like getInstance, except that newInstance guarantees that each instance returned is distinct from all others.
- getType--Like getInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method.
- newType--Like newInstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method.引自 ITEM 1: CONSIDER STATIC FACTORY METHODS INSTEAD OF CONSTRUCTORS
To make a class immutable, follow these five rules: 1. Don't provide any methods that modify the object's state. 2. Ensure that the class can't be extended. 3. Make all filelds final. 4. Make all fields private. 5. Ensure exclusive access to any mutable components.
2016-07-14 16:32:01
To make a class immutable, follow these five rules:
1. Don't provide any methods that modify the object's state.
2. Ensure that the class can't be extended.
3. Make all filelds final.
4. Make all fields private.
5. Ensure exclusive access to any mutable components.引自 ITEM 15: MINIMIZE MUTABILITY
0 有用 .. 宸 ~ 2016-12-15 01:16:17
书写的非常好,有条有理论据让人信服,但是不觉得这书需要通篇看第二遍。第四章Classes and Interfaces和第五章Generics是我全书最喜欢的章节,肯定会重看的,非常详细的讲述了java的多态和通用类型的使用,这也算是java的核心思想了,看完对java的设计思想开始有些理解了。总体感觉java是一个很繁琐的语言,特别是它的concurrency这一块,synchronize的使用... 书写的非常好,有条有理论据让人信服,但是不觉得这书需要通篇看第二遍。第四章Classes and Interfaces和第五章Generics是我全书最喜欢的章节,肯定会重看的,非常详细的讲述了java的多态和通用类型的使用,这也算是java的核心思想了,看完对java的设计思想开始有些理解了。总体感觉java是一个很繁琐的语言,特别是它的concurrency这一块,synchronize的使用简直awkward到想哭。不过这书第二版是java 1.5的,不是很记得后面几版这块有没有改进。非常好奇Go作为并发语言是怎样高雅的实现并发的。目前就自己所掌握的来看,akka的并发思想是自己最喜欢的。 (展开)
0 有用 拉脚 2017-07-21 22:40:45
补坑。
0 有用 君弈 2012-02-22 20:55:37
经典
0 有用 王哈哈 2012-08-26 00:41:54
重新看了一遍。比《Practical Java》要深一些,不适合入门者看。语言描述没有后者简洁,有些晦涩,需要仔细认真的阅读。
0 有用 sure 2011-12-20 09:38:15
读了两遍了,估计未来肯定还有第三遍第四遍第n遍...
1 有用 Kenny小狼 2019-09-10 23:22:23
神作...影印版
0 有用 慢慢慢时光 2019-06-28 07:10:17
看的是第三版,文字的质量不用说了,美工部分也非常不错,高亮和代码处理的非常舒服,推荐纸质版
0 有用 侘 寂 2018-05-16 10:02:23
214睡前读物#1,谢谢Charlie
0 有用 刘家宝树 2018-02-28 22:09:18
作者文字有点别扭,有些句子需要仔细看才明白
0 有用 拉脚 2017-07-21 22:40:45
补坑。