aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main method " Watch "main method " New topic
Author

main method

Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
What are the valid signatures for the main method?
The only valid one I know of is:
public static void main(String variable []) and
"static" is required". Also, by default main is final.
However, I tried the below with protected, private, and friendly, and I am not getting an error. Also, could you let me know if any of my assumptions are wrong or incomplete.
<CODE>
public class Parent {
final void zzz() {
System.out.println("zzz6");
}
void main(String args []) { //errored must have static
//static void main(String args []) { //no errors on below sign.
//final static void main(String args []) {
//final private static void main(String args []) {
//private static void main(String args [])
//protected static void main(String args [])
//static void main(String args [])
new Parent().zzz();
}
}
</CODE>
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Charlie,
This is bug#4155575 with the JVM and you can check-it out by
clicking it here .
We had a discussion on the same topic at
http://www.javaranch.com/ubb/Forum24/HTML/009364.html
Hope this clears your doubt.
Ravindra Mohan
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Do you know where I can get a hold of the Java VM specifications?
This is for future reference, and I wanted to see the signature of the main method. That is the access modifiers, and if final is used by default.
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Ravinda,
Thank you for your answer. I am glad I was not loosing it.
shailesh sonavadekar
Ranch Hand

Joined: Oct 12, 2000
Posts: 1874
Charlie , If I have not mistaken , JAVA VM specifications are available for free download from www.javasoft.com ( Books in Sun series ).
I hope that can be helpful to you.
Your Friendly Bartender
Shailesh.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Charlie,
Just an FYI, <code>main()</code> is not <code>final</code> by default. The following is also a valid declaration:

The only caveats are:

  • 'void' must precede 'main'
  • it must be declared 'public'
  • it can have only one parameter which must of type 'String[]'

  • <code>main()</code> is treated as any other method with the exception that it has the 'special' meaning of being the first method the JVM will look for when an application is started.
    Hope that helps.
    ------------------
    Jane Griscti
    Sun Certified Programmer for the Java� 2 Platform

    [This message has been edited by Jane Griscti (edited May 24, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Thanks, that does help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method