Newbie: Java Import and compile statement

Discussion in 'Java' started by Rachel, Jul 3, 2003.

  1. Rachel

    Rachel Guest

    Hi,

    1. I have 3 files:

    c:\folder1\folderA\file1.java // no package statement inside
    c:\folder1\folderA\file2.java // no package statement inside
    c:\folder1\folderB\file3.java // package folderB;

    2. I've compiled file1 & file 2:
    c:\folder1\folderA> javac *.java
    So, c:\folder1\folderA contains file1.class & file2.class

    3. Now, I want to import file1.class & file2.class from c:\folder1\folder11.

    Question:
    a. What should the import statement be in file3.java?
    b. In C:\folder1\folderB, what should the javac statement be for file3.java?

    Thanks much,
    Rach
     
    Rachel, Jul 3, 2003
    #1
    1. Advertising

  2. Rachel wrote:
    > Hi,
    >
    > 1. I have 3 files:
    >
    > c:\folder1\folderA\file1.java // no package statement inside
    > c:\folder1\folderA\file2.java // no package statement inside
    > c:\folder1\folderB\file3.java // package folderB;
    >
    > 2. I've compiled file1 & file 2:
    > c:\folder1\folderA> javac *.java
    > So, c:\folder1\folderA contains file1.class & file2.class
    >
    > 3. Now, I want to import file1.class & file2.class from c:\folder1\folder11.
    >
    > Question:
    > a. What should the import statement be in file3.java?


    import file1;
    import file2;

    > b. In C:\folder1\folderB, what should the javac statement be for file3.java?


    javac -classpath
    c:\folder1\folderA\file1.class;c:\folder1\folderA\file2.class

    > Thanks much,
    > Rach
     
    Ahmed Moustafa, Jul 4, 2003
    #2
    1. Advertising

  3. Rachel

    Jon Skeet Guest

    Rachel <> wrote:
    > 1. I have 3 files:
    >
    > c:\folder1\folderA\file1.java // no package statement inside
    > c:\folder1\folderA\file2.java // no package statement inside
    > c:\folder1\folderB\file3.java // package folderB;


    That's your first mistake then. Always use packages, and always have
    your source layout matching the package layout.

    See http://www.pobox.com/~skeet/java/compiling.html

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet/
    If replying to the group, please do not mail me too
     
    Jon Skeet, Jul 4, 2003
    #3
  4. Rachel

    ghl Guest

    "Ahmed Moustafa" <> wrote in message
    news:UW9Na.24854$...
    > Rachel wrote:
    > > Hi,
    > >
    > > 1. I have 3 files:
    > >
    > > c:\folder1\folderA\file1.java // no package statement inside
    > > c:\folder1\folderA\file2.java // no package statement inside
    > > c:\folder1\folderB\file3.java // package folderB;
    > >
    > > 2. I've compiled file1 & file 2:
    > > c:\folder1\folderA> javac *.java
    > > So, c:\folder1\folderA contains file1.class & file2.class
    > >
    > > 3. Now, I want to import file1.class & file2.class from

    c:\folder1\folder11.
    > >
    > > Question:
    > > a. What should the import statement be in file3.java?

    >
    > import file1;
    > import file2;


    This is incorrect and is now officially wrong. You cannot import from the
    unnamed package.
    Place all classes in a package from now on. Only use unnamed code for quick
    tests and minimal demos.
    --
    Gary
     
    ghl, Jul 4, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JPractitioner
    Replies:
    13
    Views:
    20,162
    Roedy Green
    Feb 24, 2006
  2. Nagaraj
    Replies:
    1
    Views:
    870
    Lionel B
    Mar 1, 2007
  3. timjowers
    Replies:
    7
    Views:
    4,351
    heyjude
    Feb 2, 2011
  4. zalek
    Replies:
    6
    Views:
    277
    Arne Vajhøj
    Jul 27, 2008
  5. Stéphane Klein
    Replies:
    0
    Views:
    275
    Stéphane Klein
    Jul 5, 2011
Loading...

Share This Page