Skip to content
Codewilds

Lesson 1 of 34 · Fundamentals

Java Hello World: Your First Program

easy10 XP3 min readFree lesson

Welcome to the Bytecode Highlands! Every programmer's journey starts the same way: by making the computer say hello. In this first lesson you will write, compile and run a real Java program — right here in your browser, with nothing to install.

Java is one of the most widely used programming languages in the world. It runs bank back-ends, Android apps, search engines and games like Minecraft, and its strict, readable style makes it a great language for learning how programs are really built.

Your first Java program

Here is a complete Java program:

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

When you run it, Java prints:

Hello, World!

That is more ceremony than a one-liner in Python or JavaScript, but every piece has a job:

  • public class Main { ... } — all Java code lives inside a class. A class is a named container for code; we will build our own classes in Chapter 4. A public class must be saved in a file with the same name, so this one lives in Main.java.
  • public static void main(String[] args) { ... } — the main method. It is the entry point: when the program starts, Java runs the statements inside main from top to bottom. For now, treat this line as a fixed recipe.
  • System.out.println("Hello, World!"); — prints a line of text. System.out is the standard output (the console) and println means print line.
  • "Hello, World!" is a String — a piece of text in double quotes.
  • The semicolon ; ends the statement, and the curly braces { } mark where the class and the method begin and end.

Compile, then run

Java is a compiled language. When you press Run, two things happen:

  1. The compiler, javac, checks your code and translates it into bytecode — compact instructions for the Java Virtual Machine (JVM).
  2. The bytecode is executed, and your main method starts.

If the compiler finds a mistake — a missing semicolon, a typo in a name — the program never starts. Instead you get a compile error with a line number. Errors are normal: professional developers see them all day. Read the message, go to the line, fix it, run again.

println adds a line break after the text, so the next output starts on a new line. print does not:

System.out.print("Level ");
System.out.print(1);
System.out.println("!");
System.out.println("Ready.");
Level 1!
Ready.

Comments

Comments are notes for humans; the compiler ignores them.

// A single-line comment runs to the end of the line.
/* A block comment
   can span several lines. */
System.out.println("Comments are ignored"); // this part too

Common mistakes

  • Forgetting the semicolon: System.out.println("Hi") fails with ';' expected.
  • Wrong capitalisation: Java is case-sensitive. system.out.println or System.out.PrintLn will not compile — the class is System and the method is println.
  • Single quotes around text: 'Hello' is not a String in Java. Single quotes are only for a single character, like 'A'.
  • Unbalanced braces: every { needs a matching }. Keeping the indentation tidy makes them easy to spot.

Assignment

Write a program that prints exactly these two lines:

Hello, World!
I'm learning Java!

Put your two System.out.println statements inside the main method. The output must match exactly — capital letters, spaces, punctuation and the apostrophe in I'm all count.

Hello World in other languages

Need a quick reminder? The Java cheat sheet has every topic of Learn Java on one page.

Lesson last updated on .

Write code ↓
Java+10 XP

Press Run to execute your code, or Submit to check it against the tests.