• 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

Using commandline arguments Query

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 100
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
command line arguments are implicitly converted to Strings
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not that they're converted to Strings, they are Strings.
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic