Core-Java Importance of Main Method in JAVA:: Public Static Void Main (String Args) ( - Instructions - )
Core-Java Importance of Main Method in JAVA:: Public Static Void Main (String Args) ( - Instructions - )
2.To define starting point and ending point to the application execution.
Syntax:
----instructions-----
Note: main() method is not predefined method, it is not user defined method, it is a
conventional method implementation.
In java applications to strart applications execution jvm has to access main() method, to
access main() method scope must be available to jvm. To bring main() method scope to the
jvm we have to declare main()method as "public".
If we declare main() method as private then that main() method is available upto the
respective main class only, not to the jvm, so that jvm is unable to access main() method.
if we declare main() method as <default> then main() method is available upto the respective
package only, not to the jvm, so that jvm is unable to access main() method.
if we declare main() method as "protected " then main() method is available upto the present
package and upto the child classes available in the other packages, but not the jvm, so that
jvm is unable to access amin() method.
id we declare main method as "public " then main() method is available through out the java
application or through out the system including jvm, so that, jvm is able to access main()
method.
Note: If we declare main() method with out "public" then coplier will not raise any error, but in
jvm will provide the following messages.
JAVA6: Main method not public
JAVA7: Error: Main method not found in class Test, please defined