Search⌘ K
AI Features

Say “Hello, World!”

Explore how to create and run your first Java program by printing messages to the console. Understand the main method, class structure, and output commands essential for starting Java programming confidently.

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:

Java
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 ;.