简体   繁体   English

SCJP 6问题:类路径和当前目录

[英]SCJP 6 issue : classpath and current directory

I am taking up SCJP 6 and came across a question which is as follows. 我正在处理SCJP 6,遇到了一个如下问题。

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 ABF and GI am not getting a proper explanation which justifies those answers are right. 根据这本书,答案是ABF,而GI没有得到适当的解释来证明这些答案是正确的。 It would be grateful if someone can explain. 如果有人可以解释,将不胜感激。 This is SE 6 Java. 这是SE 6 Java。

Answer A: Step X adds rtutils.jar on the classpath and the Controller.java has all the requirements needed to compile. 答案A:步骤X在类路径上添加rtutils.jar,而Controller.java具有编译所需的所有要求。

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. 答案B:由于未指定类路径(步骤Y),因此类路径由当前目录(即$ ROOT目录)中的类文件组成。 The extraction creates the package rt.utils and hence, the required Remote.class is also available on the classpath. 解压缩将创建包rt.utils,因此,所需的Remote.class也可在类路径上使用。

Answer C: When compiling Controller.java, the compiler looks for the rt/utils/Remote.class file. 答案C:编译Controller.java时,编译器将查找rt / utils / Remote.class文件。 Since it has been moved to the $ROOT directory, the compilation will fail. 由于已将其移至$ ROOT目录,因此编译将失败。

Answer D: Since -cp . 答案D:从-cp开始。 has been specified in step Z, the classpath consists of the current directory, which is the $ROOT directory. 在步骤Z中已指定,类路径包含当前目录,即$ ROOT目录。 However, this does not include any JAR files in the $ROOT directory. 但是,这在$ ROOT目录中不包括任何JAR文件。 Each JAR file has to be specified, or * can be used to include the required JAR files. 必须指定每个JAR文件,或者*可用于包括所需的JAR文件。

Answer E: Same as answer C 答案E:与答案C相同

Answer F: JAR files included in $JAVA_HOME/jre/lib/ext are called Installed Extensions and are available globally. 答案F:$ JAVA_HOME / jre / lib / ext中包含的JAR文件称为“已安装扩展”,并且在全球范围内可用。 However, they are not appropriate for use by a single, or small set of applications. 但是,它们不适用于单个或少量应用程序。

Answer G: Same as F 答案G:与F相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM