• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java Main()

 
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()?
 
Sheriff
Posts: 6631
1254
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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.
 
Author
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.
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic