Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using commandline arguments Query

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i pass 12 at cmd then it would get stored in arg[0],how that's possible as arg is an array of string type

 
Gari Jain
Ranch Hand
Posts: 100
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
command line arguments are implicitly converted to Strings
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GAri,could you refer to me a link where can i see how they are converted to strings
is it possible to pass anything at command line and that would be implicitly converted to string
 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this because whenever you want to use any element of the array which you are passing to main method, if it is not a String, i.e you passed in an integer then you have to parse it using Integer.parseInt(), Boolean.parseBoolean() and such and such methods.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that they're converted to Strings, they are Strings.
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew said

It's not that they're converted to Strings, they are Strings.


if they are not converted to strings,then

when i pass 12 or 12.0 HOW they are accepted into array of type Strings


i.e. String[] arg
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what matthew wanted to say is that
whatever we write on the command line, they are Strings actually, they are not converted into Strings THEY ARE STRINGS

you may be confused because of the fact that we do not give double quotes there on command line
but it is optional when we are passing command line arguments
THEY ARE STRINGS thats it

Happy preparation
 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:It's not that they're converted to Strings, they are Strings.



Yup that is what I meant, they take those double quotes automatically, but what is exactly happening is not known to me and I would love to know what is exactly happening, how are we able to pass arguments without quote and it gets converted into string and why does it get converted into String?Is the toString() method called?

[EDITED]No toString() is not called[EDITED]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic