Skip to content

Exercise 1 of 10 · Output

Hello, Out Loud

What you will make

A banner with your own name inside it, printed by Java code that you compiled and ran yourself.

The one new idea: System.out.println prints a line, and a Java program always starts inside a main method

Almost everything you write from here on will show you something. System.out.println is how a program talks back to you — and how you check whether your code did what you thought it did.

Go straight to the code ↓

Every program starts inside main

Java will not run a line of code just because it is sitting in a file. It needs a class to hold it, and inside that class it needs one particular method: public static void main(String[] args). That line is not decoration and none of the words in it are optional yet — think of it as the doorway every Java program is required to have, the one spot the computer knows to start reading from. Everything you want to happen goes between the curly braces that follow it.

The class name and the file are tied together on this site: your code always runs as a class called Main. That is why every starter file you meet from here on begins the same way.

What System.out.println does

Whatever sits between the round brackets gets shown on the screen, and println adds a new line afterwards so the next call starts on a fresh row. Wrap your text in double quotes and Java treats it as plain text, printed exactly as written — letters, spaces, punctuation and all.

That is the whole idea. There is nothing hidden underneath it.

A worked example

Here is a different program, so you can see the shape of it without being given the answer:

Java
public class Main {
    public static void main(String[] args) {
        System.out.println("--> ready");
        System.out.println("--> steady");
        System.out.println("--> go");
    }
}

Running that prints three lines:

Output
--> ready
--> steady
--> go

Three println calls, three lines of output, in the order they were written. The arrows and the spaces come out exactly as they were typed — Java does not tidy anything up or add anything of its own.

Your turn

The editor already holds a working program. Press Run before changing anything and a four-line banner appears: a row of = signs, two lines of text, then another row of = signs.

One thing is missing. The middle line says YOUR NAME instead of your name.

Replace those two words with your own name, keep the quotes exactly where they are, and press Run again. That is the entire task — you are not expected to write a line from scratch yet.

If something goes wrong

If javac complains, it is almost always the quotes or the semicolon. The text you want printed has to sit between double quotes — "Hello, Maya!" works, Hello, Maya! on its own does not, because without quotes Java reads it as the name of something rather than as text to display. And every statement needs a semicolon at the end; leaving one off makes the compiler report the mistake on the line after the one that is actually missing it.

Nothing you do here can break anything. Change it, run it, change it again.

Write your code

Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.

Ctrl/Cmd+Enter to run

Press Esc then Tab to move keyboard focus out of the code editor.

Ready
Output will appear here after you run your code.

The runtime is starting in the background. You can type now — it will be ready before you are.

The answer appears here once you have run your code at least once.

Things that often go wrong here

Deleting the quotes along with the placeholder
Without quotes, javac tries to read your name as the name of something already defined in the program — a variable, a class, a method — and finds nothing by that name. It stops before a single line runs and reports cannot find symbol, pointing at the exact word it did not recognise.
Deleting the semicolon at the end of the line
Every statement in Java ends with a semicolon. Drop it and javac reports ';' expected at the start of the next line, because it read straight through to there still waiting for the one that should have closed the line above.
Changing one of the banner lines instead of the name line
Only the middle println has a placeholder. The two rows of = signs are the top and bottom of the banner and are already correct — shortening one by a character is a real difference in the output, even though it looks identical at a glance.

Want a blank editor instead? Open the Java playground.