...

/

Say “Hello, World!”

Say “Hello, World!”

Write and run a basic Java program with console output.

Welcome to Java! In this course, you’ll learn the fundamentals of Java programming in a hands-on, practical way. We’ll start by writing your first Java program, printing a message to the screen, and breaking down how Java is structured. No prior experience? No problem—just bring curiosity and your keyboard.

Goal

You’ll aim to:

  • Write and run a basic Java program.

  • Use System.out.println() to display output.

  • Understand Java’s basic structure.

Your first Java program

Let’s print the first Java program:

Press + to interact
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}

That’s it—you’ve written a full Java program that prints a message to the screen!

What’s going on?

  • public class Main defines the class named Main. It’s the program’s entry point.

  • main() is the method where every Java program starts running.

  • System.out.println() displays output in the console.

  • Each statement ends with a semicolon ;.

Try this

Change the following message:

Press + to interact
System.out.println("Java is awesome!");

When you run your code, Java reads it and performs the action—in this case, printing your message.

Mini challenge

Add two more lines to your program to print new messages:

Press + to interact
System.out.println("Let’s learn Java.");
System.out.println("Line by line.");
Press + to interact
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
// Write your code here:
}
}

What does the output look like?

Great job! You’ve completed your first Java output challenge.

What’s next?

You’ve said hello. Next: make Java do math—and become your own calculator!