Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravinda,
Thank you for your answer. I am glad I was not loosing it.
 
shailesh sonavadekar
Ranch Hand
Posts: 1874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that does help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic