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

Katie Diamond
Katie Diamond
2,035 Points

What are the "$"s in "$3" and "$4" in this video (Welcome Back with Craig Dennis) about Java basics?

In this video, there are instances of variables being returned as something like:

$3 ==> true $4 ==> false $5 ==> 40

What does the "$3" mean, for example? Where are these variable coming from? I googled it and it sounded like a dollar sign meant an error, but these clearly are not errors.

Thanks so much! Katie

1 Answer

When the output of an expression is not explicitly assigned to a variable, JShell creates a variable of the form $ followed by an integer to refer to the output so that the output can be used later. For example, boolean b = $3 && !$4 will explicitly assign the value true to the variable b since $3 was assigned to be true and $4 was assigned to be false. If instead you used $3 && !$4 by itself, JShell will create a new variable $6 with a value true.