Display the minimum and maximum value of primitive data types in Java


Every data type in Java has a minimum as well as maximum range, for example, for Float.

Min = 1.4E-45
Max = 3.4028235E38

Let’s say for Float, if the value extends the maximum range displayed above, it leads to Overflow.

However, if the value is less than the minimum range displayed above, it leads to Underflow.

The following is the Java Program to display the minimum and maximum value of primitive data types.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      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);

      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);
   }
}

Output

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
Byte Datatype values...
Min = -128
Max = 127
Short Datatype values...
Min = -32768
Max = 32767

In the above program, we have taken each datatype one by one and used the following properties to get the minimum and maximum values. For example, datatype Short.

Short.MIN_VALUE;
Short.MAX_VALUE

The above returns the minimum and maximum value of Short datatype. In the same way, it works for other datatypes.

Min = -32768
Max = 32767

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements