Data types are used for representing the data in main memory of the computer.
In JAVA, we have eight data types which are organized in four groups. They are integer category data types, float category data types, character category data types and Boolean category data types.
These are used to represent integer data. This category of data type contains four data types which are given in the following table:
S.no | Data Types | size(bites) | Range |
---|---|---|---|
1 | Byte | 1 | +127 to -128 |
2 | Short | 2 | +32767 to -32768 |
3 | Int | 4 | +2147483647 to -2147483648 |
4 | Long | 8 | ±9.223*1018 |
Whatever the data type we use that should not exceed predefined value.
Note:
Range of any data type = (A)number of bits occupied by a data type Where, A = number of bits available in the language which is understand by computer i.e., 2 bits.
For example:
Range of byte = 28
= 1 to 256
= 0 to 255
= 0 to (255/2)
= (127.5 - 0.5 = +127) (127.5 + 0.5 = -128)
Float category data types are used for representing the data in the form of scale, precision i.e., these category data types are used for representing float values. This category contains two data types; they are given in the following table:
S.no | Data Types | size(bites) | Range | Number of Decimal places |
---|---|---|---|---|
1 | Float | 4 | +2147483647 to -2147483648 | 8 |
2 | Double | 8 | ±9.223*1010 | 16 |
Whenever we take any decimal constant directly in a JAVA program it is by default treated as highest data type in float category i.e., double.
A character is an identifier which is enclosed within single quotes.
In JAVA to represent character data, we use a data type called char. This data type takes two bytes since it follows UNICODE character set.
S.no | Data Types | size(bites) | Range | Number of Decimal places |
---|---|---|---|---|
1 | Char | 2 | +32767 to -32768 | 8 |
JAVA is available in 18 international languages and it is following UNICODE character set.
UNICODE character set is one which contains all the characters which are available in 18 international languages and it contains 65536 characters.
Boolean category data type is used for representing logical values i.e., TRUE or FALSE values.
To represent logical values we use a keyword called Boolean.
This data type takes 0 bytes of memory space.
Note:
All keywords in JAVA must be written in small letters only.