Data Types in Java: Dr. Kumud Tripathi
Data Types in Java: Dr. Kumud Tripathi
● A data type is used to indicate the type of data value stored in a variable
● There are two types of data types in Java:
1. Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and
Arrays.
Data Type Default Value Default size
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
● long is a signed 64-bit type and is useful for those occasions where an int type is not large
enough to hold the desired value.
● It is a signed 64-bit type that has a range from –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
● Example: long a = 100000L, long b = -200000L
Float Data Type
● The type float specifies a single-precision value that uses 32 bits of storage.
● Single precision is faster on some processors and takes half as much space as double precision,
but will become imprecise when the values are either very large or very small.
● It has a range from 1.4e−045 to 3.4e+038.
● Example: float f1 = 234.5f
Double Data Type
● The type double specifies a double-precision value that uses 64 bits of storage.
● Double precision is actually faster than single precision on some modern processors that have
been optimized for high-speed mathematical calculations.
● It has a range from 4.9e–324 to 1.8e+308.
● Example: double d1 = 12.3
Char Data Type