Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Personal blog Sync release: Effective java-Reading notes-Chapter III methods that are common to all objectsChapter III methods that are common to all objectsAll non-final methods (equals, Hashcode, toString, clone, Finalize) have explicit general conventions because they are designed to be overwritten, if not adhered to, a hash-based collection (HashMap, HashSet, HashTable) may not work together with this c
Singleton mode: "A class has and has only one instance, and self-instantiation is provided to the system as a whole." ”There are a number of ways to implement a singleton pattern, such as lazy mode (and so on when the time is instantiated), a Hungry man mode (class loading is instantiated), and so on, here with the A Hungry Man mode method implementation, that is, class loading on the instantiation, a single case pattern application scenario has many, such as an application has a window interfac
DescriptionHere is read the "Effective Java Chinese version of the second edition" of the Reading notes, here will record some personal feeling a little bit important content, convenient for later review, may be due to personal strength reasons caused by misunderstanding, if found welcome to point out. Some individuals do not understand that will be marked with a slash.The first chapter is the introduction,
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
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, be
The compiler generates a public, parameterless default constructor only if the class does not contain an explicit constructor. This class cannot be instantiated as long as a class contains a private constructor. Example:1 //Tool Class2 Public classUtilityclass {3 //Private Constructors4 PrivateUtilityclass {5 Throw Newassertionerror ();6 }7 8 //Other operations ...9} Assertionerror avoid invoking the constructor inside the class to ensure that the class is not inst
up when a new entry is added to the cache. The Linkedhashmap class can implement the latter through its Removeeldestentry method. For more complex caches, you must use Java.lang.ref directly.A third common source of memory leaks is listeners and other callbacks.If the client registers callbacks in its own implementation of the API, but does not explicitly unregister, they will accumulate unless some action is taken. The best way to ensure that callbacks are immediately treated as garbage collec
correct.Although we can solve this problem through a composite approach (composition), the two classes are not is-a relationships.
The nature of the static factory approach is still a static method, and he does not have a particular standard.We cannot specifically identify a static factory method in the API documentation (perhaps by adding a standard annotation?).When I want to find a way to instantiate a class from the API, it is still not intuitive relative to the constructor.Although the
. Without the boss's previous reminders, I'm afraid it's hard to think of the reason for this (especially if the fault cannot be reproduced locally and the error data cannot be tested with breakpoints). Young man, as a novice, good accumulation of experience, later to do the work will become more and more handy. At the same time, if it takes a lot of time to solve a problem, ask your mentor or a colleague who is more experienced than you are asking for help. After a few days the task is not so n
Item 15 The variability of the minimized class
Effective Java
How do I make a class immutable?
Does not provide a way to change the state of an object. (mutators)
Ensure that the class is not inherited, that is, the class is qualified with final.
Make all fields (field) final.
Make all the domains private.
Ensure all mutually exclusive access to the mutable component (
annotations, Package-info.java can (but is not required) include package declarations and package annotations.Javadoc the ability to have "inherited" method annotations. If the API element does not have a document comment, Javadoc will search for the most applicable document comment, and the document comment of the interface takes precedence over the document comment for the superclass.You can also inherit portions of a document's comments from a superclass using the {@inheritDoc} tag. This mea
policy with a function objectIn Java, where there is a similar set of sequencer, the Sequencer object only represents the strategy of sorting, such instances of the class is functionally not different, mutual equivalence, suitable as a singleton, saving unnecessary object creation overhead.prioritize static member classesStatic member classes are the simplest kind of nested classes. If the member class does not require access to the perimeter instanc
JNI calls.These JNI methods is coded in C or C + +. They do the actual work, interacting with a native label.Let's look at the figure.You can see this AWT components provide a universal public API to the application by AWT component class and AWT peers. A Component class and its peer interface is identical across platform. Those underlying peer classes and JNI codes are different. )
In addition, finalizer chaining was mentioned. The subclass constructor automatically calls the parent class con
Sixth elimination of expired referencesThere will still be memory leak in Java, such as a stack growth and contraction, then the object pops from the stack will not be garbage collected, the immediate use of the stack of the program no longer reference these objects. This is because the inside of the stack maintains outdated references to these objects (which are never dismissed) and needs to be shown to empty (null) the objects and tell the garbage c
rather than classes to refer to objects.2. If no interface is available, consider the abstract base class.Ix. interface takes precedence over reflection mechanism1. Defect of reflection mechanismA, loss of the benefits of compile-time type checkingb, the code needed to perform the reflection access is very clumsy and lengthy.C, Performance loss2, usually only the class must work with the class that is unknown at compile time to need reflection. Used only to instantiate objects, it is best to us
The first thing about using the OO language in Java is that if the class is not designed to be inherited, try not to use the combinationFrom 2, our class B makes a copy of the add of Class A to drink the AddAll method, so that we can count the number of calls to Class A every time we call it, and we actually call Class B.But the count variable of instance object B becomes 2, explaining the reason in Figure 1 I have done a blackboard painting, this exa
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.