1 · Foundations · lesson 3 of 41
Variables & Primitive Types
Eight primitive types, one reference world, and why the difference matters.
Java has 8 primitive types stored directly on the call stack, and reference types whose values live on the heap while a reference to them sits on the stack.
Java
int age = 27; // 32-bit integer
long views = 9_000_000L; // 64-bit integer
double pi = 3.14159; // 64-bit float
float ratio = 0.5f; // 32-bit float
boolean ready = true;
char grade = 'A';
byte flag = 0x1F;
short port = 8080;
String name = "Ada"; // reference typeTIP
The 3D visualization shows stack frames on the left with primitives inline, and objects on the heap with arrows from stack references.
Loading 3D scene…
Key takeaways
- ✓8 primitives: byte, short, int, long, float, double, boolean, char.
- ✓Primitives store the value; references store an address to a heap object.
- ✓Use _ as a digit separator for readable large numbers.