Example:
int x = 10;- The variable
xis stored in the stack. - The value
10is also in the stack.
Java data types define the kind of data a variable can hold and how memory is allocated. Learn about primitive types, reference types, and memory storage.
Data types in Java are broadly categorized into:
Primitive types store the actual value directly in the stack memory.
Example:
int x = 10;x is stored in the stack.10 is also in the stack.✔ Primitive = store REAL value in stack
Non-primitive types store a reference in the stack, but the actual object is stored in the heap memory.
Example:
String name = new String("John");Memory behavior:
name → stored in stackname stores a reference to the heap object.✔ Non-primitive = stack holds reference, heap holds actual object

Java has eight primitive data types. They store single values directly and are stored in stack memory.
| Type | Description | Default | Size | Example | Range |
|---|---|---|---|---|---|
| boolean | Logical values | false | 1 byte (JVM dependent) | true, false | — |
| byte | 8-bit signed integer | 0 | 1 byte | 10 | -128 to 127 |
| char | 16-bit Unicode character | \u0000 | 2 bytes | 'A', '\u0041' | 0 to 65,535 |
| short | 16-bit signed integer | 0 | 2 bytes | 2000 | -32,768 to 32,767 |
| int | 32-bit signed integer | 0 | 4 bytes | 1000, -500 | -2,147,483,648 to 2,147,483,647 |
| long | 64-bit signed integer | 0L | 8 bytes | 123456789L | ±9.22e18 |
| float | 32-bit floating point | 0.0f | 4 bytes | 3.14f | ~6–7 digits precision |
| double | 64-bit floating point | 0.0d | 8 bytes | 3.14159d | ~15–16 digits precision |