Menu
Topics Index
...
`

Hello World Program - Java Example Program


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

Hello World

DESCRIPTION

Every Java program contains the following structure.


class class-name
{
    public static void main(String args[])
    {
        program-content
    }
}
In this structure(or format), only class-name, program-content and args will be different from program to program. The class-name will be the name of that program. program-content is where we include the code. This code will be executed when we run the program. args is the name of the variable to access the input parameters for the program. Although args can be called as s or arguments or input or some other name, it is a common practice to call it args or s.

In this example, we have called class-name as PrintHelloWorld and in program-content, we have included the code System.out.println("Hello World");, which will print Hello World to the screen.

The words used like class, public, static, void, main, String, System.out.println, the flower brackets {}, the parentheses () and the square brackets [], will be explained later. For now only remember the structure and understand that every program needs this structure.

THINGS TO TRY
  • Use the 'Try It' link on the top right of this program and change the print text from "Hello World" to "Hello Universe" and see the result.
  • Add one more print statement (System.out.println) to print the text "I completed my first java program." and see the output.

© meritcampus 2019

All Rights Reserved.

Open In App