Print Hello World

1 min readUpdated August 29, 2026core-javaexamplesbeginner

Every Java program needs a main method — it’s the entry point the JVM looks for when you run the class.

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

Try it yourself: change the text inside the quotes and re-run the program — you’ll see your own message printed instead.

Line by line

  • public class Main — declares a class named Main. The file must be named Main.java.
  • public static void main(String[] args) — the fixed signature the JVM calls to start your program.
  • System.out.println(...) — writes text to standard output, followed by a newline.

A second example: printing several lines

public class Main {
public static void main(String[] args) {
System.out.println("Line one");
System.out.println("Line two");
System.out.print("No newline here, ");
System.out.println("so this continues on the same line.");
}
}

print does not add a trailing newline; println does — mix them when you want to build up a single line from multiple statements.