File locations

I am new to Java, I am hoping someone can tell me where to put my files;


And how do I make sure it finds classes it needs to import when I compile the code.
LVL 17
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In which enviroment are you working on?
In my case I'll create serveral folders for example:

First of all I'll create this folders on the same level:

Then I'll put all *.java in subroot "src" and all classes in subroot "classes" with this directory structure inside for each subroot:

com->myproject->classname-> ( or classname.class)

The same structure for both subroots. Is an easier approach to create packages.
Hope that helps.
To use the .class you have to add in the CLASSPATH the path of the classes that you want to use. As a java standard you have to create a subdir for each class
Another comment,

If you have 5 .java that are classes inherited from another, you can do this, for example:

Project: Tree -

The first structure will be like this:

Suppose that you have 3 more classes inherited from fathertree then you will do:

You'll put the .classes under the classes subroot. As a naming convention in java all the class files begin with a capital.


Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

use JBuilderX Enterprise version.
in JBuilderX when u import packages and classes.
and if they are not used in class then their color becomes gray. otherwsie black.
Well, you have to add the subdirs to the classpath, for example:
I have this class: src->com->hydranet->mailer->Mailer.class (or

If I want to import it, I'll put in my classpath the path "src" then I'll declare the import this way: import com.hydranet.mailer.Mailer;

Is good to have all the structure in the import because you can see the inherited classes in it.

The best way to do is to follow these steps:

 1. create a package by putting all the use full classes which you want to import in the package.
 2. compile the complete package.
 3. create jar of that package.

    jar -cvf jarfilename.jar packagename.*;

 4. set the -classpath for that .jar file before compiling ur code in which ur importing that package or required classes.

 5. Run your code

if you still got any confusion then don't hesistate to ask
download eclipse..
it will prevent compile errors also it provides necessary sugeston to avoid errors on double clicking the icon
It manages import on click(it automatically imports the necessary package.
try this
u dont need to worry about will show the icon in yellow color on will automatically import for u...good one
for ur problem...

first set the class path for java
path=ur jdk path/bin (e.g D:\bea\jdk141_02\bin)
classpath=ur jdk path/lib (e.g D:\bea\jdk141_02\bin)

create package for eg
under this package u got one class
and one more package for eg
under this u got one more class and u  got one static method called getE()

In the if u want to use this getE() of Error class

u need to code
Package com.test.maint;
import com.test.error.Error;
ublic class Main{
public void doX(){

Let these two classes lies in D:/test/

If u compile like D:/test/javac -d . *.java
-d for package options and . for current directory
Instead of . u can specify the path where u want to put the class files.

the generated class files will be under

for u want to use external jar use classpath option

ANy doubts ?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.