Explain the difference between primitive and reference data types.

Beginner

Answer

Primitive types store actual values directly in memory and include: byte, short, int, long, float, double, boolean, char. They are stored on the stack and have fixed memory allocation.
Reference types store references (memory addresses) to objects located in heap memory. Examples include classes, interfaces, arrays, and enums. When you assign a reference variable, you're copying the reference, not the actual object.

int x = 10; // primitive - stores value 10
String str = "Hello"; // reference - stores memory address of String object