File locations

Posted on 2004-11-17
Last Modified: 2010-03-31
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.
Question by:Tacobell777
    LVL 2

    Assisted Solution

    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.
    LVL 2

    Expert Comment

    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
    LVL 2

    Assisted Solution

    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.


    LVL 5

    Expert Comment

    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.
    LVL 2

    Expert Comment

    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.

    LVL 2

    Assisted Solution

    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
    LVL 3

    Accepted Solution

    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 ?


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    java JDK Download 7 49
    Java: Convert List<Object[]> to List<MyBean> 3 34
    bunnyEars challenge 6 45
    for i loop in grovy 1 26
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now