Re: Why a simple package statement
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 11/21/03
- Next message: Christopher Dean: "Re: Synchronizing on SimpleDateFormat vs. clone"
- Previous message: David Zimmerman: "Re: ANT question regarding Env Variable?"
- In reply to: lonelyplanet999: "Re: Why a simple package statement"
- Next in thread: lonelyplanet999: "Re: Why a simple package statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 Nov 2003 13:06:52 -0500
lonelyplanet999 wrote:
> That means, if I should give a .java file a package name such that
> it's class can be referenced in other .java files. I must create
> corresponding directory to accommodate it ?
That is not absolutely required, but it is very good practice. Among
other things, it allows the java compiler to find and compile
dependencies at need.
> e.g. Now I place all .java files under c:\javapgm. I call
> c:\j2sdk1.4.1_01\bin\javac & c:\j2sdk1.4.1_01\bin\java under
> c:\javapgm to compile & run java programs.
>
> 1. If I named File1.java as "package package1;", I need to place
> File1.java under c:\javapgm\package1\
That should work. There are alternatives, but I wouldn't worry about
them right now.
> 2. If another file under c:\javapgm named File2.java without package
> statement needs to reference class inside package1.
> 3. File2.java needs the statement "import package1.*;" or
> "package1.<specific class>;" to import specific class.
The location of the source file is not directly relevant to how the Java
class(es) it describes must refer to other classes. If classes in any
package other than package1 want to access members of package1, though,
then the alternatives you describe are indeed the available options.
> 4. If another file named File3.java with "package package3;" statement
> needs to reference class inside File1.java too.
> 5. File3.java needs to be stored under "c:\javapgm\package3\".
This would be best.
> 6. File3.java needs import "package1.*" or "package.<specific class>;"
> inside it under "package package3;" statement.
As described above, the relevant criterion is the package to which a
class is assigned, not the structure of the source tree, but yes, that's
correct.
John Bollinger
jobollin@indiana.edu
- Next message: Christopher Dean: "Re: Synchronizing on SimpleDateFormat vs. clone"
- Previous message: David Zimmerman: "Re: ANT question regarding Env Variable?"
- In reply to: lonelyplanet999: "Re: Why a simple package statement"
- Next in thread: lonelyplanet999: "Re: Why a simple package statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|