• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java Main()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?
 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic