Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 70
    Worth noting is that args doesn't necessarily have to be named args (you can name it whatever you want) - though it's best to follow convention. You also might see String... args from time to time, which is equivalent. Commented Jun 20, 2013 at 6:40
  • 87
    args indexing start at 0. (contrary to C giving you the name of the program) Commented Mar 21, 2014 at 10:48
  • 1
    @Daniel, Is args guaranteed to be separated by space regardless of OS? Commented Jun 17, 2014 at 21:08
  • 1
    @Luke That can not be true, at least not on Unix systems. There the shell passes arguments to the program already split according to the shell's rules (with quoting/escaping removed accordingly). There is no way for the program (the java interpreter in this case) to access the original unsplit command line, nor should it wish to do so because it would confuse the hell out of the user. Commented Nov 12, 2016 at 14:17
  • 1
    If some future user wonders how the arguments are received by the main method – first, the arguments are passed to the JVM by the shell's rules. Most shells split by spaces. Then the JVM initializes a String[] for you, filled with the arguments. This array is then passed to the main method as argument. Commented Feb 10, 2020 at 22:18