*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about classpath" Watch "question about classpath" New topic
Author

question about classpath

foxy milano
Greenhorn

Joined: Jul 03, 2011
Posts: 5
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

Joined: Jul 19, 2011
Posts: 185
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

Joined: Jul 03, 2011
Posts: 5
@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

Joined: Jul 19, 2011
Posts: 185
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about classpath
 
Similar Threads
Compiling problem for Scjp
java command question
K&B Chapter 10 Self Help Question 9
problem in classpath and jar files and searching
compling files using classpath option