Hello, Java

Every Java program starts as text in a file. The text in the editor is a complete program: a class named Hello, with a method named main. When you run a Java program, the computer starts at main and runs its statements from top to bottom. This one has a single statement, which prints a line.

Press Run, or press ⌘↵ in the editor (Ctrl+Enter on Windows and Linux): it runs the code you see.

1 Your first program Hello.java ● in the editor

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

What Run did

The first lines of the output are the two commands Run typed for you:

  1. javac is the Java compiler. It reads Hello.java, checks it, and writes Hello.class, the compiled program, into the folder out.
  2. java is the Java virtual machine. It loads Hello.class and calls main.

These are the real javac and java of OpenJDK, running in a small Linux computer inside this browser tab. To make Run quick, the compiler is kept warm in the background, ready for your next program.

The file name and the class name must match: public class Hello lives in Hello.java. Java is case-sensitive, so hello and Hello are different names.

println and print

System.out.println(…) prints its text and then ends the line. System.out.print(…) prints without ending the line, so the next output continues on the same line.

Change the program so that it prints exactly these two lines:

Hello, Java!
I am learning.

2 Exercise: two lines Hello.java ○ to do

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

Your code is saved in this browser: come back later and it is still here. Terminal, next to Output, is a shell in the same computer; your files are in /home/student. Alt+[ and Alt+] move between the steps of a lesson, and Keyboard shortcuts in the ⋯ menu next to Run lists the others.

Terminal

Editor.sh · Learn to program by writing and running real code in your browser. Nothing to install; your work stays in this browser.

© 2026 xuwaters.com

Step 1 of 2Your first program