You are on page 1of 2

CORE-JAVA

Importance of Main()method in JAVA:

The main intention of main() in java application is

1.To manage application login in java applications.

2.To define starting point and ending point to the application execution.

Syntax:

public static void main(String[] args)

----instructions-----

Note: main() method is not predefined method, it is not user defined method, it is a
conventional method implementation.

Q) What is the requirement to declare main() method" public"?

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

public static void main (....)

2Q)What is the requirement to declare main () method as "Static"?

You might also like