Java · Lesson 2 of 3

📦 Variables and types

In Java you say what kind of value a variable holds.

int holds whole numbers, double holds decimals, String holds text and boolean holds true or false.

public class Main {
    public static void main(String[] args) {
        String name = "Riya";
        int age = 12;
        double height = 1.45;
        System.out.println(name + " is " + age);
        System.out.println("Height: " + height + " m");
    }
}
OUTPUTRiya is 12 Height: 1.45 m

💡 Use + to join text and values together.

✏️ Your turn

Open this example in the playground, change it and run it.

▶ Try it yourself

🧠 Quick quiz

Which type stores 3.5?