Hello World – Java display message example

 

The very first tutorial in any programming language will be “Hello World”. So lets start with it then.

The basic understanding of this tutorial is to print a message in java language.

So before going any further we need to have a environment setup for writing java programs.

 

Software’s Required:

1)  java JDK

Its a java development kit which is used to compile java programs on your machine / system.

 

2) intellij IDE

Generally we can run a simple java program using cmd promt by using notepad to write programs although its a better way of learning according to me because there is no error detection in notepad so we have to find them on our own.

But as we have a best IDE available form intellij i recommend to use it for beginners.

 

So after downloading the above software’s install “JDK” prior to “IDE”. So as to provide JDK path to IDE can be done later also but its a good practice to do so.

 

The very first step in writing a java program is to create a file with “.java” extension.Initial program is hello world so our class will be as

 

helloworld.java

Now start writing code in this file by specifying class name in initial line

 

public class helloworld

 

Don’t understand??? 

now worry let’s break it down

 Here public is access specifier and class name is specified later.

There comes our main method its the starting point of every program i..e, the execution of program starts from here.

 

 public static void main(String args[])

public:

Public as specified earlier is access specifier,

static:

Static is used to call the method without object creations basically every method in java should create a object to call it so here we are skipping it by making use of static.

void:

Every method will have a return type so when we don’t want a method to return any specific return type we use this void in method.

main:

Here main is the name of the method.

String args[]:

Its a parameter to accept command line arguments.

 

to display a message we use  “System.out.println()” and pass message to it

System.out.println("Hello World");

 

Here we can use

print(“Hello World”) // print the message and display cursor in same line

println(“Hello World”) .. print message and moves cursor into next line.

 

 

public class helloworld {

    public static void main(String args[]) {

        System.out.println("Hello World");
    }
}

 

Show Buttons
Hide Buttons
Read previous post:
Android Databinding Library || java || jet pack

  Android dataBinding : Android databinding, Jetpack provides new data binding mechanisms using which a user can bind UI components...

Close