Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie: Java Import and compile statement

Reply
Thread Tools

Newbie: Java Import and compile statement

 
 
Rachel
Guest
Posts: n/a
 
      07-03-2003
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


 
Reply With Quote
 
 
 
 
Ahmed Moustafa
Guest
Posts: n/a
 
      07-04-2003
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


 
Reply With Quote
 
 
 
 
Jon Skeet
Guest
Posts: n/a
 
      07-04-2003
Rachel <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
ghl
Guest
Posts: n/a
 
      07-04-2003
"Ahmed Moustafa" <(E-Mail Removed)> wrote in message
news:UW9Na.24854$(E-Mail Removed) rthlink.net...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
imp.find_module don't found my module but standard import statement can import this module… why ? Stéphane Klein Python 0 07-05-2011 07:36 AM
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
trying to compile after using "import java.lancs.*" Cory Lechner Java 3 05-19-2004 03:01 PM



Advertisments