Java hello world program

In this article you will learn how to write a program to print hello world in display screen using java. This is the first program you had learned in every programming language you learn.

Here you find the program in java with full advantage of “Object-Oriented Programming” approach. As the java is Object-Oriented language, here everything is happened inside class an access by object.

Print hello world java program


// Java print "Hello, World!" program

// class to print "Hello, world!"  
class HelloWorld{
    //method to print "Hello, world!" with void return type
    void print(){
        System.out.println("Hello, World!");

// Main class 
class Main{
    //Main method 
    public static void main(String s[]){
        //object creation of HelloWorld class
        HelloWorld ob = new HelloWorld();
        //calling print method using object 
}//end of the program


Hello, World!

How java hello world program worked?

The execution is started from main method inside main class, the object of the HelloWorld class is created inside main method using new operator(or memory allocated to the ob object).

After that with the help of ob object it calls the print method of HelloWorld class, and perform operation mentioned on the print method.

You can also check the program using the online compiler by click here.

Recommended Post