Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package

 
mike zhang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
william2000
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic