Whether public static void main(String[] args)
is an inbuilt or user defined or overridden function of some class provided by Java? If it is declared or defined inside some interface or class, where can its declaration be found?
The Java Virtual Machine starts execution by invoking the method main of some specified class, passing it a single argument, which is an array of strings.
Every Java application should have a main()
method , the JVM will look for the main()
method while launching the application. This is where the execution starts. No it is not in-built, you define the main()
method in your class which becomes the starting execution point for your application. The main() method must be public
, static
, return void
, and accept one parameter: a String
array. Any class with such a main()
method can be used as the starting point for a Java application.
The Java Virtual Machine starts up by creating an initial class, which is specified in an implementation-dependent manner, using the bootstrap class loader (§5.3.1). The Java Virtual Machine then links the initial class, initializes it, and invokes the public class method void main(String[]). The invocation of this method drives all further execution. Execution of the Java Virtual Machine instructions constituting the main method may cause linking (and consequently creation) of additional classes and interfaces, as well as invocation of additional methods.