This tutorial covers Java data types. For the continued discussion, see Part 2.
Primitive Data Types
Java has eight primitive data types:
| Type | Size | Range / Description |
|---|---|---|
| byte | 1 byte | -128 to 127 |
| short | 2 bytes | -32,768 to 32,767 |
| int | 4 bytes | -2,147,483,648 to 2,147,483,647 |
| long | 8 bytes | Very large integers |
| float | 4 bytes | Decimal numbers (single precision) |
| double | 8 bytes | Decimal numbers (double precision) |
| char | 2 bytes | Single character (Unicode) |
| boolean | 1 bit | true or false |
Reference Data Types
Reference types include classes, interfaces, and arrays. The most commonly used reference type is String. Unlike primitives, reference variables store the memory address of the actual data.
String name = "LankaTricks";
int[] numbers = {1, 2, 3, 4, 5};
Next: Java Data Types Part 2 | Related: Wrapper Classes