Java Java Basics Perfecting the Prototype Reviewing Our Feedback

Classified Classified
Classified Classified
767 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?

3 Answers

28,473 Points

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 This asks Java to compile your source code (which is stored in 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 Jelani
Shafiq Jelani
161 Points

Running the command

clear && javac && java TreeStory

are actually means,

Run first command : clear <-- if this is succeeded without any fails(error) then, Run second command : javac <-- 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.

Angella McCoy
Angella McCoy
3,218 Points

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.