Initialization and cleanup of Java

Source: Internet
Author: User

this keyword
think in Java: the This keyword can only be used inside a method, representing a reference to the "that object that called the method". Usually this when written, it refers to this object or the current object.
Usage
1. Distinguish the variable with the same name 2. Returns a reference to its own Class 3. Call another constructor in one of the constructor functions of the current class
Code
 Public classUser {intA; User () { This(0);//distinguishing variables with the same name} User (inta) {         This. A = A;//calling a construction method in a constructor method    }     PublicUser GetUser () {return  This;//returns a reference to its own class    }}
Note: 1. Only one construction method can be called, and the call action is placed at the top 2. Constructor method cannot be called in another method

Initialization
order (when creating an object): 1. Static variable, static method 2. Member variable, member Method 3. Constructor static variable initialization: 1. When you create an object (New keyword) 2. When you access the object's static data (class.staticdate)
Array
The
array is class, so when we want to use it, we need to initialize it with the New keyword and create a reference.
New= {Type,type};
Arrayname is a reference to the type[] array object.
Variable parameter list
A method can have only one variable-length parameter, and the variable-length parameter must be the last parameter of the method
 Public class TestClass {    publicstaticvoid  getString (String ... args) {          for (String X:args) {            + "\ T");}    }      Public Static void Main (string[] args) {        getString ("Hello", "world", "haha");}    } Out:hello    World    haha
Clean
after watching the garbage cleanup and then write
Refence

http://alexyyek.github.io/2015/01/03/initial/

Initialization and cleanup of Java

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.