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 trialDrew Warren
4,565 PointsUsing your own website?
Craig mentions in the video that you should 'feel free to use your own website' when he creates the Project under the com.teamtreehouse package.
Can someone please explain to me a little bit about what that would entail? For example, if I own the domain, www.DrewsWebsite.com (I don't), and I use it as the package when I make a new Project, does that affect the website in any way? Are these things stored? Or is this just a Project Naming 'Best Practice'?
Or maybe just give me a link if there's a TreeHouse video or an external source that explains this?
Thank you!
2 Answers
lambda
12,556 PointsI believe the instructor is referring to the "package" keyword.
He's just saying that if you work for a company, organization, or if you have your own domain then you can use it for your package name. That's why the instructors use "com.treehouse" because all the files are related to treehouse.
Examples:
package com.mycompanyname.myproduct.myname;
package com.mywebsite.myproduct;
This is just a convention. Your code will still work if you name it something else, so long as the directory/file structure matches the package name (i.e. Program.java is inside the src/com/mycompany/myproduct/myname folders.
What you name the package doesn't really matter; it is a way to organize/structure your code. For example, I can name my java package anything.
package asdf.qwerty.randomletters;
The problem with that is no one will understand what "asdf" or "qwerty" refer to or means. So that's why people usually use meaningful package names.
To answer your questions:
For example, if I own the domain, www.DrewsWebsite.com (I don't), and I use it as the package when I make a new Project, does that affect the website in any way?
No, it will not.
Are these things stored?
No, it doesn't store anything on the website. But affects files/directories structure on your local machine.
Or is this just a Project Naming 'Best Practice'?
Yes, they are best practices/conventions that good programmers use and follow.
Drew Warren
4,565 PointsThanks for the reply. I think I understand. I just wonder now.. why did Craig create a 'com' folder as well as a 'treehouse' folder. It seems like if it didn't matter, why wouldn't he just have used teamtreehouse/model since nothing is stored in the com folder other than the treehouse folder.
lambda
12,556 PointsI believe it was mentioned in the video, but to reiterate. The convention is to use the reverse domain name so that it is unique and won't cause duplication conflicts.
If you just used "package com;" then a lot of people might also have it (since there are a lot of .com's) even if they are unrelated. For example, google.com, apple.com, microsoft.com (which com does com refer to?)
Likewise, if you used "package treehouse;" it might refer to treehouse.net or treehouse.org not just treehouse.com.
Again this is just a convention. But you can name your package anything you want. Just like how you can name your variables anything you want. But the convention is to name variables with meaning. The compiler doesn't care, it's all just letters to the compiler.
public int asdf = 0;
// This will compile and run correctly, but what is asdf? I don't know what this person is trying to say.
versus
public int numberOfCars = 0;
// Oh, this refers to the number of cars.
People usually follow conventions because it is a "best practice" (very good idea). Bad ideas usually die off on their own because they are bad and no on follows them.
Drew Warren
4,565 PointsThank you again for your time. That makes a lot more sense now.
If I were going to create a project for my company, I'd use the company website name just as a naming convention to house the project. It won't affect it if I named it otherwise, but if I had to pass the project to someone else, they would know "Oh, this is for the company I found at this website I visited after looking at their Project Name! Now I know what I'm looking at."
Steve Brewer
15,030 PointsSteve Brewer
15,030 PointsIf you had a domain you would need to 'point' it to a server where you would host the files for your website. You wouldn't be able to use it with Treehouse Workspaces (but you can use Workspaces to create whatever content you wish, it just wouldn't have a domain).
You could also create your own local website on your computer, which if you're just doing HTML, CSS and JavaScript you can do this without needing a local server program like MAMP.