Java Program to display hello world

How to display a message in java?

Here we are explaining how to write a simple java program to display hello world. So first we have to declare the class HelloWorld with a public modifier. The name of the class started with the capital letter H.And we set the modifier as public. Then we started the main() function, where the java program execution begins. Then we display the message Hello World.. using System.out.println.

What is System.out.println() in java?

It is used to print the argument which is passed to it. Here the System is a class that is defined in the java.lang.package.And out is an instance of PrintStream.The println() prints the argument which is passed through it. The println() also adds a new line.

Example,System.out.println("hai") which prints hai on the screen.

ALGORITHM

STEP 1: Declare the class HelloWorld with a public modifier 

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Display the message "Hello World.. " using system.out.println.

 

Java Source Code

                                          public class HelloWorld {      //define the class
     public static void main(String []args){
        System.out.println("Hello World...");   //Display the message Hello World 
     }
}
                                      

OUTPUT

Hello World...