computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

☕

🎓

⏱ 25 min

Free

Hello, Java!

Discover what makes Java special and write your first Java program.

🎯 What you will learn

  • Where Java is used
  • The parts of a Java program: class and main
  • Print with System.out.println

👋 Let’s get started!

Java powers Minecraft (Java Edition), Android apps and huge company systems ☕. It is stricter than Python — every program lives inside a class, and every line ends with a semicolon. Strict = fewer surprises!

🪜 Step by step

1. 🏠 Every program has a class

Code lives inside a class. The file name matches the class name: Main.java.

public class Main {
    // your code lives here
}
2. 🚪 main is the front door

Java starts running inside the main method.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
3. ; Semicolons and { }

Each statement ends with ; and blocks are wrapped in curly brackets { }.

System.out.println("Line one");
System.out.println("Line two");

🧪 Try it!

Read the code, guess what it prints, then press 👀 Show output.

My first Java program

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java! ☕");
        System.out.println("I am learning to code.");
    }
}

Put the program together

public class Main {
    public static void main(String[] args) {
        System.out.println("Hi!");
    }
}

📖 Key words

Tap a card to flip it over!

class
A container for Java code 🏠
main
Where the program starts 🚪
println
Prints a line of text 🖨️
Compile
Turning code into something the computer runs ⚙️

🏆 Challenge

What would this program print? Predict it, then press “Show output” to check.

Challenge

public class Main {
    public static void main(String[] args) {
        System.out.println("Java");
        System.out.println("is");
        System.out.println("fun!");
    }
}

Knowledge Check Quiz

  1. Where does a Java program start?
  2. What ends a Java statement?
  3. Which prints a line?
Next lesson →