Java-object Source Code Analysis

Source: Internet
Author: User

The Java.lang package does not need to display the import when it is used, and is automatically imported by the compiler at compile time. The object class is the root of the class-level results, and all classes in Java inherit from this class fundamentally. The object class is the only subclass in Java that does not have a parent class. All other classes, including standard container classes, such as arrays, inherit the methods in the object class. The object class includes the following methods: (1) object (): the default constructor. (2) GetClass (): Returns the run-time class of an object. (3) Hashcode (): Returns a hash code value to the object. (4) Equals (Object obj): Determines whether an object obj is equal to this object. (5) Clone (): Creates and returns a copy of this object. (6) toString (): Returns the string that is converted to 16 by the class name and by the hashcode value. (7) Notify (): Wakes up a single thread waiting on this object monitor. (8) Notifyall (): Wakes up all the threads waiting on this object monitor. (9) Wait (): Causes the current thread to wait until other threads call the Notify () method of this object or the Notifyall () method. Wait (long timeout) causes the current thread to wait until another thread calls the Notify () method of this object or notify (), or exceeds the specified amount of time. (one) Wait (long Timeout,int Nanos): Causes the current thread to wait until another thread calls the Notify () method of this object or the Notifyall () method, or some other thread interrupts the current thread, or has exceeded an actual amount of time.registernatives (): Static method, several local methods are registered, some of the above functions are local methods.

Based on the Java8 object source code:

Public classObject {private static native voidregisternatives();Static{registernatives();    }Public Final nativeClass<?>GetClass();public native inthashcode();Public Booleanequals(Object obj) {return( This= = obj);    }protected nativeObjectClone()throwsClonenotsupportedexception; PublicStringtoString() {returnGetClass (). GetName () +"@" + Integer.tohexstring(Hashcode ());    }Public final native voidNotify();Public final native voidNotifyall();Public final native voidwait(LongTimeoutthrowsInterruptedexception;Public final voidwait(LongTimeout, intNanosthrowsinterruptedexception {if(Timeout <0) {throw NewIllegalArgumentException ("Timeout value is negative");        }if(Nanos <0|| Nanos >999999) {throw NewIllegalArgumentException ("nanosecond timeout value out of range");        }off(Nanos >=500000|| (Nanos! =0&& Timeout = =0)) {timeout++;        } Wait (timeout);    }Public final voidwait()throwsinterruptedexception {Wait (0);    }protected voidFinalize()throwsThrowable {}}

Copyright Notice: Knowledge is to share, technology lies in communication, please leave a blogger's link on the reprint.

Java-object Source Code Analysis

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.