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 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

Effective Java-minimizing variability

, there are two ways we can solve this problem: Use the basic type as much as possible within the class. If you can pre-think that those states will often change, then provide a package-level private matching class, for example, StringBuilder is relative to string. Also, if, for some reason, you cannot use the final modifier immutable class, but you do not want to be extended, there are other methods in addition to using final.The method is to replace all public constructors wi

"Effective Java" reading notes (v) using dependency injection instead of the original resource dependency

:// Dependency Injection provides flexibility and testability Public class spellchecker { private final Lexicon dictionary; Public spellchecker (Lexicon dictionary) { this. Dictionary= Objects.requirenonnull ( dictionary); } Public boolean isValid (String word) {...} Public List Suggestions (String typo) {...}}So the customer needs to use what dictionary is the customer's own decision, and our code does not need to maintain multiple copies.The popular explanation f

Effective Java experience, common approach

field that invokes its Hashcode method on each of these elements.[3] The above computed hash code is saved to the INT variable C, and then executed Result=37*result+c;[4] returns result.3. Always overwrite the ToString method. only override this method, other such as arrays.tostring (), and the toString of the collection class. When you call the output of the class, you invoke the ToString that the class has already implemented.4. Call the Clone method with caution. When you are designing a cla

Follow general conventions When overriding equals--effective Java reading notes

This is the desired result if any of the following conditions are met:Each instance of a class is inherently unique.Does not care if the class provides a "logical equality" test function.The superclass has overridden equals, and the behavior inherited from the superclass is also appropriate for subclasses.Class is private or package-level private, it can be determined that its Equals method is never called.If a class has its own unique "Roggi" concept (unlike the concept of object equivalence),

Effective Java to avoid creating unnecessary objects and eliminating outdated references

Why avoid creating unnecessary objects? The process of creating objects is still more cost-intensive, according to the performance tests given in the book, the time consuming to recreate objects is 250 times times the time consumed by reusing objects. The following is a list of scenarios where objects can be reused.1, String type Note that there is a big difference between string s = "as" and string s = new String ("as"), and the second method of creating a string instance will actually produce

Is it really effective to use the final keyword inline compiler optimization in Java?

(inkfish original, reprint please indicate the source: http://blog.csdn.net/inkfish/) In order to seek the performance optimization of Java code, search from the internet to use final keyword compile-time inline optimization method, but really effective. The actual test found that not necessarily, even the performance impact of the huge, eventually abandoned the idea of using final optimization. Test enviro

Effective Java Learning Notes (i)

Recently in the watercress to see some book reviews, very feel, and there is a call effective Java is said to be very good, download a look, really masterpiece, a lot of things are not read, the skill is still shallow, still have to continue efforts. It feels so good to read that it's much better than a grammar-telling book. The first part of the object is created and destroyed. Said 5 principles. 1. Rep

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

"Reading notes-effective Java" 05. Avoid creating unnecessary objects

Calendar,date every time. Performance is improved in the following ways, and the meaning of the code is more clear.ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.TimeZone; Public classPerson {Private FinalDate birthday; Private Static FinalDate Boom_start; Private Static FinalDate Boom_end; Static{Calendar gmtcal= Calendar.getinstance (Timezone.gettimezone ("GMT")); Gmtcal.set (1946, Calendar.january, 1, 0, 0, 0); Boom_start=Gmtcal.gettime (); Gmtcal.set (1965, Calendar.january,

"Reading notes-effective Java" 01. Consider replacing constructors with static factory methods

There are two ways to get an instance of a class:1. Provide a public constructor (most commonly used).2. Provide a public static factory method (static factory methods).// Static Factory Method Example Public Static Boolean ValueOf (boolean b) { return b? Boolean.TRUE:Boolean.FALSE;}Advantages of the Static factory approach:1. There is a name. When a class requires more than one constructor with the same signature (method signature = method name + parameter list), the static factory method

Consider builder--effective Java reading notes when encountering multiple constructor parameters

= servingsize; This. servings = servings; }/** * * @param val * Assign a value to an option * @return Builder object for chain adjustment Use the Assignment function * / PublicBuildercalories(intval) {calories = Val;return This; } PublicBuilderFat(intval) {fat = val;return This; } PublicBuilderSodium(intval) {sodium = Val;return This; } PublicBuilderCarbohydrate(intval) {carbohydrate = Val;return This; }/** * Create a Get object method and pass yourself (Builder) as a parameter * *

Effective Java Directory

exceptions throws a corresponding exception to the abstract Each method throws an exception that must have a document Include information in the detail message that could be failed to replenish Try to keep the failure atomic Do not ignore exceptions Concurrent Synchronizing access to shared mutable data Avoid over-synchronization Executor and tasks take precedence over threads Concurrency tools take precedence over wait and notify Documentation

Reading notes--effective Java; directory structure, easy to review and find

exceptions for programming errors 59th: Avoid unnecessary use of the exception that is examined 60th: try to use the standard exception 61st: throws an exception corresponding to the abstract 62nd: All exceptions thrown by each method must have a document 63rd: contains the failure-capture information in the detail message 64th: Try to keep the failure in the Atomic 65th Bar: Do not ignore exceptions chapter 10th Concurrent 66th: Synchronizing access to shared variable data 67th: Avoid too many

Effective Java Reading Notes value 2nd: Consider using a constructor when you encounter multiple constructor parameters

parameterless builder method to generate the immutable object. This builder is the static member class of the class of its builder.public class Person {private string id;private string Name;private string address;public the parameters necessary for static class builder{//Priv Ate final string id;//optional parameter private String name = "";p rivate string address = "";p ublic Builder (String Id) {this. id = ID;} Public Builder name (String name) {this.name = Name;return this;} Public Builder a

Big talk effective Java core combat programming thought of the Monkey King's trick

I do not know whether we remember in the "Journey to the" in the Lotus Hole in the story of the Treasure, is the Monkey King skillfully grabbed the treasures, the gold and Silver Kok King that chapter. What does this story give us? What is the connection between this story and effective Java? Or continue the style of the article, read the code, read the story. 1import static org.junit.assert.*;2import org.

Effective Java reading notes-classes and interfaces

Last week for a bunch of reasons for preparing for the exam, no time to read, make up a little today.Classes and interfaces are at the heart of the Java programming language, and they are the basic abstraction unit of the Java language, which provides a number of powerful basic elements for programmers to design classes and interfaces, and this chapter is about guiding principles for designing more useful,

Effective Java (6) How to eliminate outdated object references

First, the introduction Many people may be thinking of the problem: Java has garbage collection mechanism, then there are memory leaks? The answer is yes, the so-called garbage collection GC automatically manages memory recycling without requiring programmers to manually free up memory every time, but if there are a large number of temporary objects that do not need to be used without canceling a reference to them, they consume a large amount of memo

Effective Java Chinese version 2nd edition PDF

: Network Disk DownloadContent Introduction······This book introduces 57 useful rules of thumb in Java programming that cover the solutions that most developers face on a daily basis. A comprehensive description of the technologies used by the Java platform design experts reveals what should be done and what should not be done to produce clear, robust, and efficient code.Each of the rules in this book appea

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