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 Data Structures Getting There Packages

Aditya Puri
Aditya Puri
1,080 Points

Don't really get what packages mean.

I don't really get the idea of packages. What are they?

Also I don't understand the "com.teamtreehouse" thing.

Please help

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

There are a lot of answers in the web about it. Check out this discussion on Stack for example:

http://stackoverflow.com/questions/1088509/what-is-the-purpose-of-defining-a-package-in-a-java-file

Also very simple reason, could be that there are not so many words in English Language to distinct different classes when you use many classes in your application:

The more libraries will you use in your App, or frameworks: like Spring or Hibernate (see courses here at Treehouse) the more you have to decide which class you want to use.

Take "Spring Security Workshop" App 'todotoday'. If I type User class, my IDE will print my following User classes and many many others:

  • org.springframework.security.core.userdetails.User;
  • org.springframework.boot.autoconfigure.security.User;
  • org.apache.tomcat.jni.User;

Now you see that a lot of libraries define the same class "User", and the only way to differentiate is using different packages.

About com.teamtreehouse: it is just style following a convention of package names in Java, please read this:

https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

Good quote from there

Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.