Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Current Progress

Nasim Zoubeiri
Nasim Zoubeiri
2,652 Points

Running '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
Dennis Mårtensson
7,400 Points

I 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
Alex Popian
977 Points

I 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
STAFF
Craig Dennis
Treehouse Teacher

Yeah 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?