Results 1 to 10 of 10
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Arguments in Main

    Hey Guys just tell me whats the purpose of these String args[] in main .... I have searched on Google but fail to understand

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Arguments in Main

    When you invoke your program "java myprog arg1 arg2 arg3" they are passed as String arguments to the array.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Arguments in Main

    whats the purpose of passing these strings ?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Arguments in Main

    Quote Originally Posted by allaudin View Post
    whats the purpose of passing these strings ?
    Did you ever do a 'dir *.txt'? The '*.txt' part is a String argument for the 'dir' process.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    7

    Default Re: Arguments in Main

    allaudin,

    Firstly you have to understand is what is the purpose of passing variable in methods? If you understand this, you will get an answer for your first question.
    Mak
    (Living @ Virtual World)

  6. #6
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Arguments in Main

    I know passing variables in methods ... but where these strings are used in main ... ??? String args[]

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Arguments in Main

    I'm afraid reply #4 was written with invisible ink again ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Arguments in Main

    They are arguments to the program (this has been mentioned twice in this thread). They are only used at the discretion of the developer who wrote the application. If the application does not require any command line arguments to process then the String array is not used.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Arguments in Main

    thanks JIM (y)

  10. #10
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Arguments in Main

    Command line arguments solved my problem :)

Similar Threads

  1. Use of passing arguments in main method
    By REICHKONIG in forum New To Java
    Replies: 1
    Last Post: 01-01-2013, 05:50 PM
  2. Passing array arguments into main
    By JohnDas in forum New To Java
    Replies: 12
    Last Post: 11-10-2010, 04:00 PM
  3. Replies: 8
    Last Post: 09-23-2010, 01:07 AM
  4. Replies: 5
    Last Post: 10-06-2008, 01:11 AM
  5. Arguments in Main
    By CyberFrog in forum New To Java
    Replies: 2
    Last Post: 03-30-2008, 10:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •