A data type is a scheme for representing values or data type defines the kind of data that is represented by a variable.
Data type represent which type of data is stored in a variable. Java data types are case sensitive.
Each Variable in Java must have certain type associated with it which tells us what kind of data a variable can store.
Classification of Data types in Java
1. Primitive Data Type
There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword.
In java Primitive data types are classified into three types
- Integer Data Type
- Floating point Data Type
- Non-Numeric Data Type
2. Non-Primitive Data Type
The data types that are derived from primary data types are known as Non-Primitive data types.
These data types are used to store group of values. Examples of Non-primitive data types are Array, structure, union, link list, stacks, queue etc.
Data types with size and range
Data type | Size (byte) | Range |
byte | 1 | -128 to 127 |
boolean | 1 | True or False |
char | 2 | A-Z, a-z, 0-9 etc |
short | 2 | -32768 to 32767 |
Int | 4 | (about) -2 million to 2 million |
long | 8 | (about) -10E18 to 10E18 |
float | 4 | -3.4E38 to 3.4E18 |
double | 8 | -1.7E308 to 1.7E308 |