• Post Reply Bookmark Topic Watch Topic
  • New Topic

java Main()  RSS feed

 
Ritesh Waghela
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why java compiler forces us to write a main method with String array parameter, and even though we don't pass any command line parameter while running java application from command prompt, why it does'nt throw any run time error. We have learnt that a method that takes a paremeter must be invoked with a paremeter of declared type, does JVM passes any sort of argument to main()?
 
Devaka Cooray
Marshal
Posts: 5649
765
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Ritesh Waghela wrote:does JVM passes any sort of argument to main()?

Yes. An array of command line arguments, if any. Otherwise, an empty array.
Please take some time to CarefullyChooseOneForum - this forum is only for the questions related to Servlets.
Moving to Beginning Java forum.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that it's not *us* calling main, it's the JVM itself: if we called it manually (and you can try this on your own) we'd need to pass in an argument, or our code wouldn't compile. When running a program from the command line the JVM itself creates the argument from any command-line parameters we pass in.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!