Java "Hello, World!" Program

Hello World!

A "Hello, World!" program is usually the first program written by people who are beginners in writing codes. It is a very simple program which displays the message "Hello, World!". It is probably the simplest program to illustrate a few basic syntaxes of a programming language. This article covers the Java program to print "Hello World!".






1. Algorithm for "Hello, World!"


1. Print "Hello, World!"





2. Pseudocode for "Hello, World!"


1. Procedure print():

2. Print "Hello, World!"

3. End Procedure





3. Time complexity for "Hello, World!"


Time Complexity: O(1)





4. Java Program & output for "Hello, World!"

Code has been copied
// declare a class
public class HelloWorld {
    // The program begins with a call to main() function and
    // it prints "Hello World!"
    public static void main(String args[]) {
        System.out.print("Hello,  World!");
    }
}

Output


Hello, World!


  • public class HelloWorld: This line declares a class named HelloWorld.
  • public static void main(String args[]): This line defines the main method. The main method is the entry point of a Java program and is where the program execution begins. It takes an array of strings as an argument (commonly named args) and is marked as public and static, indicating that it can be accessed without creating an instance of the HelloWorld class.
  • System.out.print("Hello, World!");: This line uses the System.out.print method to output the string "Hello, World!" to the console.