effective java third edition

Read about effective java third edition, The latest news, videos, and discussion topics about effective java third edition from alibabacloud.com

Effective Java Reading notes of the seven general programming

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

<<effective java>> the best use of combination rather than inheritance

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

"Effective Java" notes

; - } + PublicBuilder Fat (intval) { AFat =Val; at return This; - } - PublicBuilder Sodium (intval) { -Sodium =Val; - return This; - } in Publicnutritionfacts Build () { - return NewNutritionfacts ( This); to } + } - the Privatenutritionfacts (Builder builder) { *Servingsize =builder.servingsize; $Servings =builder.servings;Panax NotoginsengFat =Builder.fat; -Sodium =Builder.sodium; the } +}Call:1 New Nutriti

Effective Java 3

an alternative to choose the following methods:Private Static Final thing[] Private_values = {...}; Public Static Final ListPrivate Static Final thing[] Private_values = {...}; Public Static Final thing[] VALUES () { return private_values.clone ();}9. In Java, public is not the highest access level, and if it is not in the export package, it will be private to the module.10. The public class should not have a public domain unless it is a public

Effective Java within class

Effective Java in the requirements of the class, interface, etc., summed up is enough to do, do not give too much access, the definition of the class is also, if a class is only used inside the class, then the class is defined as an inner class bar.The inner class is divided into four types:1, static inner class: Static inner class is in front of class more static keyword inner class, this class and class s

"Reading notes-effective Java" 02. Consider using the builder when you encounter multiple constructor parameters

construction Process There is a cost to creating the builder //Example Builder mode Public classnutritionfacts {Private Final intServingsize;//Required Parameters Private Final intservings;//Required Parameters Private Final intFat//Optional Parameters Private Final intSodium//Optional Parameters Public Static classBuilder {Private Final intservingsize; Private Final intservings; Private intFat = 0; Private intSodium = 0; PublicBuilder (intServingsize,intservin

Reading notes of "effective Java" Third, strengthen the Singleton property with a private constructor or enumeration type

is asked to create a second instance. In addition to the factory method there is a public domain method:public class Elvis2 {public static final Elvis2 INSTANCE = new Elvis2 ();p rivate Elvis2 () {}public void leavethebuilding () {} }The advantages of this approach are clear and unambiguous. The disadvantage is rigid, performance is not. The advantage of factory method is flexibility. The disadvantage is that it can be easily modified, such as changing to a unique instance of each thread that i

Java setting session timeout (fail) Three ways to set the session's effective time

1. Set in the Web container (for example, Tomcat here)Set in Tomcat-5.0.28\conf\web.xml, the following is the default configuration in Tomcat 5.0:[HTML] View plain copy - session-config> session-timeout>30session-timeout> session-config> Tomcat default session timeout is 30 minutes, can be modified as needed, negative or 0 is not limit session failure time.2. Set up in the project's Web. xml[HTML] View plain copy 3. Using

Hardening the Singleton property with a private constructor or enumeration type--effective Java reading notes

