Muhammad Fari Madyan
Hire me
Java basics · part 2 of 21

Learn Java from Scratch Part 2: Your First Program: Hello, World — The main Door, javac & Your First Error Message

The second part of a Java series for complete beginners: install JDK 25, write Halo.java, understand the main door and the execution arrow, compile with javac, run with java, and read the three most common error messages.

Muhammad Fari Madyan

· 7 min read

Baca dalam Bahasa Indonesia →

Introduction: One Line, One Enter

One line of code. One press of the Enter key. Then the computer greets you back:

TEXT
Halo, Dunia!

Halo, Dunia means "Hello, World" in Indonesian. I keep the Indonesian text so the code is the same in both versions of this series.

It looks very simple. But behind that one line there is a door, an arrow that moves, and one semicolon that can make everything fail.

In this part you write your first program. This time you type too. You do not only read.

After this part, you will be able to:

  1. Install the JDK and check that it is ready.
  2. Explain the pieces of the simplest Java program.
  3. Compile a program, run it, and read your first error message.

Answer to the Part 1 Challenge

The question: the file Halo.class was made on a Windows laptop, and your friend uses a Mac. What must your friend do?

The answer is B: just install a JVM.

The bytecode package is exactly the same. The only missing piece is the adapter, which is the JVM for Mac. There is no need to compile again, and no need to write the code again.

If you answered B, well done!


1. Get Your Tools Ready

Install JDK 25, the toolbox we opened in Part 1. You can download a JDK for free. Two examples are Eclipse Temurin at adoptium.net and Oracle JDK at oracle.com/java.

After the installation, open a terminal. On Windows it is called Command Prompt or PowerShell. Then type:

BASH
java --version

The result looks like this:

TEXT
openjdk 25.0.5.1 2026-11-17

The numbers at the end can be different. The important part is the first number: 25. It means the JVM is ready.

Now check the translator:

BASH
javac --version
TEXT
javac 25.0.5.1

Both commands must work. If the terminal does not know one of them, the JDK is usually not installed correctly. Close the terminal, open it again, and try once more.

To write code, you can use any editor. Two popular ones are Visual Studio Code and IntelliJ IDEA.


2. A Program Is a House with One Door

Before you type, picture a program as a house.

This house can have many rooms. But it has only one front door. The name of that door is main.

Every time the program runs, the JVM enters through the main door. It never enters through a window or a back door.

After it enters, there is an execution arrow. The arrow moves from the top line to the bottom, one line at a time. It is like reading a recipe: step one first, then step two.

A program enters through the main door, then the execution arrow moves from top to bottom

Click the diagram to open it in full size.

If there is no main door, the JVM does not know where to enter. The program cannot run.


3. Writing Halo.java

Create a new file named Halo.java. Then type this code:

JAVA
void main() {
    IO.println("Halo, Dunia!");
}

Only three lines. Let us look at each piece.

PieceMeaningIn our picture
void main()The entry point of the programThe front door
{ and }The start and the end of mainThe walls of the house
IO.println(...)Show some text, then move to a new lineOne step in the recipe
"Halo, Dunia!"The text to showWhat the step says
;The end of one instructionThe full stop at the end of a sentence

A few small notes:

  • println is short for "print line".
  • Text between double quotes is called a string. A string is printed exactly as it is written.
  • Every instruction between { and } belongs to main.

You do not need to think about the word void yet. We cover it in the part about methods.


4. Compile, Then Run

Save the file and go back to the terminal. Make sure the terminal is in the same folder as Halo.java.

Step one: compile.

BASH
javac Halo.java

No message at all? Then it worked. With javac, silence is good news. Your folder now has a new file, Halo.class.

Step two: run.

BASH
java Halo

The JVM enters through the main door. The execution arrow stops at the first line, runs println, and the result appears:

TEXT
Halo, Dunia!

That is your first program. Well done.

Now add two more lines:

