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. Thepublickeyword means the method is accessible from anywhere,staticmeans it belongs to the class rather than instances of the class,voidmeans it does not return any value, andmainis the name of the method.String[] argsis 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.outis a standard output stream, andprintlnis 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 theHelloWorldclass definition.