1. Every Class extends Object
2. You can not store a primitive in an Object variable.
. Java . Java Object
Java Object
java.lang.Object
General Notes
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 = objectToClone.clone();
boolean isEqual = objectToCompare.equals(objectToCompareTo);
Class runtimeClass = objectToGetClassFrom.getClass();
int hashCodeOfObject = objectToGetHashCodeOf.hashCode();
String stringValue = objectToGetStringOf.toString();
Object methods for threads
objectWithThreadWaiting.notify(); //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
objectForGarbageCollection.finalize(); //called by garbage collector when no more // object references exist
References
| Comments |
| Sign In |
| to add the first comment for Java Object. |