Reputation: 81
A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the command:
java -classpath /test:/home/bob/downloads/*.jar games.Chess
Bob's CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)
Answer is C but I want to know how it is ...........
Upvotes: 1
Views: 1264
Reputation: 692023
The classpath is explicitely passed to the java command, so it supersedes the CLASSPATH environment variable. Answers B, D, E and F are thus incorrect.
A is incorrect since the class name is games.Chess
. Since the package and the directory structures must match, the Chess.class file must be in a games folder (inside or outside a jar file).
C is correct.
G is incorrect because you can't pass *.jar to a classpath. And even if Games.jar was explicitely in the classpath, the manifest doesn't play any role here.
See http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html for the documentation about the classpath.
Upvotes: 6