Effective Java Index

本文详细介绍了《Effective Java》一书中关于Java编程的最佳实践,涵盖了从创建和销毁对象到异常处理等各个方面,旨在帮助开发者提高代码质量和效率。

Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I learned from it with you just as what I did before with CSharp. Here is the index of the notes. Hope you like it :)

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

// Kaibo

转载于:https://www.cnblogs.com/haokaibo/p/effective-java-index.html

### Java For 循环概述 For循环是Java编程语言中用于控制流的一种重要结构,允许代码块被指定次数反复执行。其语法如下: ```java for (初始化; 条件表达式; 更新) { // 执行语句 } ``` 此结构由三部分组成:初始化变量、条件判断以及每次迭代后的更新操作[^2]。 ### 基本For循环实例 下面是一个简单的例子,展示了如何利用for循环打印0到9之间的整数(含边界值): ```java public class BasicForLoopExample { public static void main(String[] args) { for(int i = 0; i <= 9; ++i){ System.out.println(i); } } } ``` 这段代码定义了一个名为`BasicForLoopExample`的类,在其中实现了基本的for循环逻辑,从0开始计数直到达到上限9为止,并逐个输出这些数值。 ### 数组倒序遍历 当涉及到数组或其他类型的集合时,可以采用for循环实现逆向访问元素的功能。这里给出一段用来展示如何反向读取并显示int型数组内所有成员的具体做法: ```java public class ReverseArrayTraversal { public static void main(String[] args) { int[] numbers = {1, 2, 3, 4, 5}; for(int index = numbers.length - 1 ; index >= 0 ; --index ){ System.out.print(numbers[index]+" "); } } } ``` 在这个案例里,通过调整索引起始位置为最后一个有效下标(`length-1`)并向前推进(-1),从而达到了预期效果——即按照相反顺序输出整个列表的内容[^1]。 ### 性能考虑与最佳实践建议 考虑到效率问题,《Effective Java》提倡尽可能选用增强版for-each形式替代标准版本,因为前者不仅更易于阅读而且有助于减少潜在错误的发生几率;同时也要注意避免将耗时较长的操作置于循环体内,比如文件I/O或网络请求等,以免影响整体运行速度[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值