This content has been marked as final. Show 5 replies
This is a bit strange indeed; I ripped the following clause right from the JLS (paragraph 12.1.4)
The method main must be declared public, static, and void. It must accept a single argument that
is an array of strings.
So a private static void main(String args) should fail according to the 'law'.
Both the JLS and the JVM specs require that the main method to be public (note however that you are allowed to have a private, static, void method that takes a single String-array argument, but it should not be considered an application entry-point).
This was a bug introduced into Sun's VMs with early 1.2 releases; Originally there was no intention to fix it, but eventually they decided to do so, and it was fixed for 1.4.
If you do not declare your main methods public, static and void, you will find that your applications stop working one day when you switch Java versions, or when you roll the code out to clients using a different version to that which you developed and tested the apps on.