Skip to content
Veltoryx Technologies
FreeLesson 1.4Beginner3 min readUpdated 30 October 2026

Your first program, line by line

Write Hello World in Java, understand every word in it, and learn the mistakes beginners make most often.

Every Java journey starts with one small program that prints a line of text. It's short, but every word in it means something. Let's write it, run it, and then read it slowly, line by line.

01Write it and run it

Create a file called Hello.java and type this:

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

Run it from the terminal:

Terminal
javac Hello.java
java Hello

02Line 1: the class

java
public class Hello {

Every piece of Java code lives inside a class. Think of a class as a container for your code. public means any other code may use it, and Hello is its name.

03Line 2: the main method

java
    public static void main(String[] args) {

This is where your program starts. When you type java Hello, the JVM looks for exactly this method and runs it. Word by word:

WordMeaning
publicThe JVM can call it from outside the class
staticIt belongs to the class, so the JVM can call it without creating an object first
voidIt doesn't return any value
mainThe special name the JVM looks for
String[] argsWords typed after the program name on the command line arrive here

04Line 3: printing

java
        System.out.println("Hello, Java!");
  • System is a built-in class.
  • out is the standard output, usually your terminal.
  • println prints the text and then moves to a new line.

Every statement in Java ends with a semicolon ;.

05Using args

Let's make the program greet whoever you name on the command line:

Greet.java
public class Greet {
    public static void main(String[] args) {
        String name = args.length > 0 ? args[0] : "friend";
        System.out.println("Hello, " + name + "!");
    }
}
Terminal
java Greet.java Vivek
Expected output
Hello, Vivek!

The live editor (▶ Run) doesn't pass command-line arguments, so there it prints Hello, friend!. That's the fallback in action.

06Common beginner mistakes

  • Wrong file name: the public class name and the file name must match exactly.
  • Missing semicolon: every statement ends with ;.
  • Wrong capitals: Java is case-sensitive. system.out.println and Main instead of main both fail.
  • Running the .class file name: type java Hello, not java Hello.class.

07In the interview

Common follow-up questions:

  • Can you overload main? Yes, you can write other methods called main with different parameters, but the JVM only starts the program from main(String[] args).
  • What happens without static? The class compiles, but on older Java versions the JVM can't start it. Newer versions add simpler forms of main, which we cover in the Java versions module.
  • What is args used for? It holds the words passed on the command line after the program name.

08Check your understanding

Quiz · 4 questions

0 of 4 answered

  1. 1. Your file is called hello.java and contains public class Hello. What happens when you compile it?

  2. 2. Why is main declared static?

  3. 3. What does System.out.println do?

  4. 4. You run java Greet.java Asha. What is args[0]?