Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The Main method  RSS feed

 
Natraj Gudla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced a small problem,
When i write a small class , with a main method with only a string argument and not an string array , I do not get an compilation error where as i get a runtime error.
Why does not the compiler check the signature of the function at compile time.
can any one tell me how this works.?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM looks for a static method with the signature main(String[] args) as an entry point. There is no requirement to provide that method in a class so if you attempt to run a class and that method does not exist you get a RuntimeException. You can provide any number of main() methods (overloading) in a class as well, but the JVM will never look for those.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!