| Author |
Using commandline arguments Query
|
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
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
|
OCPJP 6.0 93%
OCPJWCD 5.0 98%
|
 |
Gari Jain
Ranch Hand
Joined: Jun 29, 2009
Posts: 100
|
|
|
command line arguments are implicitly converted to Strings
|
OCPJP 6-100%; Preparing for GATE11
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
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
Joined: Jun 29, 2009
Posts: 100
|
|
|
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
Joined: Apr 06, 2010
Posts: 3793
|
|
|
It's not that they're converted to Strings, they are Strings.
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
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
Joined: Mar 07, 2010
Posts: 438
|
|
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
|
SCJP 6 [86%] June 30th, 2010
If you find any post useful, click the "plus one" sign on the right
|
 |
Gari Jain
Ranch Hand
Joined: Jun 29, 2009
Posts: 100
|
|
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]
|
 |
 |
|
|
subject: Using commandline arguments Query
|
|
|