Data Types in Java
There are two kinds of data types in java:-
- Primitives/standard data types
- Abstract/derived data types
Primitive Data Types
Primitive data types (also know as standard data types) are the data types that are built into the Java language. The Java compiler holds details instructions on each operation the data types that are built into the Java language.
The Java compiler holds detailed instructions on each legal operation the data type supports. There are eight primitive data types in Java.
|byte||8||Byte-length integer||-128 to 128 (signed)|
0 to 255 (unsigned)
|short||16||Short integer||-215 to 215 -1|
|int||32||integer||-231 to 231 -1|
|long||64||Long integer||-263 to 263 -1|
|+/- about 10 317|
|+/- about 1039|
|char||16||A single character|
|Boolean||1||A boolean value|
(true or false)
The data types – byte, short, int, long, float and double are numeric data types. The first four of these can hold only whole numbers whereas the last two (float and double) can hold decimal values like 5.05.
All these data types can hold negative values. However, the keyword unsigned can be used to restrict the range of values to positive numbers.
Among-st others, boolean can hold the value true or false and char can hold only a single character.
Abstract/Derived Data Types
Abstract data types are based on primitives data types and have more functionality that the primitive data types.
For example, String is an abstract data type that can store alphabets, digits and other characters like /, (); :$#.
You can’t perform calculations on a variable of the string data type even if the data stored in it has digits.