Java .

Java Object


General Notes

1. Every Class extends Object
2. You can not store a primitive in an Object variable.
Object objStringFive = new String("5");    
  //this works.
Object objDoubleFive = new Double("5");    
  //this works.

int fiver = 5; Object objFive = fiver; //this will not compile. Object anotherObjFive = 5; //this will not compile.

Object methods most used

Object cloneOfObject = 

boolean isEqual = objectToCompare.equals(objectToCompareTo);

Class runtimeClass = objectToGetClassFrom.getClass();

int hashCodeOfObject = objectToGetHashCodeOf.hashCode();

String stringValue = objectToGetStringOf.toString();

Object methods for threads

  //wakes up current thread

objectWithThreadWaiting.notifyAll(); //wakes up all threads

objectToMakeThreadWait.wait(); //current thread goes to sleep until notify() or notifyAll()

objectToMakeThreadWait.wait (longTimeToWaitInMilliseconds); //current thread goes to sleep until notify(), // notifyAll(), or longTimeToWaitInMilliseconds elapses

objectToMakeThreadWait.wait( longTimeToWaitInMilliseconds, intTimeToWaitInNanoseconds); //current thread goes to sleep until notify(), // notifyAll(), or longTimeToWaitInMilliseconds + // intTimeToWaitInNanoseconds elapses

Object method for garbage collection

  //called by garbage collector when no more 
  //  object references exist


The Java 2 Platform Specification
Thinking in Java by Bruce Eckel
Core Java (TM) 2 Volume 1 - Fundamentals by Cay Horstmann and Gary Cornell
Sign in to be the first to comment on Java Object.