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

args explanation in java

on this post (https://teamtreehouse.com/community/finally-uncomment-the-addpost-method-in-forumjava-then-for-the-last-task-uncomment-the-main-method-in-examplejava) in Example.java when making a new User called author why pass in the args[0] and args[1]. How did the strings get added to the String array args?

1 Answer

Corey Johnson
PLUS
Corey Johnson
Courses Plus Student 10,192 Points

The Example class has a main method, which means this class can be executed via the command line. Assuming the Example class was in a package of com.foo, in a directory named out, i would execute with command line arguments like so:

java -cp out com.foo.Example First Last

This would create a User object named "author" with a fist name of "First" and a last name of "Last"

Hope this helps.