Java Hello World First program

Java Hello World First program

Let’s have our first example. The first example is a basic one ,a welcome program.

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

Output:

Hello World

Explanation Of above program

  • class It is a keyword used to declare a class in java.
  • public keyword is an access modifier(1 out of 4 access modifiers) which represents visibility, it means it is visible to all.We will discuss about access modifiers later.
  • static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn’t require to create object to invoke the main method. So it saves memory.
  • void is the return type of the method, it means it does not return any value.
  • main represents the start point, from where the execution of the program starts.
  • String[] args is used for command line argument. We tell you about String later.
  • System.out.println() is used as print statement. Bu using it we will print the output on screen.

The way or order of writing public static void main(String args[]) is not fixed or a specific rule. It can be also be written as:

  • public static void main(String args[])
  • public static void main(String [] args)
  • public void static main(String args[])