• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about classpath

 
foxy milano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following directory structure:

x-
---|- FindBaz.class
---|
---|- test-|
-----------|- Baz.class
-----------|
-----------|- myApp-|
-----------------------|- Baz.class

And given the contents of the related .java files:

In the test directory:

In the myApp directory:

If the current directory is x, which invocations will produce the output "test/Baz"?
(Choose all that apply.)

A. java FindBaz
B. java -classpath test FindBaz
C. java -classpath .:test FindBaz
D. java -classpath .:test/myApp FindBaz
E. java -classpath test:test/myApp FindBaz
F. java -classpath test:test/myApp:. FindBaz
G. java -classpath test/myApp:test:. FindBaz


in k&b the answers are C , F
but why B and E are not true??
I know that the comand java search to file class to execute in the current file by default and the classpaths in the command are used to search the other files that the class file need. since we are already in the x directory, and that directory already contain the file class FindBaz.class .... why B and E are false....??
please if someone can explain me...
thks
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that the comand java search to file class to execute in the current file by default and the classpaths in the command are used to search the other files that the class file need. since we are already in the x directory, and that directory already contain the file class FindBaz.class

If you don't specify a classpath then the default classpath is used which is the current directory. But if you specify a classpath then only that classpath is used meaning if you don't include the current directory (.) then the current directory is not included in the search for classes.

John
 
foxy milano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@JOHN
SO if i understand well... with java comand i have to specify where to search for class file(using the classpath ) if i dont use the classpath java will use the default directory,once i specify the classpath the default directory is not valid anymore.
but with javac, i don't have to specify the .java file to compile , javac will use the default directory to search a .java even if i specify the classpath and classpath will be used to find other classes the .java file need to be compiled.
thannks
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SO if i understand well... with java comand i have to specify where to search for class file(using the classpath ) if i dont use the classpath java will use the default directory,once i specify the classpath the default directory is not valid anymore.

Yes, that's right.

but with javac, i don't have to specify the .java file to compile , javac will use the default directory to search a .java even if i specify the classpath and classpath will be used to find other classes the .java file need to be compiled.


Yes. I guess as the .java file is not a class file searching for it is not affected by the classpath.

John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic