When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it - this is knowledge. -Confucius-

Thursday, February 18, 2016

Why it's bad to use floting point numbers for equality or condition checking ?

Most of the suggestions are to avoid floating-point numbers from equality checking or in condition checking. Because small errors in the rightmost decimal places are likely to arise when calculations are performed on floating-point numbers, And two float or double values (float and double are also different) rarely are exactly equal. assume , double oneThird = 1.0 / 3.0; double x = oneThird + oneThird + oneThird; actually...

Thursday, February 11, 2016

When we need to override equals and hashcode methods in Java ?

If a class does not implement the 'equals' and 'hashcode' methods, the default implementation which inherited from the Object class will be used. equals: The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true)....