English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Each data type in Java has a minimum and maximum range, such as Integer.
Minimum = -2147483648 Maximum = 2147483647
Assuming for Integer, if the value exceeds the maximum range shown above, it will cause an overflow. However, if the value is less than the minimum range shown above, it will cause underflow.
The following program displays the limits of data types in Java.
public class Demo { public static void main(String[] args) { System.out.println("Limits of primitive DataTypes"); System.out.println("Byte Datatype values..."); System.out.println("Min = ", + Byte.MIN_VALUE); System.out.println("Max = ", + Byte.MAX_VALUE); System.out.println("Short Datatype values..."); System.out.println("Min = ", + Short.MIN_VALUE); System.out.println("Max = ", + Short.MAX_VALUE); System.out.println("Integer Datatype values..."); System.out.println("Min = ", + Integer.MIN_VALUE); System.out.println("Max = ", + Integer.MAX_VALUE); System.out.println("Float Datatype values..."); System.out.println("Min = ", + Float.MIN_VALUE); System.out.println("Max = ", + Float.MAX_VALUE); System.out.println("Double Datatype values..."); System.out.println("Min = ", + Double.MIN_VALUE); System.out.println("Max = ", + Double.MAX_VALUE); } }
Output Result
Limits of primitive DataTypes Byte Datatype values... Min = -128 Max = 127 Short Datatype values... Min = -32768 Max = 32767 Integer Datatype values... Min = -2147483648 Max = 2147483647 Float Datatype values... Min = 1.4E-45 Max = 3.4028235E38 Double Datatype values... Min = 4.9E-324 Max = 1.7976931348623157E308
In the above program, we get each data type one by one and use the following properties to get the minimum and maximum values. For example, the data type is Byte.
Byte.MIN_VALUE; Byte.MAX_VALUE
The above code returns the minimum and maximum values of the Byte data type. Similarly, it applies to other data types.
Min = -128 Max = 127