aspose file tools
The moose likes Java in General and the fly likes Confusion regarding Java Packages and Windows Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Confusion regarding Java Packages and Windows Directory" Watch "Confusion regarding Java Packages and Windows Directory" New topic
Author

Confusion regarding Java Packages and Windows Directory

Soham Das
Greenhorn

Joined: Mar 24, 2011
Posts: 8

When preparing for the SCJP exam, we were going through the following code:

And this:

I placed both the above files in the following directory: C:\scjp\temp8 ; and the strange thing is that, the .java files are compiling and results in two .class files being created in the same directory. The thing I want to ask, is that, the difference between packages and directory. Isn't it true that the class files could be created in a directory other than the one stated in the package declaration? And the package declaration is something 'virtual', and disregards the windows directory structure. In addition, isn't it also true that, by executing the following command:

javac -d . OtherClass.java

The directories are created conforming to the package declaration, which isn't always mandatory?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
Not at all. You are not creating class files in the same directory, but in directories corresponding to the package names. Or more precisely you would be if you had spelt the package names the same
You get OtherClass.class in the "certificaton" directory and AccessClass.class in the somethingElse directory.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Confusion regarding Java Packages and Windows Directory
 
Similar Threads
Another Enthuware question
need help to understand packages
SCJP6.0 Book package example but when trying to compile using javac -d OtherClass.java its notcmpng
Packages etc.