Hello World Program in Java
In this tutorial, we will learn how to write a Hello World program in Java language. We will go through each statement of the program.
Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Output
Hello, World!
Working of the "Hello, World!" Program
public class HelloWorld
This line declares a public class namedHelloWorld
. In Java, every application must have at least one class definition that contains the main method.public static void main(String[] args)
This line defines the main method. Thepublic
keyword means the method is accessible from anywhere,static
means it belongs to the class rather than instances of the class,void
means it does not return any value, andmain
is the name of the method.String[] args
is the parameter to the main method, which is an array of strings.{
This opening brace marks the beginning of the main method's body.System.out.println("Hello, World!");
This line prints the string "Hello, World!" to the standard output (usually the screen).System.out
is a standard output stream, andprintln
is a method that prints a line of text followed by a newline.}
This closing brace marks the end of the main method's body.}
This closing brace marks the end of theHelloWorld
class definition.