Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Delivering the MVP Arrays and Command Line Arguments

passing in args[0]

I don't understand how we can pass into our objects "args[0]" and "args[1]".

Where is that coming from? The main method? Even if we did pass it in, is there actually any data in "args[0]" and "args[1]" ??

1 Answer

Hi Tony,

args take on the value of the arguments passed in, via command line, when the program is executed.

For example, java MyProgram foo bar baz has three command line arguments being passed into the program and will be available from the args variable at run time.

public static void main(String[] args) {
  // args[0] == 'foo';
  // args[1] == 'bar';
  // args[2] == 'baz';
}

Hope this helps,

Cheers

That helps thanks!