Useful Java Classes

Object Class

public boolean equals (Object obj)

This is comparing the references (though we can customize the equal() function if we want..).

Sphere s1 = new Sphere(2.0);
Sphere s2 = s1;
Sphere s3 = new Sphere(2.0);

s1.equals(s2) <- returns true
s1.equals(s3) <- returns false even though they are both defined in the same way.


public void finalize()

For destroying objects: The garbage collector calls this finalize() method to determine whether there are more references to the object.


public int hashCode()

Returns the hash code (a unique value) for the object as an integer.


public String toString()

Returns a textually represnted string of the object. ==> ClassName@#hashcode