Read Java Interview Questions and Answers for Beginners and Experienced

Java Hello World Program

Java Hello World program is one of the first program that most of the programmer write while learning Java Programming language.

In this Java examples series, we will study that how we can write Java hello World Program.

 


Java Hello World Program

Below is the Java Hello World program code

public class HelloWorld {

public static void main(String[] args) {

System.out.print("Hello World!");
}

}

When we run above Java program then below output will be got

Hello World! 

 

Explanation

Now let’s see what we write to display “Hello World!” in Java.

  • First of all, we created one public class, we named it HelloWorld
  • Inside HelloWorld class, we write Java main method public static void main(String[] args) .This main method is the entry point of java compiler to compile the program. Java compiler will start its execution from main method.
  • Inside main method, we just print the “Hello World!” with the System.out.print() method.
    • print() is the method to print or display any argument passed in it.
    • System is the class name.
    • out is the instance of System class

System.out.print() is various popular in Java programming language to display the things on the screen. There is another same method also System.out.println(), difference is just of print and println(). print() will display the output on the same line, where as println() method will display the output on next line.

So, In this Java examples, we learn the concept of how we can print Java Hello World Program.

We can display anything using System.out.print() statement.

public class HelloWorld {

public static void main(String[] args) {

System.out.print("This is my first program in java!");
}

}

Output

This is my first program in java!

So,whatever you want to print or display on the screen use System.out.print().