A variable is a named box that holds a value while your program runs. You give it a type, a name, and then you put data inside it. Reading the value back later is how your program remembers things.
int customerAge = 25;
// type + name + valueThe three parts have distinct jobs. The type such as int or String decides what kind of data can go inside and how much memory it needs. The name is what you call it, so it must follow identifier rules. The value is the actual data stored at that moment.
HOW A VARIABLE IS CREATED
┌──────────────────────────────────────────────┐
│ TYPE int how much, which │
│ NAME customerAge how you refer to│
│ VALUE 25 the real data │
└──────────────────────────────────────────────┘
Change the type later ──► not allowed, the box is fixed
Change the value later ──► always allowed, that is the pointThe idea of a fixed box is what makes Java strongly typed. A box declared as int can hold whole numbers only, and the compiler will stop you before your program runs if you try to store text in it.