Java Program to print Hello World
In this program, we will create a simple Java application to display the message "Hello World!!!" on the console.
Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!!!");
}
}
Explanation of the Program
Let us break the program into its key components for better understanding:
-
public class HelloWorld
:- Every Java program begins with a class definition.
- Here, the class is named
HelloWorld
. The class name must match the file name (HelloWorld.java
).
-
public static void main(String[] args)
:- This is the entry point for any Java program.
public
: Makes the method accessible globally.static
: Allows the method to be called without creating an object of the class.void
: Indicates that this method does not return any value.String[] args
: Accepts command-line arguments as an array of strings.
-
System.out.println("Hello World!!!");
:System.out
: Refers to the standard output stream.println
: Prints the string inside the parentheses and moves the cursor to the next line.- The string "Hello World!!!" is displayed on the console.
Output
When you run this program, the following output will appear on the console:
Hello World!!!
This is the simplest Java program, and it's often the first program written when learning a new programming language.