DATA TYPES & VARIABLES
Data Type specifies the format, range of values and memory requirement of data that a data element can hold.
Â
Hierarchy of Data Types in Java:
- Primitive
- Integral
- Numeric
- Integer
- Byte
- Short
- Int
- long
- Decimal
- Float
- double
- Character
- Integer
-
- Boolean
- Non-Primitive
- Class
- Array
Range of Signed Values for any Data Type based on its Memory Requirement:
Minimum Value: -2(n-1)
Maximum Value: +2(n-1) – 1
Range of Unsigned Values for any Data Type based on its Memory Requirement:
Minimum Value: 0
Maximum Value: +2(n-1)
Java Primitive Data types
|
Data type |
Description |
Example |
Groups |
|
Byte |
Byte-lenth integer |
10, 24 |
Integer |
|
Short |
Short Integer |
500, 786 |
|
|
Int |
Integer |
89, 945, 37865 |
|
|
Long |
Long Integer |
89L, -945L |
|
|
Float |
Single-precision floating point |
89.5f, -32.5f |
Floating point Numbers |
|
Double |
Double-precision floating point |
89.5, -35.5, 87.6E5 |
|
|
Char |
Single Character |
‘c’, ‘9’, ‘t’ |
Characters |
|
Boolean |
Boolean value (0 or 1) |
True or False |
 Boolean |
In most of the languages, the format and size of primitive data types depend on the platform on which a code is running. But in Java programming language, size and format of its primitive data types is specified.
Integer & Floating-point numbers fall under Numeric datatypes. Â Java has six numeric datatypes that differ in size and precision of the numbers they can hold. Â The Size means how many bits are needed to represent the data type. Â The Range of a data type expresses the precision of numbers.
Four categories of Integer data types
|
Type |
Values |
Default |
Size |
Range |
|
Byte |
Signed int |
0 |
8 bits (1 byte) |
-128 to 127 |
|
Short |
Signed int |
0 |
16 bits(2 bytes) |
-32768 to 32767 |
|
Int |
Signed int |
0 |
32 bits (4 bytes) |
-2147483648 to 2147483647 |
|
Long |
Signed int |
0 |
64 bits(8 bytes) |
-9223372036854775808 to 9223372036854775807 |
Float Data types
|
Float |
IEEE 754 floating point |
0.0 |
32 bits |
+/- 1.4e-45 to +/- 3.4028235e+38, +/- infinity, +/-0, NAN |
|
double |
IEEE 754 floating point |
0.0 |
64 bits |
+/- 4.9e-324 to +/- 1.7976931348623157e+308, +/- infinity, +/-0, NAN |
Â
Â
Â
Character Data type
|
Type |
Values |
Default |
Size |
Range |
|
Char |
Unicode Character |
\u0000 |
16 bits |
\u0000 to \uFFFF |
Â
Â
Boolean data type
|
Type |
Values |
Default |
Size |
Range |
|
Boolean |
True, False |
False |
1 bit used in 32 bit integer |
NA |
Â