Home › Learn › Java › First steps

Hello, world

Lesson 1 of 40. Print a line with System.out.println and see how the lessons check your work.

Every Java program is a class, and the program starts at a method called main. public class Main names the class, public static void main(String[] args) is the method the runtime calls, and the lines between its braces run top to bottom. System.out.println("text") prints a line. Every statement ends with a semicolon, and text goes in double quotes.

Press Run and the code is compiled and run in your browser by the real Java compiler. If it does not compile, the message names the line; when it runs, the checks compare what it printed or returned with what the task asked for and say what differed. Hints and a reference solution are one click away.

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

Your task

Make the program print two lines: Hello, world and then Java runs here.

Hint 1

A second System.out.println line, under the first, inside the same braces.

Show the solution
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, world");
        System.out.println("Java runs here");
    }
}

    Compiles with OpenJDK javac and TeaVM, both compiled to WebAssembly (7 MB download the first time, then cached), and runs in this tab; nothing is sent anywhere.