Initialize variables

When a variable is created it will have no contents. This means that the value will be either NULL or random. In the C++ language when you create a variable it would just grab a free position in memory. As that memory location could of been recycled it meant that the initial value could be anything. Java will complain if you try and access a variable which has not been initialized.

The term initialize means to set a value. In most instances this means setting it to 0 although it may mean setting it to something different. This is done through normal assignment

RULE - You must ALWAYS initialize a variable before you use it. This includes arrays.

When dealing with arrays you can initialize them using an for loop

FOR a=0 to arr.length
    arr[a] = 0
NEXT

Another example may be if you were creating a 2 player game where each player starts with 3 lives.

int player1Lives = 3;
int player2Lives = 3;