There are eight primitive data types in Java. They are:
- boolean: This supports only two values true and false. This type is used for true/false conditions.
- byte: Represents 8 bit integer. It is useful while handling large arrays of numbers, as the memory usage is minimal.
- short: Represents 16 bit integer.
- int: Represents 32 bit integer.
- long: Represents 64 bit integer.
- float: Represents 32 bit single precision floating point.
- double: Represents 64 bit double precision floating point
- char: Represents a single Unicode character. Its size is 16 bits.
| Data Type | Default Value (for fields) | Size (bits) | Range |
|---|---|---|---|
| boolean | false | Not defined | true/false |
| byte | 0 | 8 | -128 to 127 |
| short | 0 | 16 | -32,768 to 32,767 |
| int | 0 | 32 | -2,147,483,648 to 2,147,483,647 |
| long | 0L | 64 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| float | 0.0f | 32 | Details coming up in a separate post. |
| double | 0.0d | 64 | Details coming up in a separate post. |
| char | '\u0000' | 16 | '\u0000' to '\uffff' |
Of these types,
char and boolean are not numeric. The rest are numeric in nature.
Primitive data types are not dependent on any external libraries for usage. This is because they are built into the language itself.
No comments:
Post a Comment