Hello World Program in Java



In this tutorial, we will learn how to write a Hello World program in Java language. We will go through each statement of the program.

Java Program

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

Output

Hello, World!

Working of the "Hello, World!" Program

  1. public class HelloWorld
    This line declares a public class named HelloWorld. In Java, every application must have at least one class definition that contains the main method.
  2. public static void main(String[] args)
    This line defines the main method. The public keyword means the method is accessible from anywhere, static means it belongs to the class rather than instances of the class, void means it does not return any value, and main is the name of the method. String[] args is the parameter to the main method, which is an array of strings.
  3. {
    This opening brace marks the beginning of the main method's body.
  4. System.out.println("Hello, World!");
    This line prints the string "Hello, World!" to the standard output (usually the screen). System.out is a standard output stream, and println is a method that prints a line of text followed by a newline.
  5. }
    This closing brace marks the end of the main method's body.
  6. }
    This closing brace marks the end of the HelloWorld class definition.