int rollno = 101; // 'int' is a data type for integers
float marks = 91.4f; // 'float' is for decimal values
char grade = 'A'; // 'char' is for single characters
Primitive data types are pre-defined, basic building blocks in Java, representing fixed-size simple values like integers, decimals, or characters. Example: int rollno = 101;.
We have explained the primitive data types in points as below :-
int rollno = 101;
int number = 123; // Allocates 4 bytes for storage.
char letter = 'A'; // Allocates 2 bytes for a Unicode character.
float price = 19.99f; // Allocates 4 bytes for a decimal value.
Data Type | Default Size | Default Value | Range | Corresponding Wrapper Classes |
---|---|---|---|---|
boolean | 1 bit (not precisely defined) |
false | true or false | Boolean |
char | 2 bytes (16 bits) |
'\u0000' | 0 to 65,535 (Unicode) | Character |
byte | 1 byte (8 bits) |
0 | -128 to 127 | Byte |
short | 2 bytes (16 bits) |
0 | -32,768 to 32,767 | Short |
int | 4 bytes (32 bits) |
0 | -2,147,483,648 to 2,147,483,647 | Integer |
long | 8 bytes (64 bits) |
0L | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | Long |
float | 4 bytes (32 bits) |
0.0f | Approximately ±3.40282347E+38F | Float |
double | 8 bytes (64 bits) |
0.0d | Approximately ±1.79769313486231570E+308 | Double |
byte smallNumber = 200; // Error: 200 exceeds the byte range of -128 to 127.
Click Here to read Non-Primitive Data Types deeply.
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
We’re here to make our tutorials better based on your thoughts and suggestions.