• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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.
4 Solutions
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-> (classname.java 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.


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 Mailer.java)

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 that..it will show the icon in yellow color on doubleclick..it 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 Main.java
and one more package for eg
under this u got one more class Error.java and u  got one static method called getE()

In the Main.java 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/Main.java

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 ?


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now