Hi,
I have a confusion regarding one of the statements written in K.Sierra's book:
For any given class the
java virtual machine will need to find exactly the same supporting classes tat the javac compiler needed to find at compilation time.
Then there is a question in the Exercise as below:
Question
====================================================
Given the following directory structure:
test\GetJar.java
test\myApp\Foo.java
Below are the contents of two java files:
public class GetJar {
public static void main(
String[] args) {
System.out.println(myApp.Foo.d);
}
}
=================================================================
package myApp;
public class Foo {
public static int d=8;
}
If the current directory is
test ,which set(s) of commands will succesfully compile the two .java files and produce the output 8? (Choose all that apply.)
I am providing the correct answer as per the book:
[Correct Answer]
javac myApp/Foo.java
//put into test a jar file
[/Correct Answer]
11. Given the following directory structure:
test-|
|- GetJar.java
|
|- 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 set(s) of commands will compile GetJar.java and produce the output 8?
(Choose all that apply.)
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
11. Given the following directory structure:
test-|
|- GetJar.java
|
|- 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 set(s) of commands will compile GetJar.java and produce the output 8?
(Choose all that apply.)
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
Please let me know how is A correct.
As per the book's statement both javac and java tatements for Getjar should include the option -classpath statements.
Regards,
Chandan