...
Although Java throws a java.lang.ArithmeticException: / by zero exception for division by zero, the same issue as with C\/C++ manifests, while dividing the Integer.MIN_VALUE
by -1. It produces Integer.MIN_VALUE
unexpectedly (since the result is -(Integer.MIN_VALUE)=Integer.MAX_VALUE +1
)).
...
The shift operation in Java is quite different from C\/C++,
- The right shift is an arithmetic shift, while in C\/C++ it is implementation defined (logical or arithmetic).
- The types
boolean, float and double
cannot use the bit shifting operators.
- In C\/C++ if the value being left shifted is negative or the right-hand operator of the shift operation is negative or greater than or equal to the width of the promoted left operand, we have undefined behavior. This does not extend to Java as integer types are masked by the last 5 lower order bits of the right operand (or 0x1F). This results in a value modulo 31, inclusive.
...