more effective java

Discover more effective java, include the articles, news, trends, analysis and practical advice about more effective java on alibabacloud.com

"Effective Java" Learning notes (4)

Notes Five. The substitution of C language structure How to simulate some of the structures in C language with Java 19th: replacing structures with classes For structures in C, Java can be replaced with classes, however, you should not let class member variables can be publicly accessed, member variables should be private, and then provide some read and write operations to manipulate these variables, com

is thread optimization in Java 6 really effective?

Introduction to threading Optimization in-java 6 Sun, IBM, Bea, and others have spent a great deal of effort on the implementation of their Java 6 virtual machines to optimize lock management and synchronization. Such features as biased locks (biased locking), lock coarsening (lock coarsening), lock ellipsis from Escape (escape) analysis, adaptive spin locks (adaptive spinning), Increases concurrency effic

JAVA Web Novice Prone to the misunderstanding (all of them do miss and pro-test effective)

One: The prerequisites for configuring Tomcat in Eclipse:1. Download a JDK, configure the environment variables;2. Download one of the installed versions of Tomcat;3. Download the appropriate eclipse;Two: about how to configure the book on the internet I only say a few details1:At Target runtime this must be selected for the version of Tomcat or the system is empty by default, and after creating the servlet, there is no existing interface.2. If you want to manually configure the virtual path in

Effective Java reading notes-Creating and destroying objects (i)

operator), only instances of the class itself can be returned. The use of static factory methods can return objects of sub-types, greatly increasing flexibility.For example, the Java.util.EnumSet class introduced in Java 1.5 does not have a public constructor, only a static factory method. Enumset has two implementation classes, namely, Regalarenumset and Jumoboenumset. Two. Which implementation class is returned depends on the parameters of the stat

Effective Java 2.0_ Chinese-English control _item 10__java

. The ToString method is automatically invoked when an object is passed to println,printf, the string concatenation operator, or assert, or when printed through the debugger. (The platform in the Java 1.5 version adds a printf method, including String.Format, similar to the sprintf method in C). If you ' ve provided a good toString to phonenumber, generating a useful diagnostic message is as easy as this: If you have provided a good ToString method f

The exploration of Java Chinese chess game procedure [4]--generation effective way __java

Generate effective Reprint please retain the author information: Author: 88250 blog:http:/blog.csdn.net/dl88250 MSN Gmail qq:dl88250@gmail.com The formation of the process is to produce all the effective way, so that the computer players in these move to choose the best way, and finally out of this. The only thing you can do to make all the move is to be exhaustive. Chinese chess can have 45 choices in

Effective Java reading notes-concurrency

66: Synchronize access to shared mutable dataSynchronized:1 mutually exclusive, preventing the thread from seeing objects in an inconsistent state; 2 ensure that threads are able to see all the changes to the variables by each thread as they enter the synchronization area.In Java, in addition to a long or double, "read" or "write" a variable is atomic. Note: To read or write a single action is derived from, rather than read and write these two actions

Effective Java-Use tagged class with caution

affected by irrelevant field, and field can be declared final.Subclass rows can be extended independently of each other.Back to the original tagged class, is it really useless?If I use this class, I just need to use the corresponding arguments when invoking the constructor to get the desired instance.Just like the strategy pattern.Of course, the tagged class may be considered a strategy pattern (it should be a characteristic of a behavior rather than an instance feature), but the policy pattern

Effective access such as Java

The smaller the accessibility of the class, the better, that is enough, between different packages and modules, only the API interface is reserved for sufficient functionality, and the details of all the other features are encapsulated inside the package, so that the maintainability and extensibility of the code can be greatly improved. So, what are the access controls in Java?Public: This is the equivalent of "my door often open", anyone can enter, w

Effective Java experience, classes and interfaces

class, it is written inside the class. If you can see the wrong enumeration constants, use enumerations instead. Otherwise, these constants will be exported using a non-instantiated tool class.7. class hierarchy is better than label class . If the code has a different method result depending on a certain flag bit, that is, the code template, then you need to consider whether you can hierarchically code and extract the template code as a method in an abstract class to do class hierarchy.8. using

Effective Java reading notes-a common method for all objects

