Your First Java Program
Build a robot's 'start button' and make it talk.
Your First Java Program 🤖
Java is everywhere: in Android phones, Minecraft (Java Edition!), bank systems and competition robots. Many student robotics teams program their robots in Java. Today you write your first Java program. Here it is:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, robot world!");
}
}Whoa, that's a lot of words just to say hello! Don't panic. Think of it like a robot:
| Part | Think of it as |
|---|---|
public class Main | the robot's body: everything lives inside it |
public static void main(String[] args) | the START button: Java begins running here |
System.out.println(...) | the robot's speaker: it says things out loud |
{ } curly braces | the walls that show what's inside what |
; semicolon | the full stop at the end of every instruction |
💡🧠 For now, copy the first two lines and the closing braces exactly. You'll learn what each word means later. Today you only write the lines inside
main.
Saying more things
Each println says one line:
public class Main {
public static void main(String[] args) {
System.out.println("Systems check...");
System.out.println("Wheels: OK");
System.out.println("Ready to roll!");
}
}🔍 Predict it!
Before you run code, guess what it will print. Real programmers do this all the time; it trains your brain to think like the computer.
🚀 Fun fact
Java was invented in the 1990s by a team at Sun Microsystems. It was first called Oak, after a tree outside the creator's office!
Want to run it yourself?
Predict what the code prints first, then check! Copy an example above, paste it into the free online Java editor, and press Run. Keep the first line as public class Main.
Opens Programiz, a free site that isn't run by First Coding Path and may show ads. Grown-ups, you might like to take a look first.