Java.lang.Object

Source: Internet
Author: User
Tags instance method

Class object is the root of the object, and all objects (including arrays) implement the method of this class.
Method:

Modifier and type Method Description
Protect Object Clone () Create and return a copy of this object
Boolean Equals (Object obj) Determine if objects are equal
protect void Finalsize () When garbage collection determines that there is no reference to the object, the garbage collector calls the object on that object
Class <?> GetClass () Returns the run-time class for this object
Int Hashcode () Returns the hash code value of an object
void Notify () Waking a single thread that is waiting for the object monitor
void Notifyall () Wake up all threads waiting for object monitor
String ToString () Returns the string representation of an object
void Wait () Causes the current thread to wait until another thread calls the object's notify () or notify all () method
void Wait (long timeout) Causes the current thread to wait until another thread calls the object's notify () or notify all () method or the specified time has past
void Wait (long Timeout,int Nanos) Causes the current thread to wait until another thread calls the object's notify () or Notityall () method, or some other thread interrupts the current thread, or the specified time has past??? (Not very clear)

Detailed method
public boolean equals (Object obj):
Whether other objects are equal to this.
The Equals method implements an equivalence relationship on a reference to a non-empty object:

  • Reflexivity: For any non-null X, X.equals (x) returns True.
  • Symmetry: For any non-null reference x and Y, x.equals (y) should return true if and only if Y.equals (x) returns True.
  • Transitivity: For any non-null reference x, Y, and Z, if X.equals (y) and y.equals (z) return True, then X.equals (z) returns TRUE.
  • Consistency: Multiple calls to X.equals (Y) should always return TRUE or False if the value of x or Y has not been modified.
  • For any non-null reference value x, x.equals (NULL) returns FALSE.
    Protected Object Clone () throws Clonenotsupportedexception:
    Creates and returns a copy of this object. The exact meaning of "copy" may depend on the class of the object. The general intent is that for any object x, an expression:
    X.clone ()! = X
    X.clone (). GetClass () = = X.getclass ()
    X.clone (). Equals (x)
    Exception: Clonenotsupportedexception-If the class of the object does not support the Cloneable interface. Subclasses overriding the clone method can also throw this exception to indicate that the instance cannot be cloned.
    Public String toString ():
    Returns the string representation of an object. In general, the ToString method returns a string that represents the object "textually." The result should be a concise expression that is easy for people to read. It is recommended that all subclasses override this method.
    Public final void Notify ():
    Wakes a single thread that is waiting for the object monitor. If any thread is waiting for this object, one of them is selected to be awakened. The choice is arbitrary and takes place by the judgement of the implementation. The thread waits for the object's monitor by calling one of the wait methods.
    The awakened thread will not continue until the current thread discards the lock on this object. A thread that wakes up will compete with any other thread in the usual way, and these threads may be actively competing for synchronization on that object; For example, a thread that wakes up does not have a reliable permission or disadvantage in the next thread that locks the object.
    The method can only be called by a thread that is the owner of the monitor for that object.
    The thread becomes the owner of the object Monitor in one of three ways:
    By executing the synchronous instance method of the object.
    Synchronized the body of a synchronized statement on an object by executing it.
    For objects of type class, synchronize static methods by executing the class.
    Exception: Illegalmonitorstateexception-If the current thread is not the owner of the monitor for this object.
    Public final void Notifyall ():
    Wakes all threads that are waiting for the object monitor. The thread waits for the object's monitor by calling one of the wait methods. The awakened thread will not be able to continue until the current thread frees the lock on the object. A thread that wakes up will compete with any other thread in the usual way, and these threads may be actively competing for synchronization on that object; For example, a thread that wakes up does not have a reliable privilege or disadvantage in the next thread that locks the object.
    protected void Finalize () throws Throwable:
    When garbage collection determines that there is no longer a reference to the object, the garbage collector invokes the object on the object. A subclass overrides a Finalize method that processes system resources or performs other cleanup.
    The general contract for finalize is that if the Java¢ virtual machine has determined that there is no longer any method that can be accessed by any of the dead threads, the method is called unless it is a result of the action taken to finalize the preparation of other objects or classes. The Finalize method can take any action, including making this object available again to other threads; However, the usual purpose of finalize is to perform a purge action before the object is irrevocably discarded. For example, the Finalize method for an object that represents an input/output connection may break the connection by performing an explicit I/O transaction before the object is permanently discarded.
    The method object of the Finalize class performs any special operations; It just returns to normal. Object of object can override this definition.
    The Java programming language does not guarantee which thread will call the Finalize method for any given object. However, ensure that a thread that calls finalize does not hold any user-visible synchronization locks when it calls finalize. If the Finalize method throws an uncaught exception, the exception is ignored and the class of the object is terminated.
    After the Finalize method is called for the object, the Java virtual machine will take further action, including any other objects or categories that are ready to be completed, when it again determines that there is no longer any way to access this object through any of the threads that have not yet been killed, and the object can be discarded at this time.
    The Finalize method is never called more than once by any given object's Java virtual machine.
    Any exception thrown by the Finalize method will cause the object's termination to be stopped, otherwise it is ignored.

I just internship small whiteboard piece, slowly improve themselves, there are errors please God pointed out. Thank you.

Java.lang.Object

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.