1. java-hell.de
  2. Topics
  3. First Steps
Topic 1 of 11

Learn Java: First Steps & Hello World

Everyone starts with Hello, World! – so do you. Here you write your first lines of Java, print text and numbers, and find out why the compiler freaks out over a missing semicolon. No JDK, no IDE, no bullshit.

The exercises

What you'll learn in this topic

  1. Just Hit Run
  2. Change the Text
  3. Two Lines
  4. The Semicolon
  5. Printing Numbers
  6. Doing Math
Exercise 1 of 6

Just Hit Run

In the editor you see your first Java program. It's already done.

Click Run (or press Ctrl+Enter) and watch what happens.

You don't have to change anything — just run it.

Modern Java

We use the compact syntax from Java 25 here. In older code you'll often see the long form with public class and public static void main(String[] args) wrapped around it — it does exactly the same thing. More on that under More info.

Starter code
void main() {
    IO.println("Hello, World!");
}
Background
What happens when you run it?

Java is a compiled language. First, the compiler (javac) translates your code into so-called bytecode — a kind of intermediate language that the Java Virtual Machine understands.

Then the JVM (Java Virtual Machine) starts up and runs that bytecode. That's why Java behaves the same on every operating system — "Write once, run anywhere".

IO.println() prints one line. In Java 25, IO is available automatically — no import needed.

Compact vs. classic

Right now your code looks like this:

void main() {
    IO.println("Hello, World!");
}

In older code (before Java 25) and in most company projects you'll see the classic form:

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

Both do the same thing. The compact form has been a standard feature since Java 25 (September 2025) — perfect for getting started without having to understand classes, public, static and String[] arrays right away. You'll learn the classic form later, when you want to read existing code or work in a team.

Exercise 2 of 6

Change the Text

You just saw it: IO.println() prints text.

The text goes inside quotation marks: "..."

Change the text so that Hello Java is printed.

Change only the text between the quotation marks — nothing else.

Starter code
void main() {
    IO.println("Hello, World!");
}
Background
What's a string?

In programming, text in quotation marks is called a string (a "string of characters"). "Hello" is a string literal — a text value written directly into the code.

In Java, strings are objects of the class java.lang.String. They're immutable — once created, they can't be changed. Every "change" quietly creates a new string behind the scenes.

Exercise 3 of 6

Two Lines

You can use IO.println() as often as you like. Every call starts a new line.

The first line is already there. Add a second line that prints World.

Write it right below the first one — built exactly the same way.

Starter code
void main() {
    IO.println("Hello");
    // Add a second line here
}
Background
println vs. print

There's also IO.print() — without the ln. The difference: println automatically adds a line break (\n) at the end, print doesn't.

print("A") followed by print("B") gives you AB on one line. println("A") followed by println("B") gives you two lines.

Exercise 4 of 6

The Semicolon

In Java, every statement ends with a semicolon: ;

Forget it and the compiler yells at you with an error. It happens to everyone — even after years.

The code in the editor is missing a semicolon. Find it and add it.

Starter code
void main() {
    IO.println("Fix me!")
}
Background
Why semicolons?

Java uses ; to separate statements from each other. Unlike Python, where line breaks are enough, Java almost completely ignores whitespace (spaces, tabs, line breaks).

In theory you could write a whole program on a single line — thanks to semicolons, Java still knows where each statement ends. In practice nobody does that, of course, because it would be unreadable.

Exercise 5 of 6

Printing Numbers

println can print numbers too — without quotation marks:

IO.println(42);

Change the number so that 100 is printed.

Starter code
void main() {
    IO.println(42);
}
Background
Primitive data types

Numbers without quotation marks are literals of a primitive type in Java. 42 is automatically an int (32-bit whole number). For bigger numbers there's long (64-bit).

Java strictly distinguishes between text ("42" = String) and number (42 = int). That makes Java "type-safe" — mistakes get caught early.

Exercise 6 of 6

Doing Math

You can calculate right inside println:

IO.println(3 + 4);  // prints 7

Replace the ??? with a calculation that results in 15.

Doesn't matter how — 5 + 10, 3 * 5, 20 - 5 — as long as the result is right.

Starter code
void main() {
    IO.println(???);
}
Background
Operators and order of evaluation

Java knows the usual arithmetic operators: +, -, *, / and % (modulo/remainder). Multiplication and division come before addition and subtraction, just like in school.

Watch out for integer division: 7 / 2 gives you 3, not 3.5! If both sides are int, the result gets cut off. For decimals you need 7.0 / 2.

Enough reading. Your turn.

In the tutorial you write the code yourself, hit Run and instantly see whether your program works. No JDK, no IDE, no bullshit.

Practice First Steps in your browser