The object class of Java

Source: Internet
Author: User

Object class :

The direct or indirect superclass of all classes at the highest point in the class hierarchy

Contains the public properties of all Java classes

the main methods of the object class are :

Public final class GetClass () Gets the information of the class to which the current object belongs, returning the class object;

The public string toString () returns a String object that represents information about the current object itself;

public boolean equals (Obeject obj) compares two object references to the same object, returns Ture, and returns flase;

Protected Object Clone () copies the current object and returns the copy (copy of the object)

public int hashcode () returns the hash code value of the object

protected void Finalize () throws Throwable performs the resource release work of the normally completed object when the object is reclaimed;

equal and same :

Two objects have the same type, and the same property values, are said to be equal (equal).

If two reference variables point to the same object, the two reference variables are called the same

Two objects are the same, they must be equal

Two objects are equal, not necessarily the same.

The comparison operator "= =" Determines whether the two objects are the same; (determines whether two references point to the same object)

Hashcode Method :

Hashcode is a method of returning an object hash code;

During one execution of a Java program, if the information used by the object "Equality comparison" is not modified, the same object should return the same integer each time the Hashcode method is executed. In different executions, the Hashcode method return value of the object does not have to be consistent (not the same execution, the object's hashcode is not necessarily the same)

If two objects are equal according to the Equals method, calling the Hashcode method on both objects should return the same integer result

If the two objects that follow the Equals method do not want to wait, the return value of the Hashcode method is not required to be called on both objects.

As long as the implementation is reasonable, the object class defines the Hashcode method to return different integers for different objects, a typical implementation is to convert the object's internal address to an integer return, but the Java language does not require this to be implemented;

Clone method :

Used to construct a new object based on an existing object, that is, to copy the object.

To assign a value object using the Clone method:

Overriding the Clone method: is defined as protected in the Obejct class, so it needs to be overwritten as public. (The internal properties of each object class are different, so it is necessary to overwrite) to implement the Cloneable interface;

Finalize Method :

The system automatically calls the Finalize method of the object before it is reclaimed by the garbage collection period;

If you want to overwrite the Finalize method, you must call Super.finalize at the end of the overriding method.

GetClass Method :
The final method, which returns a class object that is used to bring the classes to which the object belongs;

Through the class object, you can query the classes of various information: such as name, superclass, implement the name of the interface;

Notify, Notifyall, and Wait methods :

Final method, can not be overwritten, these three methods are mainly used in multi-threaded programs;

The object class of Java

Related Article

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.