This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: why public for main
- From: Eric Blake <ebb9 at email dot byu dot edu>
- To: amroz kamal siddiqui <kamalamroz at rediffmail dot com>
- Cc: java at gcc dot gnu dot org
- Date: Mon, 07 Apr 2003 07:28:06 -0600
- Subject: Re: why public for main
- References: <20030405165307.30514.qmail@webmail24.rediffmail.com>
Because JVMS 2.17.1 (and also JLS 12.1.4) require that the entry point
of any Java program be public static void main(String[]). The main
method can optionally be final, synchronized, strictfp, or native
(although I've never run across a native main method). Likewise, the
throws clause (if included) for the main method is arbitrary and has no
restrictions.
Yes, you can write a main with a different signature (ie. non-public,
non-static, different return type, or overloaded with different
parameters), but it can then only be called from your code, rather than
being the entry point.
If gcj compiles a program with the --main option pointing to a class
without a public static void main, it should be a compile-time (or at
least a link-time) error. If gij runs a Java program that does not have
a public static void main, it should be a runtime error. (If this isn't
the case, these programs have a bug; file a bug report.)
amroz kamal siddiqui wrote:
hello friends out there,
Iam a newbie in java, I just have a simple and a very
annoying ( at least to me ) question. Why do we use the keyword
public for the main method ?
eg.
public static void main(String arg[])
--
This signature intentionally left boring.
Eric Blake ebb9 at email dot byu dot edu
BYU student, free software programmer