How to Get Min and Max Value of Primitive Data Types in Java

Java consists of eight primitive data types which are byte, short, int, long, float, double, boolean and char. A primitive is named by a reserved keyword and is predefined by the language. Primitive values do not share state with other primitive values. We can get the min and max value of primitive data types using the below code

primitive data types

 public class MinMaxValue{
		
	    public static void main(String args[]) {
	 
	        System.out.println("byte min value = " + Byte.MIN_VALUE);
	        System.out.println("byte max value = " + Byte.MAX_VALUE);
	        System.out.println("short min value = " + Short.MIN_VALUE);
	        System.out.println("short max value = " + Short.MAX_VALUE);
	        System.out.println("int min value = " + Integer.MIN_VALUE);
	        System.out.println("int max value = " + Integer.MAX_VALUE);
	        System.out.println("long min value = " + Long.MIN_VALUE);
	        System.out.println("long max value = " + Long.MAX_VALUE);
	        System.out.println("float min value = " + Float.MIN_VALUE);
	        System.out.println("float max value = " + Float.MAX_VALUE);
	        System.out.println("double min value = " + Double.MIN_VALUE);
	        System.out.println("double max value = " + Double.MAX_VALUE);
            System.out.println("character min value = " + (int) Character.MIN_VALUE);
	        System.out.println("character max value = " + (int) Character.MAX_VALUE);
	    }
	}

output:-

byte min value = -128
byte max value = 127
short min value = -32768
short max value = 32767
int min value = -2147483648
int max value = 2147483647
long min value = -9223372036854775808
long max value = 9223372036854775807
float min value = 1.4E-45
float max value = 3.4028235E38
double min value = 4.9E-324
double max value = 1.7976931348623157E308
character min value = 0
character max value = 65535

The boolean data type has only two possible values: true and false. So using the above code we can get the min and max value of primitive data types in java.

Leave a Comment