Min and Max Value of Primitive Types in Java




There are seven primitive types in java. They are byte , short, char, int, long, float and double.
Every Primitive type in java has corresponding Wrapper class.e.g.

Wrapper class of byte = java.lang.Byte
Wrapper class of short = java.lang.Short
Wrapper class of char = java.lang.Character
Wrapper class of int = java.lang.Integer
Wrapper class of long = java.lang.Long
Wrapper class of float = java.lang.Float
Wrapper class of double = java.lang.Double

Each of these Wrapper classes has MIN_VALUE and MAX_VALUE which are public , static and final. This variable is of primitive type only.

Demo Program to Illustrate MIN_VALUE and MAX_VALUE of Primitive Types in Java

package com.masterjavatutorial;
public class TestExample {
	
	public static void main(String[] args){

		byte minValueOfByte = Byte.MIN_VALUE; 
		byte maxValueOfByte = Byte.MAX_VALUE; 
		
		System.out.println("Min Val of Byte = "+minValueOfByte);
		System.out.println("Max Val of Byte = "+maxValueOfByte);

		short minValueOfShort = Short.MIN_VALUE; 
		short maxValueOfShort = Short.MAX_VALUE; 
		
		System.out.println("Min Val of Short = "+minValueOfShort);
		System.out.println("Max Val of Short = "+maxValueOfShort);

		int minValueOfChar = Character.MIN_VALUE; 
		int maxValueOfChar = Character.MAX_VALUE; 
		
		System.out.println("Min Val of Char = "+minValueOfChar);
		System.out.println("Max Val of Char = "+maxValueOfChar);

		int minValueOfInteger = Integer.MIN_VALUE; 
		int maxValueOfInteger = Integer.MAX_VALUE; 
		
		System.out.println("Min Val of Integer = "+minValueOfInteger);
		System.out.println("Max Val of Integer = "+maxValueOfInteger);

		long minValueOfLong = Long.MIN_VALUE; 
		long maxValueOfLong = Long.MAX_VALUE; 
		
		System.out.println("Min Val of Long = "+minValueOfLong);
		System.out.println("Max Val of Long = "+maxValueOfLong);

		float minValueOfFloat = Float.MIN_VALUE; 
		float maxValueOfFloat = Float.MAX_VALUE; 
		
		System.out.println("Min Val of Float = "+minValueOfFloat);
		System.out.println("Max Val of Float = "+maxValueOfFloat);

		double minValueOfDouble = Double.MIN_VALUE; 
		double maxValueOfDouble = Double.MAX_VALUE; 
		
		System.out.println("Min Val of Double = "+minValueOfDouble);
		System.out.println("Max Val of Double = "+maxValueOfDouble);
		
	}
			
}

Output of the above Program is as below:

Min Val of Byte = -128
Max Val of Byte = 127
Min Val of Short = -32768
Max Val of Short = 32767
Min Val of Char = 0
Max Val of Char = 65535
Min Val of Integer = -2147483648
Max Val of Integer = 2147483647
Min Val of Long = -9223372036854775808
Max Val of Long = 9223372036854775807
Min Val of Float = 1.4E-45
Max Val of Float = 3.4028235E38
Min Val of Double = 4.9E-324
Max Val of Double = 1.7976931348623157E308