A collection of fragmented knowledge points in Java (subsequent additions)

Source: Internet
Author: User

-----------------------------------about Encapsulation-------------------------------------

Packaging principles
Hide content that does not need to be provided externally.
Hides the property and provides a public way to access it. Some information is encapsulated and then provided a public interface for outsiders to access, because the access operation mode can be controlled to standardize the user input data, limit unreasonable information, improve the robustness of the code.

-----------------------------------Constructor Method---------------------------------

Feature coercion Initialization
Feature no return value the function name is consistent with the class name
Can only be called after new
If you do not explicitly define a constructor for a class, the system assigns a default parameterless, method body is empty constructor, if a constructor has been explicitly defined for a class, the system does not assign a default parameterless, method body is empty constructor, then the call will be faulted.

-----------------------------------Constructing code blocks-----------------------------------

Function: initializes the object.
The object runs as soon as it is established and takes precedence over the constructor function.
Differences from constructors:
The code block is constructed to initialize all objects, whereas constructors are initialized to the corresponding object.
Constructs a block of code that initializes the features or functions common to all objects.

----------------------------------keyword this-------------------------------------

function: Used to distinguish between local variables and member variables with the same name.

This represents the object of this class, in the end it represents the table which one?
This represents the reference to the object to which the function belongs. Simply put, which object is the one that is calling this function, this represents which object.

This applies: When defining a function in a class, the function is used internally to represent the object when it is called by this function. Whenever this type of function is used within this class of objects, it is represented by this.

This is called in the constructor:
Used to invoke each other between constructors. The This function can only be placed in the first line of the function.

---------------------------------the keyword static---------------------------------------

The new memory allocation operator, the unary operator, and new is followed by a constructor that accesses what is contained in the following class through new and then allocates memory. The return value is the physical first address of the allocated memory.
Static when the static-decorated class code is loaded into the Java virtual machine, it allocates memory immediately and assigns it only once.
A static function cannot directly reference (other) non-static members of the class, but can be referenced indirectly through an object of that class. (because new does not allocate memory for non-static members at the time of the new object)

--------------------------------Keyword Final------------------------------------------

Final: Modifier.
1, you can modify the class, function, variable.
2, the final modified class can not be inherited, the purpose is to avoid being inherited, quilt class replication, perfect inheritance brought about by the encapsulation of loopholes.
3, the final modified method cannot be replicated.
4, a final modified variable can be copied only once, either to modify the member variable, or to modify the local variable. When describing things, the value of some data is fixed, then in order to enhance the reading, all of these values are given a name, which is easy to read. This value does not need to be changed, so the final modification is used. As constants: The writing specification for constants all letters are capitalized, and if it consists of multiple words, the words are connected through _. At this time, it is often added static to make it a shared data (at this point can be called directly with the class name)

Cases:
Class Demo
{
Final double pi=3.14;
final int my_age=18;
}

A collection of fragmented knowledge points in Java (subsequent additions)

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.