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 trialnasimoyz
2,652 PointsRunning 'javac Hangman.java' seems to compile all '.java' files
Why don't we have to also compile Game.java and Prompter.java in the command line javac step? Are they automatically compiled when compiling Hangman.java because Hangman instantiates objects of those classes?
I'd image the javac command would look more like: clear && javac Hangman.java Game.java Prompter.java && java Hangman
Thanks!
3 Answers
Dennis Mårtensson
7,400 PointsI suppose it is as you say, when you tell the compiler to compile one file, it automatically compiles all other files relating to the file you are implicitly compiling. I'm no expert on the subject though, but that's a reasonable explanation!
Alex Popian
977 PointsI thought it was because it was the main file of the package we are working with (Which holds all the classes). I'm no expert either but I feel like main is connected to all other classes therefore compiling it compiles the whole package? Craig Dennis is this right?
Craig Dennis
Treehouse TeacherYeah it is because you are requiring the other java classes by importing them. When compilation happens it compiles the files it needs, which in this case is Game and Prompter.
That make sense?