Java Hello World Program
A "Hello World!" is simple program in any programming language that outputs Hello World! on the terminal. It is a program in a programming language to introduce beginners.
// Java Hello World Program
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Output:
Hello, World!
So, Let's explore how the Java program works and what syntax we should use.
How this program works?
1. //comment line
// Java Hello World Program
Any line that starts with '//' in Java is known as a comment. Comments are written for user welfare, when someone reads the code he /she can know what it is about. Which function is for what is used in the program. That's why comments are
useful in any program
2. class HelloWorld { .... }
class HelloWorld { .... }
In Java, every code/program begins with a class function. You have to start any program with a class function otherwise it
will not work. In the program, HelloWorld is the name of the class definition and also the program name.
You have to save your Java program with the same name as the class definition name.
3. public static void main(String[] args) { .... }
public static void main(String[] args) { ..... }
This statement is called the main method. Every program in Java must have the main method to initialize the program. Because the compiler starts the execution of the program from the main method.
4. System.out.println("Hello World!");
System.out.println("Hello, World!");
This syntax in Java is used for printing the output on the screen. It will output "Hello World!".
Points to be noted when writing Java applications:-
1. There must be a main method inside the class.
2. Compiler starts program execution from the main method.
3. For a Java program error-free, your application name and class name should be the same.