Effective Java Chinese version reading summary

Source: Internet
Author: User

Click on the link to see the original cloud notes spent half a day, greedy chew Read effective Java this book (although famous for a long time, but seldom read) turned over a kind of eating and sleeping feeling, work left to stay to read a special, and then simply take home to see. The following is a summary of the content, Mainly for the personal feeling useful, there is a large number of not mentioned, because the level is limited, there is no time to digest 1 Introduction 2 Creating and destroying objects# static Factory method because of the constructor boolean.valueof (String); is almost always better than the constructor Boolean (String); The constructor creates a new object each time it is called * object creation more expensive class calendar (it is recommended to instantiate one time in a static code block) the cost of establishing a database connection is very expensive, (reusing objects is very meaningful, Database connection pool--but will increase memory consumption, also can damage performance, and consider the JVM recycle) * Static Factory method common name valueof () of () getinstance () Singleton, the method has no parameters, returns a unique instance newinstance () Make sure that each returned instance is different from other instances GetType () the type of object returned by the factory method Newtype () The type of object returned by the factory method () The delay initialization is deferred to the object method for the first invocation to instantiate, (sometimes not recommended, which makes the method implementation more complex, Unable to improve performance significantly) # string s=new string ("Hello"); Don ' t do this! The statement creates a new string instance each time it executes, no need! "Hello" is itself a string instance if this usage is in a loop, or in a method that is frequently called, creates thousands of unnecessary string instance-modified code: String s= "Hello"; objects can be reused # expired object references--causing memory leaks if a stack grows first and then shrinks, the objects that are popped from the stack will not be garbage collected, even if the stack's program no longer references those objects, and they are not recycled because the stack internally maintains outdated references to those objects ( obsolete reference); the so-called expired reference is a reference that will never be lifted again. 3 methods that are common to all objects# always overwrite the ToString () method (General convention: should be a concise read representation) Java.lang.Object provides an implementation of ToString, but the string he returns is not what the user of the class wants to see; it contains the name of the class @ hash code 16 binary notation "No Strings" 1353413xxxx "to be simple and easy to understand recommend that all subclasses override this method 4 classes and Interfaces 5 generic typePrioritize generic lists over arrays take advantage of restricted wildcard characters to improve API flexibility 6 enumerations and annotationsAnnotations take precedence over named patterns 7 Methods* Use assertions to check the validity of parameters (there is no cost in nature) * Careful design method signature (name, too long parameter list) * Careful use of variable parameters static int sum (int firstarg,int ... args) {int min=firstarg;for ( int Arg:args) {}}* Returns a 0-length array or a collection, instead of a null the client programmer may forget to deal with NULL to avoid overhead problems, and it is unwise to worry about this level of performance problems unless the analysis shows that this code is the source of the performance problem; return New array[0];* document for all exported API elements 8 General Programming* Local variable scopes minimize earlier programming languages (such as C), requiring local variables to be declared at the beginning of a block of code; This habit should be corrected to minimize the scope of the local variables, it should be the first time to use the local declaration; (Avoid distracting the programmer, etc. * For-each Loop takes precedence over delivery for loop * Understand and use underwear (class library) a senior engineer with algorithmic backgrounds spends a lot of time designing, implementing, and testing, and then auditing through domain experts to ensure that time is spent properly on the application rather than the underlying details; many people use it as an industry standard, Drive optimization and improve performance without any effort; do not reinvent the wheel, if you do something very common, it is possible that the class library already provides the implementation that every programmer needs to be familiar with: Java.langjava.utiljava.io * requires precise answers, Avoiding the use of float and double is primarily for scientific calculations and engineering calculations, and does not provide completely accurate results * Basic types better than container types * String connection performance using StringBuilder to increase 50 times times + * Refer to Objects by Interface Rule 1: Do not optimize, rule 2 : Or do not optimize before the optimization is not absolutely clear, please do not optimize * Follow the universally accepted naming rules * Minimize the use of reflection the benefits of compile-time check types are lost; The code that executes the reflection is very verbose and clumsy; performance loss, reflection is much slower than ordinary method calls, the difference is hard to say 2-50 times ... RPC is used when remote calls are more appropriate 9 ExceptionsDon't quite understand ... 10 Concurrency* Avoid over-synchronization (slow performance, deadlock) * Executor and tasks take precedence over threads 11 SerializationDon't quite understand ...

Effective Java Chinese version reading summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.