A variable is a container that holds values that are used in a Java program. Every variable must be declared to use a data type. For example, a variable could be declared to use one of the eight primitive data types: byte, short, int, long, float, double, char or boolean. And, every variable must be given an initial value before it can be used.


int myAge = 21;

The variable "myAge" is declared to be an int data type and initialized to a value of 21.

mla apa chicago
Your Citation
Leahy, Paul. "Variable." ThoughtCo, Jan. 16, 2017, Leahy, Paul. (2017, January 16). Variable. Retrieved from Leahy, Paul. "Variable." ThoughtCo. (accessed November 20, 2017).