Java Basics-Single column

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Hashcode () produces a number as a symbol after the comparison, you can take this number to do comparisons, there is a comparison of numbers, there is a comparison of equals, the string can also be used to compare the hashcode
Rewrite hashcode: Write a few private properties, wrap them up with get and set

Write a test class: Only the content, that run out of the hashcode is the same, this is a means of comparison, two objects of comparison

Single Case design mode:
Design mode:
Design pattern is a fixed idea, it is a kind of code skills, as long as the object-oriented language can be used in design patterns, such as java,php,c#, etc... There are a total of 23 design patterns, which can be divided into three sections:
1. Create type
2. Structural type
3. Behavioral Type
Schema mode:
Design patterns called tactics, architecture patterns called strategies, design patterns are relatively small, the architecture mode is more than the design mode, it is dedicated to our system inside the architecture, structure, cache architecture, distributed architecture, etc...

Single case (single State):
A singleton is a single instance, meaning that a class only has one object. Which means I'm going to control this class. Only one object, not multiple objects
The singleton is divided into two modes:
1. Lazy Type
Pros: Do not load resources in advance
Cons: Slow access
Slow temper, that is, when I use it, when to create an object

Apply for a property, but it is not assigned, and then the method is ready to take the object to determine whether the object is assigned, if there is no assignment to give you a new one, put on this property, and then feedback out, add a sync keyword meaning is synchronized, With this keyword, you're going to have to go in line.

2. A hungry man type
Advantages: Fast access speed
Cons: Pre-occupancy resources
A quick temper, which means you've created this object in the first place.
The simplest design pattern is to write a privatization constructor, prevent others from being new, write a static object property, and then write a static method that feeds this method.

To get this object, you can only use this static method to get

Self-created mode:

The usefulness of a single case is:
1. System in order to maintain an object
2. A class has a large number of object accesses, but does not log related data values

Java Basics-Single column

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.