There are 2 types of variables in Java, namely primitive & reference.
Primitive-type variables are always stored inside the stack memory. Stack is a memory space that holds method-level variables that are short-lived in addition to references to other objects in the heap.
Example of primitive type variables:
|Data Type||Default Value (for fields)|
|String (or any object)||null|
Reference type variables aka objects or pointers are stored in two locations. The actual object data is stored inside the heap memory (the memory space that holds objects and JRE classes), and a reference aka pointer for the object is kept inside stack memory, which just points to the actual object.