×

java · level 1 · unit 2 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A ="button" class="pl-term" data-term="0" aria-expanded="false">variable is a box with a name on it.

A variable is a box your program keeps things in. You write a name on the label and put a inside. From then on, you say the name to get the value back.

In Java the label also says what kind of thing fits in the box. That is its type. String boxes hold text. boxes hold whole numbers, like 7 or 100.

So String name = "Sam"; means: make a String box called name and put "Sam" in it. To use the box, write its name with no quotes.

public class Main {
    public static void main(String[] args) {
        String name = "Sam";
        int age = 9;
        System.out.println(name);
        System.out.println(age);
    }
}

Read the = as put into, not equals.