There are 8 Primitive data types in java :
1.Boolean:
A boolean datatype can store either True or False.
2.Char:
The character datatype stores a single character.
3.byte:
It is an 8-bit signed two's complement integer. it
stores whole numbers ranging from -128 to 127.
4.int:
An Integer type stores an integer number with no fractional or
decimal places. Java has four integer types -byte, short, int,
and long.
5.Short:
Short is a 16-bit signed two's complement integer. it stores
whole numbers with values ranging from -32768 to 32767.
its default value is 0.
Syntax: short shortVariable;
6.long:
long is a 64-bit signed two's complement integer that stores
values ranging from -9223372036854775808 to 9223372036854775808
it is used when we need a range of values more than those
provided by int. its default value is 0L.this data type ends
with 'L' or 'l'.
Syntax: long longVariable;
7.float:
It is a floating point datatypes that stores the values,
including their decimal precision. it is not used for precise
data such as currency or research data.
it is single-precision 32-bit or 4bytes
default value = 0.0f
ends with an 'f' or 'F'
Can have a 7-digit decimal precision
Syntax: float floatVariable;
8.double:
The double datatype is similar to float. the difference
between the two is that is double twice the float in the
case of decimal precision. it is used for decimal values
just like float and should not be used for precise values.
can have a 15-digit decimal precision.
it is a double-precision 64-bit or 8bytes
default value=0.0d
Syntax: double doubleVariables;
Top comments (0)