In Java, a data type determines the type and size of values that can be stored in variables. Here are some useful data type keywords in Java along with their descriptions and examples:
Data Type | Description | Example |
---|---|---|
int | Represents integer values (whole numbers) within a specific range. | int age = 25; |
double | Represents decimal or floating-point values with higher precision compared to float. | double salary = 5000.50; |
boolean | Represents a logical value that can be either true or false. | boolean isStudent = true; |
char | Represents a single character enclosed in single quotes. | char grade = 'A'; |
String | Represents a sequence of characters. | String name = "John Smith"; |
float | Represents decimal or floating-point values with lower precision compared to double. | float pi = 3.14f; |
long | Represents large integer values that exceed the range of int. | long population = 7823476932L; |
byte | Represents a small integer value. | byte flags = 3; |
short | Represents a small range of integer values. | short temperature = -10; |
Array | Represents a collection of elements of the same type, stored in contiguous memory locations. | int[] numbers = {1, 2, 3, 4, 5}; |
Below you can check the summary of Java data type and its size,range, wrapper class along with default value.
Data Type
Size (in bytes)
Range
Wrapper Class
Default Value
byte
1
-128 to 127
Byte
0
short
2
-32,768 to 32,767
Short
0
int
4
-2,147,483,648 to 2,147,483,647
Integer
0
long
8
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Long
0L
float
4
Approximately ±3.40282347E+38F
Float
0.0F
double
8
Approximately ±1.79769313486231570E+308
Double
0.0
char
2
0 to 65,535
Character
'\u0000'
boolean
1
true or false
Boolean
false
Prev‹
›Next