V. Initialization and cleanup

Source: Internet
Author: User

When creating an object, if its class has a constructor, Java will automatically invoke the appropriate constructor before the user has the ability to manipulate the object, guaranteeing initialization.

Second, each overloaded method must have a unique list of parameter types

If the incoming data type is less than the formal parameter type declared in the method, the actual data type is promoted.

If the type of data passed in is large, the narrowing conversion is performed by type conversion.

Third, if there are no constructors in the written class, the compiler will automatically help you create a default constructor.

The This keyword can only be used inside a method, representing a reference to the "object that called the method"

The This keyword can also be used to pass the current object to another method

Use this to invoke another constructor in one constructor, except inside the constructor, where the compiler prohibits invoking the constructor in any other method, and the constructor call must be placed at the very beginning.

The static method is a method that does not have this, and the non-static method cannot be called inside the static method.

V. 1. Objects may not be garbage collected

2. Garbage collection is not equal to "destruction"

3. Garbage collection is only memory-related

Java allows you to define a method called Finalize () in a class to clean up memory: Once the garbage collector is ready to release the storage space occupied by the object, it is called first, and the memory consumed by the object is actually reclaimed when the next garbage collection action occurs, but use this method sparingly.

Java virtual machines will adopt an adaptive garbage collection technology, i.e. stop-copy and tag-sweep (<java > p90-91)

Vi. If a domain is a static base type field and does not initialize it, then he will get the standard initial value of the base type, and if he is an object reference, his default initializer is null

The order of initialization is the first static object, then the non-static object, and the initialization of the static object is performed only once.

Java allows multiple static initialization actions to be organized into a special "static clause"

Vii. array Initialization int[] A1 or int a2[]

The Arrays.tostring () method belongs to the Java.util Standard class library, which produces a printable version of an array.

Variable parameter list: object[] args or Integer ... args, etc.

Variable parameter list and automatic packing mechanism can live in harmony

Viii. creating enum types with Enums

When an enum is created, the compiler automatically adds some useful attributes that automatically create the ToString () method, which displays the name of the instance and the ordinal () method used to denote the order of declarations of an enum constant

V. Initialization and cleanup

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.