Java Primitive Data Types

506


There are 8 Primitive data types in Java, you can categorize them into 4 groups.

  1. Integer data types: byte, short, int & long
  2. Floating Data types: float, double
  3. Character Data types: char
  4. Boolean Data types: boolean
Data TypeSizeDefault ValueRange
byte8-bit0-128 to 127
short16-bit0-32,768 to 32,767
int32-bit0-2^31 to 2^31-1
long64-bit0L-2^63 to 2^63-1
float32-bit0.0f
double64-bit0.0d
booleanNA'\u0000'NA
char16-bitfalseNA

Following is a sample program with using all primitive datatypes

public class PrimiteDataTypes {

	public static void main(String[] args) {

		byte byteVal = 127;
		short shortVal = 32767;
		int intValue = 2147483647;
		long longValue = 9223372036854775807L;

		float floatValue = 1.5F;
		double doubleVaue = 12.678;

		char charValue = 'f';

		boolean booleanValue = true;

	}
}