An explanation of the source code of the object class in Java

Source: Internet
Author: User

http://www.cnblogs.com/langtianya/archive/2013/01/31/2886572.html, Lang Tianya

 PackageJava.lang;  Public classObject {/*a local method, specifically implemented in a DLL with C (c + +), and then called through JNI. */          Private Static native voidregisternatives (); /*This method is called automatically when an object is initialized*/        Static{registernatives (); }        /*returns the run-time class for this Object. */         Public Final nativeClass<?>getclass (); /*The general agreement for Hashcode is: 1. During Java application execution, when the Hashcode method is called multiple times on the same object, the same integer must be returned consistently, provided that the information used to compare the object to equals is not modified.    The integer does not need to be consistent from one execution of an application to another execution of the same application.    2. If two objects are equal according to the Equals (object) method, calling the Hashcode method on each object in both objects must produce the same integer result. 3. If two objects are not equal according to the Equals (Java.lang.Object) method, calling the Hashcode method on either of these objects does not require that a different integer result be generated.   However, programmers should be aware that generating different integer results for unequal objects can improve the performance of the hash table. */             Public native inthashcode ();  Public Booleanequals (Object obj) {return( This==obj); }             /*The local clone method, which is used for copying objects. */        protected nativeObject Clone ()throwsclonenotsupportedexception; /*returns the string representation of the object. A very important method*/         PublicString toString () {returnGetClass (). GetName () + "@" +integer.tohexstring (Hashcode ()); }            /*wakes up a single thread waiting on this object monitor. */         Public Final native voidnotify (); /*wakes all the threads waiting on this object monitor. */         Public Final native voidNotifyall (); /*causes the current thread to wait before another thread calls this object's notify () method or the Notifyall () method.    In other words, this method behaves as if it were only executing wait (0) calls. The current thread must have this object monitor. The thread releases ownership of this monitor and waits until other threads wake up by calling the Notify method, or the Notifyall method notifies the thread waiting on this object's monitor. The thread then waits to regain ownership of the monitor before it can continue execution. */         Public Final voidWait ()throwsinterruptedexception {Wait (0); }                    /*causes the current thread to wait before another thread calls this object's notify () method or the Notifyall () method, or exceeds the specified amount of time. */         Public Final native voidWaitLongTimeoutthrowsinterruptedexception; /*The current thread waits while 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. */         Public Final voidWaitLongTimeoutintNanosthrowsinterruptedexception {if(Timeout < 0) {                 Throw NewIllegalArgumentException ("Timeout value is negative"); }                 if(Nanos < 0 | | Nanos > 999999) {                 Throw NewIllegalArgumentException ("Nanosecond timeout value out of range"); }             if(Nanos >= 500000 | | (Nanos! = 0 && Timeout = 0) ) {Timeout++;         } wait (timeout); }             /*This method is called by the object's garbage collector when the garbage collector determines that there are no more references to the object. */        protected voidFinalize ()throwsthrowable {}}
View Code

An explanation of the source code of the object class in 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.