First Program

Basic Java
≈ 2 min read

A minimal program in Java

Let us start with a small program that can already be run so you can see a result:

void main() {
    System.out.println("Hello, Java!");
}

In Java 25, a program like this does not require you to declare a class first or write public static void main(String[] args). The entry point can simply be written as void main(): Java finds this method and starts executing the commands inside it from top to bottom.

This is a regular Java 25 feature, not a special shortcut used only for teaching. Compact source files and simplified forms of main are full parts of the language.

What happens inside main

In our example, there is one command inside main:

System.out.println("Hello, Java!");

It prints text to the console. After the program starts, the result will look like this:

Hello, Java!

The text to print is written inside quotation marks, and the semicolon ; ends the command. If you add another System.out.println(), it will run next:

System.out.println("Hello, Java!");
System.out.println("My first program is running.");

The console will show two lines in the same order:

Hello, Java!
My first program is running.

Curly braces and letter case

Curly braces { } mark the boundaries of the main body. The commands between them belong to this method. Indentation makes the code structure easier to see at a glance.

Java is case-sensitive: main and Main are different names, just like System and system. If you change the letter case where a specific name is expected, the program will not compile.

The classic main form

In existing Java code and regular projects, you will also often see the more familiar form:

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

It is still fully valid in Java 25. For now, you do not need to memorize what public, static, and String[] args mean: these parts will become clearer as you move through the course. For now, it is enough to recognize both forms and understand that program execution starts with main.