0

I am taking up SCJP 6 and came across a question which is as follows.

Given:
2. import rt.utils.Remote;
3. public class Controller{
4. public static void main(String[] args){
5. Remote remote = new Remote();
6. } }
And rt.utils.Remote class is properly bundled into a JAR file called rtutils.jar.
And given the following steps:
P. Place rtutils.jar in the $ROOT directory.
Q. Extract rtutils.jar and put rt directory with its subdirectories in the $ROOT directory.
R. Extract rtutils.jar and place Remote.class in the $ROOT directory.
S. Place rtutils.jar in the $JAVA_HOME/jre/lib/ext directory.
X. Compile using: javac -cp rtutils.jar Controller.java
Y. Compile using: javac Controller.java
Z. Compile using: javac -cp . Controller.java

If Controller.java resides in the $ROOT directory, which set(s) of steps will compile the
Controller class? (Choose all that apply.)
A. P -> X
B. Q -> Y
C. R -> Z
D. P -> Z
E. R -> Y
F. S -> X
G. S -> Z

As per the book the answer is A B F and G I am not getting a proper explanation which justifies those answers are right. It would be grateful if someone can explain. This is SE 6 Java.

user3201640
  • 571
  • 3
  • 10
  • 19

1 Answers1

0

Answer A: Step X adds rtutils.jar on the classpath and the Controller.java has all the requirements needed to compile.

Answer B: Since the classpath is not specified (step Y), the classpath consists of the class files in the current directory, which is the $ROOT directory. The extraction creates the package rt.utils and hence, the required Remote.class is also available on the classpath.

Answer C: When compiling Controller.java, the compiler looks for the rt/utils/Remote.class file. Since it has been moved to the $ROOT directory, the compilation will fail.

Answer D: Since -cp . has been specified in step Z, the classpath consists of the current directory, which is the $ROOT directory. However, this does not include any JAR files in the $ROOT directory. Each JAR file has to be specified, or * can be used to include the required JAR files.

Answer E: Same as answer C

Answer F: JAR files included in $JAVA_HOME/jre/lib/ext are called Installed Extensions and are available globally. However, they are not appropriate for use by a single, or small set of applications.

Answer G: Same as F

asohun
  • 331
  • 3
  • 7