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 trialDiego Silva
313 PointsJshell- REPLL
Hi guys
I didn't get the idea of the Jshell. Why do we need to use that? In some of his examples, I got confused, like those where we had $7==> Where this number came from?
2 Answers
Deneen Edwards
5,626 PointsThe Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code. JShell is a Read-Evaluate-Print Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
JShell helps you try out code and easily explore options as you develop your program. You can test individual statements, try out different variations of a method, and experiment with unfamiliar APIs within the JShell session.
....
When an expression is entered that doesn't have a named variable (such as you enter jshell> 5 + 5),
a scratch variable (such as $7) is created so that the value can be referenced later.
(jshell will return something like: $7 ==> 10)
In other words, it's just an auto-generated variable name.
But if you entered jshell> int myNum = 5 + 5..............jshell will return: myNum ==> 10
Darth R3id4k
Courses Plus Student 10,125 Points$ is nothing more than just ID (or dynamic implicitly consecutive generated variable name) of properly handled snipet. If you use command /list you will see list of all correctly executed snippets in the current JShell session. On the left side of this list there are numbers with colon - ID. You can use this number(s) in next snipet: 11 + 5 $10: 16 20 - $10 $11: 4 You can run snipet again by typing ID number ($4) /4