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 trial

Java Java Objects (Retired) Creating the MVP Storing Guesses

How do you know which code goes into which .java file? (In any coding project, not just this Hangman game)

I also don't understand how one knows which file to run when they all do things to the game.

2 Answers

Hi Stephanie,

When you have multiple .java files (and a big project), you write different bits of code in each one. Then one of them is written in to run them all. This is done to break the project down into bite sized pieces.

I hope this helps.

Will Beasley
Will Beasley
6,020 Points

Hey Stephanie, I'll try an elaborate on what Peter was getting at. Java, as I'm sure you know is an object oriented language. What this means is that Java is comprised of Classes which contain methods and properties. When creating a class the idea is fairly straight forward (at least on the surface). You think of them as objects in the real world. Think about a car as a class. A car has properties like color, make, model, miles, etc. These are all unique to a specific car. But there is more to that car, like an engine for example. An just like a car an engine has various properties you must define like horsepower. You could even go far as to talk about sub-classes. I'm not sure if this has been touched on by treehouse in this point but I'll dive right in. A sub-class is just a class but with one special feature, it can INHERIT from another class. I only capped the inherit because this is core Java, it is on of the 4 core principles of Java and OOP. Going back to the car feature, what if instead of needing to list out details of a car that is shared among trucks, SUVS, motorcycles and so on we create a class that they can all derive from. This is what is known as a super-class. We create this super-class which we can call automobile for this example and all of these sub-classes will then EXTEND (keyword) it. This could even go a step further by saying well, there are properties that an automobile shares with a boat, a plane, and so on. Then you could go so far as to create what is known as an interface. This contains a list of methods you know each class that IMPLEMENTS (another keyword) it will share. These methods are known as ABSTRACT (another core principle) method. This is a fancy way to say they don't have anything in them much like a constructor and you will need to add that in the class that implements the interface. I know this is a lot but good OOP/OOD practice is a subject in and of itself, one that deserves its own course here on treehouse TBH. It takes time to identify when to put code in a particular place and comes with practice. A good starting point would be thinking of classes in a 'is-a' or 'has-a' relationship. A prius IS-A car (meaning it will inherit) which HAS-A motor (meaning it will be a property). Hope this helped and sorry for the long winded answer, unfortunately there is no quick way to cover such a broad subject. If you want more details there are a ton of great books on this subject like The Fundamental Concepts of Object-Oriented Programming or The Object Oriented Thought Process.

Hi Will,

Thanks for elaborating on what I said.