繁体   English   中英

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

[英]SCJP 6 issue : classpath and current directory

我正在处理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

根据这本书,答案是ABF,而GI没有得到适当的解释来证明这些答案是正确的。 如果有人可以解释,将不胜感激。 这是SE 6 Java。

答案A:步骤X在类路径上添加rtutils.jar,而Controller.java具有编译所需的所有要求。

答案B:由于未指定类路径(步骤Y),因此类路径由当前目录(即$ ROOT目录)中的类文件组成。 解压缩将创建包rt.utils,因此,所需的Remote.class也可在类路径上使用。

答案C:编译Controller.java时,编译器将查找rt / utils / Remote.class文件。 由于已将其移至$ ROOT目录,因此编译将失败。

答案D:从-cp开始。 在步骤Z中已指定,类路径包含当前目录,即$ ROOT目录。 但是,这在$ ROOT目录中不包括任何JAR文件。 必须指定每个JAR文件,或者*可用于包括所需的JAR文件。

答案E:与答案C相同

答案F:$ JAVA_HOME / jre / lib / ext中包含的JAR文件称为“已安装扩展”,并且在全球范围内可用。 但是,它们不适用于单个或少量应用程序。

答案G:与F相同

暂无
暂无

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

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