File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package" Watch "package" New topic
Author

package

mike zhang
Ranch Hand

Joined: Feb 26, 2002
Posts: 59
If I have a java pgm as follows:
***********
package dir;
public class Test {
...
...
}
**************
1. In order to compile it, I can either do "javac dir/Test.java" at the same directory level as "dir" or do "cd dir" followed by "javac Test.java", both are correct and the resulting 'Hello.class" will be the same, right ?
2. In order to run it, I can do "java dir.Test" at the same directory level as "dir". If I include the Hello.class into my classpath, then I should be able to run it at ANY directory level, but at that level I should still type "java dir.Test" instead of 'java Test', right ?
Thanks,
Mike
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Well... I think you are doing it correctly, but I'll argue with you concerning your consideration of what "at the same directory level" means.
It would appear that you are using this phrase to mean that given a subdirectory of sub of a parent directory parent, while working from the parent directory you are saying you are working "at the same directory level" as sub - which I'd consider an improper description of the working directory. In this example, the working directory is not "at the same directory level" as sub. The working directory is the parent directory of sub.
To repeat and rephrase, it looks like you're doing things correctly, but you aren't working "at the same directory level" as the subdirectory - you are working from the parent directory.
Making sense?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
william2000
Greenhorn

Joined: Apr 21, 2002
Posts: 1
so , i think u item 1 is right,but the item 2 has somthing wrong, include hello.class into u classpath have no effect,if u include the parent directory level of 'dir' ,u can 'java dir.Test' at any directory level,but no 'java Test'
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
william2000,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package
 
Similar Threads
I got a magic experience about java classpath
Package creation
javac options
Basic problem
packing classpath errors