🎯 What you will learn
- Declare variables with a type
- Use int, double, boolean, char and String
- Do math and join strings
👋 Let’s get started!
In Python a box can hold anything. In Java, you label the box with a TYPE first — “this box only holds whole numbers”. It helps catch bugs before the program even runs! 📦
🪜 Step by step
1. 🏷️ Type + name + value
Write the type, then the name, then = and the value.
int lives = 3;
double speed = 2.5;
boolean isHero = true;
String name = "Nova";
2. ➕ Math
Java does math like Python. Careful: int / int drops the decimal!
int a = 7;
int b = 2;
System.out.println(a + b);
System.out.println(a / b); // 3, not 3.5
3. 🔗 Joining
Use + to join strings and other values.
String player = "Nova";
int score = 120;
System.out.println(player + " scored " + score);
🧪 Try it!
Read the code, guess what it prints, then press 👀 Show output.
Player card
String name = "Nova";
int level = 5;
double health = 87.5;
boolean hasShield = true;
System.out.println("Player: " + name);
System.out.println("Level: " + level);
System.out.println("Health: " + health);
System.out.println("Shield: " + hasShield);Level up
int level = 1;
level = level + 1;
System.out.println("Level " + level);📖 Key words
Tap a card to flip it over!
- int
- Whole number 🔢
- double
- Number with decimals 🌊
- boolean
- true or false ✅
- String
- Text (capital S!) 🔤
🏆 Challenge
Predict the output, then check.
Challenge
int apples = 10;
int eaten = 3;
int left = apples - eaten;
System.out.println("Apples left: " + left);Knowledge Check Quiz
- Which type stores 3.75?
- What prints?
- Which line is correct Java?