java · level 1 · unit 2 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Give every box a name that tells you what is inside.
Names can use letters, digits and _. They cannot have spaces and cannot start with a digit. Capitals matter, so score and Score are two different boxes.
Some words are taken. A such as int, class or public already means something to Java, so it cannot be a name.
For names made of several words, Java coders use : squash the words together and give each new word a capital, like favouriteFood. Pick names that say what is inside.
public class Main {
public static void main(String[] args) {
String favouriteFood = "pizza";
int bestScore = 120;
System.out.println(favouriteFood);
System.out.println(bestScore);
}
} A name like x works, but bestScore tells future you what it means.
guess first
Is this a good name? What happens?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
public class Main {
public static void main(String[] args) {
String 2ndPlace = "Ollie";
System.out.println(2ndPlace);
}
}
your turn
Your turn. Name your own box.
Choose a camelCase name for a box that holds your favourite film, like bestFilm. Type it in both name blanks, put the film in the quotes, then run.
output
press run to see what happens
fix it
Two words, one box. Can you fix it?
output
press run to see what happens
- Java says a semicolon is expected, but the real trouble is the name. What sits in the middle of it?
- Names cannot have spaces. Squash the two words together in camelCase, on both lines.
- Change it to favouriteColour on lines 3 and 4, then press run.
nailed it
your boxes have great names now. :D
- Names use letters, digits and
_, with no spaces. - Never start a name with a digit or use a keyword.
- Use camelCase names that say what is inside.
new words in your collection
- keyword
- camelCase
This lesson isn’t saved. A free account remembers every lesson you finish.