java · level 1 · unit 1 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
shows a message on the screen.
System.out.println is a command that shows something on the screen. Read it as: system, out, print a line. Whatever you put inside its brackets is what appears.
Words go inside double quote marks, like "Hello, world!". A piece of text in quotes is called a . Picture the letters threaded on a string, like beads. The quotes are not shown.
Every instruction ends with a , ;. It works like the full stop at the end of a sentence, telling Java that this instruction is finished.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
} Use a capital S in System, small letters in out.println, and double quotes at both ends.
guess first
What will appear on the screen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
public class Main {
public static void main(String[] args) {
System.out.println("My cat is called Pickles");
}
}
your turn
Your turn. Tell the computer what you love to eat.
Type your favourite food in place of the blank, keeping it inside the quotes. Then press run.
output
press run to see what happens
fix it
This line will not run. Can you fix it?
output
press run to see what happens
- Java stopped before showing anything. Look at the very end of line 3.
- Every instruction needs a mark at the end, like the full stop at the end of a sentence.
- Add a semicolon,
;, after the last bracket on line 3, then press run.
nailed it
you made the computer talk. :D
System.out.printlnshows whatever is inside its brackets.- Text inside double quote marks is called a string.
- Every instruction ends with a semicolon.
new words in your collection
- System.out.println
- string
- semicolon
This lesson isn’t saved. A free account remembers every lesson you finish.