Thanks for the reply. I just typed the questions in the book this time,
Page 830, "Question12"
Given the following directory structure:
x-|
---|-GoDeep.class
---|-test-|
-----------|-MyJar.jar
-----------|
-----------|-myApp-|
----------------------|-Foo.jar
----------------------|-Foo.class
And given the contents of GoDeep.java and Foo.java:
3 public class GoDeep{
4 public static void main(
String[] args){
5 System.out.println(myApp.Foo.d);
6 }
7 }
3 package myApp;
4 public class Foo {public static int d=8;}
And MyJar.jar contains the following entry: myApp/Foo.class
If the current directory is x, which commands will successfully execute GoDeep.class and produce the output 8?
A.java GoDeep
B.java -classpath . GoDeep
C.java -classpath test/MyJar.jar GoDeep
D.java GoDeep -classpath test/MyJar.jar
E.java GoDeep -classpath test/Myjar.jar:.
F.java -classpath .:test/MyJar.jar GoDeep
G.java -classpath test/MyJar.jar:. GoDeep
The answer is F and G, cause the command line must find both GoDeep.class and Foo.class. So i guess the reason C is wrong is that it lacks "." and can't find the current directory.
Page 829,"Question 11":
Give the following directory structure:
test-|
------|-GetJar.jar
------|
------|-MyApp-|
-----------------|-Foo.java
And given the contents of GetJar.java and Foo.java:
3 public class GetJar{
4 public static void main(String[] args){
5 System.out.println(myApp.Foo.d);
6 }
7 }
3 package myApp;
4 public class Foo {public static int d=8;}
If the current directory is test, and myApp/Foo.class is placed in a JAR file called MyJar.jar located in test, which sets of command will compile GetJar.java and produce the output 8?
A.javac -classpath MyJar.jar GetJar.java
java GetJar
B.javac Myjar.jar GetJar.java
java GetJar
C.javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar
D.javac MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar
The answer is A. B and D are incorrect cause javac MyJar.jar GetJar.java is wrong syntax.C is wrong because the -classpath MyJar.jar in the java invocation does not include the test directory.
Here are my questions,
I.In question12 it says you need to use -classpath "." to find the class in the current directory and the class in the jar file while invoking the java command, but how come in question11 there's no "." in any of the -classpath command when you invoke the javac command?
II. In question11, the answer says in the java invocation C doesn't have the test directory, but look at B and D, none of the javac invocation in these two include the test directory, and why?
Thanks for the reply.