Java-Object source code analysis, java-object source code

Source: Internet
Author: User

Java-Object source code analysis, java-object source code
Come to the end of the paper, and never know how to do this-Lu YouWenqu that clear such, for the source of live water to Zhu Xi

The java. lang package does not need to be displayed for import during use. The Compiler automatically imports the package during compilation. The Object class is the root of the Class-level result. All classes in Java basically inherit from this class. 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 (): default constructor. (2) getClass (): returns the runtime class of an object. (3) hashCode (): A hash code value returned to the object. (4) equals (Object obj): determines whether an Object obj is equal to this Object. (5) clone (): Create and return a copy of this object. (6) toString (): returns a string converted from the class name and hashCode value to a hexadecimal value. (7) Wake y (): Wake up a single thread waiting on this object monitor. (8) yyall (): Wake up all threads waiting on this object monitor. (9) wait (): causes the current thread to wait until other threads call the notify () method or notifyAll () method of this object. (10) wait (long timeout) causes the current thread to wait until other threads call the notify () method or notify () of this object, or exceed the specified time. (11) wait (long timeout, int nanos): causes the current thread to wait until other threads call the notify () method or yyall () method of this object, or another thread breaks the current thread, or the actual time has exceeded. (12) registerNatives (): static method. Register several local methods. Some of the above functions are local methods.

Java 8-based Object source code:

Public class Object {private static native void registerNatives (); // register the local method static {registerNatives ();} public final native Class <?> GetClass (); // return the runtime class of the Object public native int hashCode (); // call the local method to obtain the hashCode value. The result is the Object address public boolean equals (Object obj) {// determine whether the addresses of the two objects are the same return (this = obj);} protected native Object clone () throws CloneNotSupportedException; // clone public String toString () of the local method () {return getClass (). getName () + "@" + Integer. toHexString (hashCode (); // class name and hex hash value} public final native void y (); // wake up a single thread in a local way public Final native void policyall (); // The local method wakes up multiple threads public final native void wait (long timeout) throws InterruptedException; // The local method thread waits for public final void wait (long timeout, int nanos) throws InterruptedException {if (timeout <0) {throw new IllegalArgumentException ("timeout value is negative ");} if (nanos <0 | nanos> 999999) {throw new IllegalArgumentException ("nanosecond timeout value out of range" );} If (nanos> = 500000 | (nanos! = 0 & timeout = 0) {timeout ++;} wait (timeout);} public final void wait () throws InterruptedException {wait (0 );} protected void finalize () throws Throwable {} // System. this function will be executed during gc runtime}

Copyright Disclaimer: knowledge is shared, and technology is for communication. Leave a blogger's link for reprinting.

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.