In this tutorial, you’ll understand about public static void main(string args[]) in java programming.
The main() method is a special method in Java Programming that serves as the externally exposed entrance point by which a Java program can be run. To compile a Java program, you doesn’t really need a main() method in your program. But, while execution JVM ( Java Virtual Machine ) searches for the main() method and starts executing from it.
// A Java program to print "Hello World"
public class Hello {
public static void main(String args[])
{
System.out.println("Hello World");
}
}
In the above application example, we are using the public static void main. Each word has a different meaning and purpose.
Public
It is an Access Modifier, which defines who can access this Method. Public means that this Method will be accessible by any Class(If other Classes can access this Class.).
Static
Static is a keyword that identifies the class-related thing. It means the given Method or variable is not instance-related but Class related. It can be accessed without creating the instance of a Class.
Void
It is used to define the Return Type of the Method. It defines what the method can return. Void means the Method will not return any value.
main
Main is the name of the Method. This Method name is searched by JVM as a starting point for an application with a particular signature only.
String args[] / String… args
It is the parameter to the main method. The argument name could be anything. You can either use String array (String args[]) or var args variable of String type. Both will work the same way.