• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method passing of arguments

 
naveen patil
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
main method has String arguments as its parameter , but it works fine even when we dont pass any arguments to main method at command prompt. How is that?

Thank You.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because they are optional.
 
naveen patil
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
optional in the sense? Can you please tell something more
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to enter any arguments. No error will occur; the string array will simply be empty,
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3664
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naveen patil wrote:main method has String arguments as its parameter , but it works fine even when we dont pass any arguments to main method at command prompt. How is that?

Thank You.

Not passing any argument basically means that you are passing zero arguments and that is what you will get in the String[] parameter of the main method i.e. a String array of length 0. I wouldn't call it "empty", which could be misconstrued to mean that all its elements are null.

HTH,
Paul.
 
Mala Gupta
Author
Ranch Hand
Posts: 280
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naveen,

Java runtime passes to the main method a String array with 0 elements, if you don't pass any runtime arguments to it.




With respect,
Mala
 
naveen patil
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mala Gupta wrote:Naveen,

Java runtime passes to the main method a String array with 0 elements, if you don't pass any runtime arguments to it.




With respect,
Mala

Thank you much clear now . Am reading your book for OCA JP 7 exam preparation.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic