2017  Kodetalk | Feedback | Privacy Policy | Terms | About

What will happen if the expression 1.0 / 0.0 will execute?

What does the the expression 1.0 / 0.0 will execute?

Will it throw any Exception or will give compile time error?

Java developer knows about double primitive type and Double class. But while doing floating point arithmetic they don't pay enough attention to Double.INFINITY, NaN, and -0.0 and other rules that govern the arithmetic calculations involving them. The answer is, will not throw ArithmeticExcpetion and return Double.INFINITY. Also note that the comparison x == Double.NaN always evaluates to false, even if x itself is a NaN. To test if x is a NaN, one should use the method call Double.isNaN(x) to check if given number is NaN or not.
Answer is