Variables
Think of a variable as a labeled storage box in your computer's RAM.
42
Strict Typing
Java is strictly typed. You must declare the Shape of the box before you put anything inside it.
int
Whole numbers
ex: 10, -5
double
Decimals
ex: 99.99
boolean
True / False
ex: true
String
Text (Reference)
ex: "Hello"
Naming Rules
Variables must be named using camelCase. No spaces, and they cannot start with a number.
✔ VALID:
int playerScore;
double _taxRate;
String user1Name;
✘ INVALID:
int 1stPlayer; // Starts with number
double tax rate; // Contains a space
int playerScore;
double _taxRate;
String user1Name;
✘ INVALID:
int 1stPlayer; // Starts with number
double tax rate; // Contains a space
Syntax in Action
Let's declare and initialize a variable.
// Click the buttons below
1 / 4