All classes in Java inherit from the object class, and there are a number of common methods in the object class that are discussed in this chapter: for common methods in the object class, our classes do not inherit, and the things to be aware of when inheriting.1th: Equals (), please observe the General Convention when overwritingFirst look at the situation where you do not need to overwrite:1. Each instance of a class is inherently unique. (such as s

Effective java--Reading notes

StringBuffer Append method.34. Referencing objects via interfacesDeclare it as much as possible:List subs=new ArrayList ();Rather than such a statement:ArrayList subs=new ArrayList ();It is appropriate to use a class to refer to an object if no suitable interface exists.8th Chapter Exception40. Use a run-time exception for program errors when using a checked exception for recoverable conditions.46. Try to keep the failure atomic:A failed method call should keep the object "in its state before i

Effective Java's Universal programming

This chapter is about some of the coding tips, or the code is recommended to observe some of the principles, the following one to enumerate:1, the scope of the local variable is the smallest. The reason for this rule is very simple, in the use of local variables when the creation of local objects, so easy to read the program, while ensuring that the local variables can be released as soon as possible after use, while in the creation of local variables, it is best to assign values to local variab

Effective Java English Second Edition reading notes Item 5:avoid creating unnecessary objects.

, Calendar.january, 1, 0, 0, 0); Boom_end=Gmtcal.gettime (); } Public BooleanIsbabyboomer () {returnBirthdate.compareto (Boom_start) >= 0 Birthdate.compareto (boom_end) ; }}There ' s a new-to-create unnecessary objects in release 1.5.It was called Autoboxing,and It allows the programmer to mix Primitive and boxed primitive types,boxing and unboxing automatically as needed.Prefer Primitives to boxed Primitives,and watch out for unintentional autoboxing.Don ' t create a new object when you sh

Effective Java reading notes of four generic type

.3. When using @suppresswarnings annotations, add a comment explaining why it is type-safe to do so.Third, the list takes precedence over the arrayThe two different points of an array compared to a generic:A, the array is covariant: Sub is a subclass of Super, sub[] is a subclass of super[].b, arrays are materialized: they are known and checked for element type constraints at run time.Based on the above two points: arrays and generics are not very well mixed to use. If there is an error or warni

Effective Java Reading notes eight exceptions

exception to debug high-level exception to help group, can use the form of abnormal chain translation.3, high-level strategy is the priority to prevent or deal with the underlying exception, do not make exception translation.Six, each method throws the exception to have the documentVii. include information that can capture failures in the detail message1, the abnormal details should be captured failure, easy to analyze later.2, Indexoutofboundsexception is a better example.Viii. efforts to main

Effective Java Reading notes two methods common to all objects

. Consider the implementation of the comparable interface1. The Comparato method is not a method in object, but is the only method in the comparable interface. This method can not only compare equivalence, but also make sequential comparisons.2, the General Convention of the interface is defined by the Equals method, but the ordered set uses the equivalence test of the CompareTo method.3, if it is a value class, and has a clear intrinsic ordering relationship, because it is determined to impleme

Effective Java-----Precise answers and double&float

(itemsbought+ "items bought."); System.out.println ("change:$" +funds);The returned results are as follows:4 items bought.Change:$0The result is correct.The program that uses int is as follows (1.00$ must be converted to 100cents first):int itemsbought = 0;int funds = 100;for (int price=10;funds>=price;price+=10) {funds-= Price ; itemsbought++;} System.out.println (itemsbought+ "items bought."); System.out.println ("change:$" +funds);The returned results are as follows:4 items bought.

Effective Java-----Returns an array or collection of 0 lengths instead of NULL

The following code, which normally returns NULL when the user list is empty, is assumed to be that the null return value is better than a zero-length array because it avoids the overhead required to allocate the array.Private final listBut this view is untenable for the following reasons:1) It is unwise to worry about performance issues at this level unless the analysis shows that this approach is the real source of performance problems;2) It is possible to return a 0-length array every time for

Effective Java Learning Notes

(max.). salt (5). chess (. sausage). Build ();The builder model has the advantage of variable parameters and no need to consider order. however, the builder mode is much more verbose than the overlapping constructor pattern, preferably in very good parameters.Article Three: hardening the Singleton property with a private constructor or enumeration typeThree ways to achieve singleton:1. Public static members are final fields// Singleton with public final field public class wills{ publicstati

Total Pages: 15 1 .... 9 10 11 12 13 .... 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.