Here is a program which prints Hello World!.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
The first line is a syntax of defining a class called HelloWorld.public class HelloWorld {
The next line is the main method to be able to run program.public static void main(String[] args) {
public
anyone can access it.static
anyone can use or call this method without creating an instance of the class.void
method doesn't return any value.- main name of the method.
- String[] args is method arguments and it is an array of string. The argument stores the value of parameters if the program is run with any parameter.
System.out.println("Hello World!");
- System is the System class contains several useful class fields and methods.
- out is a static method of class System and a "standard" output stream corresponds to display output in the program.
- println is to print a String and then terminate a line.