这几章看的比较快,内容就如同标题一样比较容易理解,所以只有部分内容会在[]中解释,其他的就直接理解标题,并不影响阅读质量。不过如果时间充足的话,还是仔细读一读原书的内容,相信还是有所收获的。主要最近自己想进入算法与机器学习部分,尽快结束这本书。另一方面,讨论一些自己感兴趣的内容,我会将搞过的东西总结下。后面可能写一部分关于java字节码阅读以及编写的东西。只所以这么来,是因为字节码编程还是非常用途实际的,这一"java编译语言"使得String与StringBuilder的性能对比又有了新的认知,为了更好的编写程序,这些是值得学习的。之后,我会在5月份投入到机器学习中,╮(╯▽╰)╭。
Reprint Please specify source: http://blog.csdn.net/supera_li/article/details/45155857
Enumerations and annotations
- Use an enum instead of an int constant. [Class | Method General constants, enum centralized to facilitate management | call | change]
- Replace ordinal with instance field
- Replacing bit fields with Enumset
- Replace ordinal index with Enummap
- Simulating a scalable enumeration with interfaces [enumeration of interface types, recommended]
- Annotations take precedence over naming patterns [that's what the note pack is]
- Insist on using the override annotation [override if no annotations are displayed, you may throw a method that does not actually overwrite the parent class, making future programs a potential bug]
- Defining a type with a markup interface [eg: it is something that is a trade-off between some serialization classes and Targe (ENUM. Constants). If you apply a specialized interface, use the former]
Method
- Check the validity of the parameter [method at the beginning of the parameter check, the parameters to be trusted to make a credible judgment]
- Protective copy when necessary [output to the client, the data returned by the client is not necessarily trustworthy, if possible, a copy on the server side, which is the most reliable]
- Careful design method signature
- Use overloading with caution [can be less, can be called by a type conversion call, try to avoid overloading]
- Use variable parameters sparingly [method parameters should be as few as possible]
- Returns a 0-length array or collection, not null[, or the upper code always needs to do a null test, or a lot of comments when returning null.
- Write a document comment for all exported API elements
General programming
- Minimizing the scope of local variables
- For-each loops take precedence over traditional for loops
- Understanding and using class libraries
- If precise answers are required, avoid using float and double[only for scientific calculations using floating-point numbers, and sometimes consider using large-number classes BigDecimal instead of related operations]
- The base type takes precedence over the boxed base type [the latter belongs to the class, especially in the cycle of automatic unboxing and boxing, the performance degradation is more serious]
- If other types are more appropriate, try to avoid using strings [strings have a higher performance cost, a connection + sign represents the new character object, consider the StringBuilder class instead? ]
- Beware of the performance of string connections [similar to the connection + number is the object's new operation]
- Referencing an object through an interface [after changing an object implementation, you only need to change the new object type after the interface, and the other code will continue to work]
- The interface takes precedence over the reflection mechanism [the reflection mechanism is mainly intrusive, and the reflected anomalies are concentrated in the running period, which is not easy for abnormal control, so it is not recommended]
- Use local methods with caution [platform migration is over]
- Careful optimization [Analysis good optimization, as far as possible in the design of good or bad to optimize, otherwise optimization may lead to unnecessary waste]
- Adherence to universally accepted naming conventions [easy to understand and team consensus is the norm]
Abnormal
- Exceptions are used only for exceptions [a more normal sentence, but the definition of anomalies requires careful consideration]
- Use a run-time exception for a programmatic error with a inspected exception for recoverable cases
- Avoid the need to use a inspected exception [incoming parameter trustworthiness]
- Preferential use of standard-corresponding exceptions [standardized, easy to understand]
- Each method throws an exception with a document [easy to understand]
- Contains information that captures the failure in the detail message [should be called a reserved exception field, to be able to know the context content when the exception occurs]
- Trying to keep the failure atomic [is not to say that many failures are treated as a failure]
- Do not ignore exceptions [catch and do a deal, cannot ignore, or neglect to give a comment]
Effective Java experience, enumerations, annotations, methods, generic design, exceptions