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
According to SECLISTS, they found that the new Reflection API did not undergo a very safe review when introducing Java SE 7, and there was a very large vulnerability.
This vulnerability allows hackers to use a widely known method 10 years ago to attack Java virtual machines. The Reflection API in Java SE 7 does not adopt the appropriate protection mechanism to p
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 (
Generics, which have been used since Java 1.5, have a more intuitive impression of ... "the type in the angle brackets I do not have to check the type and do not have to go strong."Indeed, what is the point of generics if you think of the problem from the user's point of view of the API?
Discover errors as soon as possible after they is made, ideally at compile time.
Generics provide precisely this capability.For example, there is a coll
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
XML has now become a general Data Interchange format, its platform independent, language-independent, system-independent, which brings great convenience to data integration and interaction. For the syntax knowledge and technical details of the XML itself, it is necessary to read the relevant technical literature, which includes the DOM (document Object Model), the DTD (document Type Definition), and SAX (simple APIs for XML), XSD (XML Schema Definition), XSLT (extensible Stylesheet Language Tran
provide the return natural for STA Tic Factory methods. Interfaces can ' t have static methods, so by convention, static factory methods to a interface named Type are put in a No Ninstantiable Class (Item 4) named Types.
One application of flexibility is that APIs can return objects without having to make their classes public. Hiding the implementation class in this way will have a more concise API. This technique applies to an interface based framework (Item 18), which provides a natural retur
Concurrent66. Synchronizing access to shared mutable dataThe keyword synchronized can guarantee that only one thread can execute a method, or a block of code, at the same time.If there is no synchronization, the change of one thread cannot be seen by other threads. Synchronization not only prevents a thread from seeing an object in an inconsistent state, it also guarantees that every thread that enters the synchronization method or synchronizes the code block sees all the modifications that were
: validity is difficult to guarantee.Manually freeze objects to prevent objects from being used before thawing.The constructor mode guarantees the security of the overlapping constructor mode, and also guarantees the readability of the JavaBeans mode.Builder Instance Build treeIn Java, the traditional abstract factory implements the class object, which acts as part of the build method with the Newinstance method. This usage implies a lot of problems.
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.