Main Method
Main Method
The main() is the starting point for JVM to start execution of a Java program. The main()
method is required for the JVM to execute the program.
Note: public static or static public these access specifiers can interchange their positions.
(More on this will be specified later once we speak these in detail as individual)
public: It is an access specifier. We should use the public keyword to let the JVM know
main() presence in the class(increasing the visibility of the main method).
static : static keyword is used to make the main() method static then jvm will call the method
without creating the object.
(static methods can be called without creating objects – More can be discussed in static
keyword concept)
void : Every method has the return type in Java. void keyword is used to inform the compiler
that the main() method does not return any value.
main: It is the name of the main method in java. JVM will start the program execution from
the main method as it is predefined for JVM hence It must be main and cannot be changed.
String [ ] args : It's the main method parameter to receive command line arguments.
Irrespective of whether the data(arguments) are passed from command line or not, the main
method must contain String []args. If we ignore String [] args from the main method then the
Java file will be compiled but cannot be executed by JVM. Hence it must be required in the
main method.
Note : Kindly also check Q and A pdf attached in resources to get more clarity of concepts
delivered in class.