When preparing for the SCJP exam, we were going through the following code:
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?
Joined: Oct 13, 2005
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.