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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Development" Watch "Development" New topic
Author

Development

swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

And the following subdirectory structure:

test
|-UseKit.class
|
com
|- KitJar.jar
|
pkg
|-Kit.class

If the current directory is test, and the file pkg/Kit.class is in KitJar.jar, which command line will produce the output bc?

One of the answer is: "> java -cp com:. UseKit a b c"

I am not getting this answer. Please let me know the reason.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

swaraj gupta wrote:
If the current directory is test, and the file pkg/Kit.class is in KitJar.jar, which command line will produce the output bc?

One of the answer is: "> java -cp com:. UseKit a b c"

I am not getting this answer. Please let me know the reason.


Did the question just ask whether it will work? Or will it work by using in the class in the jar file?

With that run, it will work -- but it will use the Kit.class file directory (in the test.com.pkg directory). And not the kit.class file in the jar file.

Henry
swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

Did the question just ask whether it will work? Or will it work by using in the class in the jar file?

I have put the question exactly in the same way it is asked. The question is having other options as well but those are clear to me.

With that run, it will work -- but it will use the Kit.class file directory (in the test.com.pkg directory). And not the kit.class file in the jar file.
How is it possible if interpretor is instructed to search for the supporting Kit.class in:
1> com package
2> current directory (test)

and both do not have the Kit.class file.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

swaraj gupta wrote:
With that run, it will work -- but it will use the Kit.class file directory (in the test.com.pkg directory). And not the kit.class file in the jar file.
How is it possible if interpretor is instructed to search for the supporting Kit.class in:
1> com package
2> current directory (test)

and both do not have the Kit.class file.


The classpath specifies the *root* directories to search in, and not the exact directories to search in... and since the Kit class is in the pkg package, it will searching in the pkg directory off of those root dirs that you listed, for that class.

Henry
swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

Sorry sir, I didn't get your point..
The classpath specifies the *root* directories to search in, and not the exact directories to search in.


According to my weak knowledge: "classpath option is used to specify the paths where java or javac look in to search for the supporting files for the compilation or execution operation to be successful."
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

swaraj gupta wrote:
The classpath specifies the *root* directories to search in, and not the exact directories to search in.


According to my weak knowledge: "classpath option is used to specify the paths where java or javac look in to search for the supporting files for the compilation or execution operation to be successful."


Maybe it would be good idea to revisit how classpaths work...

http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

Because it is not as simple as a list of directories to search for files -- it also depends on what package the classes are in.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Development