the face of complex serialization or reflection attacks. * Single-element enumeration types have become the best way to implement Singleton. * @author Liu Xiangfeng * * * * Public enumEnumsingleton {INSTANCE; Public void leavethebuilding(){}}/** * Serialization of Singleton mode * @author Liu Xiangfeng * */ Public class Serializesingleton implements Serializable { //Declare all instance domains to be instantaneous transient Private Static FinalSerializesingleton INSTANCE =NewSerializesin

Effective binary lookup tree judgment (Java implementation)

Leetcode Original question: (That is, to determine whether the binary tree is a two-fork search tree)Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node ' s key. The right subtree of a node contains only nodes with keys greater than the node ' s key. Both the left and right subtrees must also be binary search trees The following

"Effective Java"--exception

keep the failure atomicA failed method call should keep the object in the state it was before it was called, and there are several ways to do so Using Immutable objects Check parameter validity before changing state, throw exception early Put the potentially failed action before the change state, so that the failure can end prematurely without leaving the object in an inconsistent state Write recovery code (infrequently used), typically for data that has persisted To ma

Effective Java-Creating and destroying objects

1, consider using the static factory method instead of the constructor.Here are some advantages: The static method factory method has a variable name. For example, a true object defined in a Boolean class with a name that is very intuitive. Boolean.truepublic static Final Boolean true = new Boolean (true); You do not have to create new objects every time you call. If creating objects is expensive, using static classes can improve performance. Any subcla

[Effective Java Reading notes] Chapter II Creating and destroying objects the first article

Chapter II Creating and Destroying objectsThe first one uses the static factory method instead of the constructor, because: Static factory methods can have different names, that is, the constructor can only be distinguished by different parameters, and static factories can express different purposes in their names. The static factory method creates a new object without each invocation (in fact because it is static, so it can only be used as static, so it is created early and does not need

"Effective Java" 7, preference for generic methods

.item27; Public classgenericsingletonfactory{//Create object objects first, temporarily override T objects Private StaticUnaryfunctionNewUnaryfunction() { Publicobject Apply (object arg) {returnArg; } }; //according to T, the identity_function is converted to the corresponding type, because Identity_function returns the object type parameter unmodified, so the following type conversion is safe@SuppressWarnings ("Unchecked") Public Staticidentityfunction () {return(una

"Effective Java" 12, avoid over-synchronization

= = 23) { //Thread pool, which creates a thread pool of a single threads, creates a new thread instead of executing the task if the current thread breaks abruptly when the task is executedExecutorservice executor =Executors.newsinglethreadexecutor (); Finalsetobserver This; Try{executor.submit (NewRunnable () {@Override Public voidrun () {//There's going to be a deadlock.Set.removeobserver (Observer); }}). get (); } Catch(i

Effective Java Learning--16th: compound takes precedence over inheritance

(collectionreturnS.retainall (c); } @Override PublicBooleanRemoveAll(collectionreturnS.removeall (c); } @Override Public void Clear() {s.clear (); }}Myset2.javaPackage Cczu.edu.test2;import java.util.Collection; Public class MySet2e> extends forwardingsete>{ Private intAddcount =0; @Override Public BooleanAdd (e e) {addcount++;return Super. Add (e); } @Override Public BooleanAddAll (collectionreturn Super. AddAll (c); } Public intGetaddcount () {returnAddcount; }}Test@Test Public voidTest2

[Reading notes] Effective Java Chapter III

the general conventions of Object.hashcode, which prevents the class from working properly with all hash-based collections, such as Hashmap,hashset and Hashtable.always overwrite ToStringThis item is mostly intended to provide the necessary critical information when printing data, because the default ToString method only returns the unsigned hexadecimal representation of the class name [email protected]+ hash code.cover clone with careThe purpose of the Cloneable interface is expressed as an ob

"Effective Java" reading notes (a): Replace constructors with multiple parameters with builder mode

; } Public Static voidMain (string[] args) {Builderdemo demo=NewBuilder (calories). Carbohydrate (43). build (); }}Such code is easy to write and read. Furthermore, constraints can be imposed on their parameters, and the build method can examine these constraints, copy the parameters from the builder to the object, and test them in the object domain.Insufficient builder mode: 1. You need to create the builder before creating the object, which is not applicable in a very performance-oriented

[Effective Java Reading notes] Chapter III Class and interface 16th

The 16th compound takes precedence over inheritanceIf you are unsure of the relationship between B and a, and B is indeed a, then you should not use B to inherit a, or you will expose the implementation details, and your implementation will be limited to the original implementation, Is-a.The first example of the book cited implements a class extends HashSet class, because the lack of understanding of the AddAll method of the HashSet class (AddAll calls the Add method repeatedly), resulting in a

"Effective Java" service provider framework

The static factory method returns the class to which the object belongs, and can not be present when writing a class that contains the static factory method. This flexible, static factory approach forms the basis of the service provider Framework (Provider framework), such as the JDBC API. The service provider framework refers to a system in which multiple service providers implement a service (interface) that provides multiple implementations of the service provider's clients and decouples them

Total Pages: 15 1 .... 7 8 9 10 11 .... 15 Go to: Go

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.