Ads Sponsored By Google :)

Sunday, 13 January 2013

java.lang.object|object class api|methods of|in java


object class api in java class object in java object class in java methods of object class in java object class methods in java class object in java java.lang.object class java.lang.object api java.lang.object methods


Object Class (or) Super class for all classes in java (or) java.Lang.Object:
       Java.Lang.Object is the super class of all classes in java. Why it is super class for all classes in java, because it contains some methods such as Finalize(), toString() etc….. , these methods providing common functionality for all classes. For that Java.Lang.Object was designed as super class for  all classes in java.

The Following are the methods in Java.Lang.Object Class:

1)      private static native void registerNatives():
Returns the runtime class of this Object. The returned object is the object that is locked by  static synchronized methods of the represented class.

2)      public final native Class<?> getClass():

3)      public native int hashCode():                                                                                                                                       Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by  java.util.HashMap.

4)      public boolean equals(Object obj) //Contains Definition:                                                                                                                                                       Indicates whether some other object is "equal to" this one.

5)      protected native Object clone() throws CloneNotSupportedException:
6)      public String toString(): 
              Returns a string representation of the object. In general, the method returns a string that "textually represents" this object.

7)      public final native void notify():
8)      public final native void notifyAll():
9)      public final void wait(long timeout, int nanos) throws InterruptedException //contains  Definition:

            The above 7,8,9 would briefly in multi threading.

10)   protected void finalize() throws Throwable //contains Definition:
          This is most useful method in Java.lang.Object Class because it used to un reference the referenced variables and datamembers in class. it acts like a garbage collector.

    Inner code Of Java.Lang.Object Class Api or Object Class Api :
      package java.lang; // this is hierarchy of Object Class.

   public class Object {
     private static native void registerNatives(); // Returns the runtime class of this {@code Object}. The     
         //returned  object is the object that is locked by  static synchronized methods of the represented class.
      static {
                 registerNatives();
                }
     public final native Class<?> getClass();
     public native int hashCode(); 
     public boolean equals(Object obj) {
                    return (this == obj);
                }
    protected native Object clone() throws CloneNotSupportedException;
    public String toString() {
                       return getClass().getName() + "@" + Integer.toHexString(hashCode());
                 }
   public final native void notify();
   public final native void notifyAll();           
   public final native void wait(long timeout) throws InterruptedException;
   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++;
                 }

       }

No comments:

Post a Comment

LinkWithin