JAVA
void main() {
    IO.println("Halo, Dunia!");
    IO.println("Aku belajar Java.");
    IO.println("Sampai jumpa!");
}

The new lines mean "I am learning Java." and "See you!". Compile and run again with the same two commands. The result:

TEXT
Halo, Dunia!
Aku belajar Java.
Sampai jumpa!

Three instructions, three lines of text. The order is exactly the order of the code. The arrow moves down to the second line, then to the third. When the arrow reaches }, the program ends.


5. A Shortcut for Practice

For a program with one file, like this one, modern Java has a shortcut:

BASH
java Halo.java

Look closely: this time java gets the file name, with .java. The code is translated in memory and then runs at once. No .class file is created.

WayCommandIs a .class file created?
Two stepsjavac Halo.java, then java HaloYes
Shortcutjava Halo.javaNo

The shortcut is handy for practice. But remember the two steps, because that is what really happens behind the scenes.


6. Three Beginner Traps

The three error messages below are real messages from javac. I broke the code on purpose so you can see them first.

Trap one: a missing semicolon.

TEXT
Halo.java:2: error: ';' expected
    IO.println("Halo, Dunia!")
                              ^
1 error

How to read it: Halo.java:2 means the problem is in the file Halo.java, on line 2. ';' expected means javac expected a semicolon. The ^ sign points to the place. Add the semicolon, compile again, and it is fixed.

Trap two: capital letters and small letters.

Java is strict. Println with a capital P is a different word from println.

TEXT
Halo.java:2: error: cannot find symbol
    IO.Println("Halo, Dunia!");
      ^
  symbol:   method Println(String)
  location: class IO
1 error

"Cannot find symbol" means javac cannot find anything named Println.

Trap three: a quote that is not closed.

TEXT
Halo.java:2: error: unclosed string literal
    IO.println("Halo, Dunia!);
               ^
1 error

"Unclosed string literal" means the string is not closed. javac does not know where your text ends.

MistakeMessage from javacFix
Missing ;';' expectedAdd ; at the end of the instruction
Printlncannot find symbolWrite println, all small letters
Quote not closedunclosed string literalClose it with "

One thing to remember: an error message is not a punishment. It is a hint, and it even tells you the line number.


Summary

  1. A Java program always starts at the main door.
  2. The execution arrow runs the instructions from top to bottom, one at a time. Every instruction ends with a semicolon.
  3. println shows text and then moves to a new line. Compile with javac, then run with java.

Challenge

println has a sibling named print. The difference: print shows text, but it does not move to a new line.

Now look at this code:

JAVA
void main() {
    IO.print("Halo, ");
    IO.println("Dunia!");
    IO.println("Siap belajar.");
}

What is the output?

  • A. Halo, Dunia! on the first line, Siap belajar. on the second line.
  • B. Three texts on three separate lines.
  • C. An error.

Try to answer first, then run it yourself to check. I explain the answer at the start of Part 3.


Conclusion & What's Next

Your first program runs. You now know that a program enters through main, moves from top to bottom, and that javac tells you which line is wrong.

But our program can only show text that is already fixed. In Part 3, our program starts to remember things. We meet variables and data types: boxes of different sizes, from the tiny byte to the large long.

See you in Part 3. Get your coffee ready. Hot chocolate is fine too.

ShareLinkedInXWhatsApp

Written by Muhammad Fari Madyan

Senior Backend Engineer and co-founder of LampungDev. I write up what I build so others can learn from it.

Work with me
← part 1Meet Java and the JVMpart 3 →Variables and Primitive Types

Muhammad Fari Madyan

Senior Backend Engineer building real-time, high-concurrency systems that hold up in production. Co-founder of LampungDev. Based in Bandar Lampung, Indonesia (UTC+7), working remote.

Work

Case studiesCahTixExam platform, 4 stacksOpen source

© 2026 Muhammad Fari Madyan

Designed and built by Muhammad Fari Madyan