Every variable in java must be supposed as the specified datatype.
And these data types are classified into two types.
Primitive Datatypes
Non-Primitive Datatypes.
Primitive DataTypes:
Primitive DataTypes tells us the size and type of variable values.
Primitive datatypes mainly include datatypes such as :
byte
short
int
long
float
double
boolean
char
1 Byte
is equal to8 bits
DataType | Size | Ranges From |
byte | 1 byte | ranges from -128 to 127. |
short | 2 bytes | ranges from -32,768 to 32,767. |
int | 4 bytes | ranges from 2,147,483,648 to 2,147,483,647. |
long | 8 bytes | ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. |
float | 4 bytes | stores the fractional numbers. |
double | 8 bytes | stores the fractional numbers. |
boolean | 1 bit | stores true or false values. |
char | 2 bytes | stores a single character/ ASCII values. |
Non-Primitive DataTypes:
Strings
Arrays
Classes
Example:
int number = 5; // Integer (whole number)
float floatNumber = 5.99f; // Floating point number
char letter = 'D'; // Character
boolean choice = true; // Boolean
String text = "Hello"; // String
ย