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 - Retired Getting There Packages

Adam Sawicki
Adam Sawicki
15,967 Points

DIRECTORY of package

Hey,

I tried move Example file to another folder rather than "com". If I do that Example file can't "see" the package. Is it possible to place my package anywhere in the hard drive and still be able to import it to my class?

regards ;)

2 Answers

Alison Brodribb
Alison Brodribb
24,615 Points

Hi Andrew

Did you remember to change the directory path for importing the Example file into your class?

You should be able to access it from anywhere as long as you have the correct path:

E.g. if the example post is in the "test" folder, then to import into your main class, you would write:

import test.Example;

Adam Sawicki
Adam Sawicki
15,967 Points

So, what I realized is that I can access my package from anywhere but it calls for change of directory in "package" statement and "import" statement as well. How It happens that java packages can be imported from anywhere in the computer without changing directories e.g java.util.* is always imported with the same path no matter where importing class is placed.

regards ;)