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!
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
Classified Classified767 Points
What's the exact reason we run 'clear && javac TreeStory. java && TreeStory'? What's it mean/do?
My guess is 'clear' clears the cache and what was done before. But I don't understand why we run 'javac TreeStory' at the same time as 'TreeStory' right after. Is it because 'javac' compiles and 'TreeStory' is what it's gonna be named?
I'll explain one command at a time:
clear: It actually just clears the terminal window of text. It does not clear up any cache or anything like that. You can leave off this command and your program would still run fine. The terminal window would just be a bit more messy.
javac TreeStory.java: This asks Java to compile your source code (which is stored in TreeStory.java) into code that java itself can execute.
java TreeStory: This tells Java to execute the program you just compiled.
If you only ran
javac then you would compile the program but not actually run it. And only running the command to run it would also not work, since it needs to be compiled first. Therefore both of those commands are necessary.
Shafiq Jelani161 Points
Running the command
clear && javac TreeStory.java && java TreeStory
are actually means,
Run first command : clear <-- if this is succeeded without any fails(error) then, Run second command : javac TreeStory.java <-- if this is succeeded without any fails(error) then, Run third command : java TreeStory
Basically you are combining multiples commands into one line so that you dont have to run the commands one by one each time you want to compile your JAVA code. For the usage of each command, you can refer to andren answer above.
Typing "clear && javac TreeStory. java && TreeStory" in one line is a more efficient way of having the system to execute the commands. You could enter each command one line at a time, however (for efficiency), it is best to create one command line, and allow the system to execute each command, without user interaction (at each step), from the programmer.