Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Changing and Naming Variables

Recall that a variable holds a value, and that value can change or vary. If you use a variable to keep score you would probably increment it (add one to the current value). You can do this by setting the variable to the current value of the variable plus one (score = score + 1) as shown below.

Copying Variables

You can set one variable’s value to a copy of the value of another variable. This won’t change the value of the variable that you are copying from. Step through the code below by clicking the “Forward” button to see how the values of the variables change.

Code Link

Naming Variables

While you can name your variable almost anything, there are some rules. A variable name should start with an alphabetic character (like a, b, c, etc). You can’t use any of the keywords or reserved words as variable names in Java (forifclassstaticintdouble, etc). Here is the complete list of keywords and reserved words for Java.

The name of the variable should be descriptive, that is, it should suggest the function of the variable and the type of the variable. A name like score helps make your code easier to read. Do not try to be cute and name your variables crazy things like thisIsAReallyLongName. This makes the code very hard to understand.

The convention in Java is to always start a variable name with a lower case letter and then use uppercase for the first letter of each additional word. For example, highestScore.

Variable names may not include spaces, so uppercasing the first letter of each additional word makes it easier to read the name. Uppercasing the first letter of each additional word is called camel case.

Java is case-sensitive, thus, playerScore is  are not the same as, playerscore.