How does Java handle integer overflows and underflows?Java does not handle integer overflows and underflows. The values will be wrap around by adding 1 to the maximum values of a primitive data type, which returns the minimum value.
For example, the declaration byte bNumber=129 returns -127.How does Java handle integer overflows and underflows?- If a type exceeds a range of a type, it results in an overflow. - In case of an overflow, java uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
|