Hello World java program

This is our first program in Java. It will print “Hello World!” to the screen. Being the first program, it is very easy. It is basically used to illustrate the basic syntax and program structure of Java.

Problem:
Display “Hello World!” on the screen.
Code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 /*
  * @author Hafiz Muhammad Umer
  */
 public class HelloWorld 
 {
     public static void main(String[] args) 
     {
     System.out.println("Hello World!");
     } 
 }

Output:

Hello World!

Explanation:
This program illustrates the basic program structure in java.

  • The lines 1 to 3 are comments.They have no effect on the execution of  the program. The are also not necessary.
  • The line 4 declares a class which ends at line 10.
  • At line 6 the main method starts which ends at line  9. The execution of a java program starts from the main method.
  • The statement at line 8 is used to display the output. It prints “Hello World!” to the screen.

This was our first program in java and first post on “Java with Umer”. Hope you liked it.

Leave a Comment