使用“:”来表示。和“。”在带有类路径声明的 java 调用中

发布于 2024-08-14 07:29:11 字数 667 浏览 1 评论 0原文

这是一道 SCJP 模拟考试题。

假设我有以下两个文件:

package pkg;

public class Kit {
    public String glueIt (String a, String b) {return a+b;}
}

import pkg.*;

class UseKit {
    public static void main(String[]args) {
        String s = new Kit().glueIt(args[1],args[2]);
        System.out.println(s);
    }
}

以及以下目录结构:

test
   |--UseKit.class
   |
   com
     |--KitJar.jar

当前目录是 test 并且文件 pkg/Kit.class 位于 KitJar.jar< /code>

根据答案,产生输出 bc 的 java 调用是

java -classpath com/KitJar.jar:. UseKit a b c 

请解释运算符“:”和“.”的使用。

This is a scjp mock exam question.

Suppose I have the following two files:

package pkg;

public class Kit {
    public String glueIt (String a, String b) {return a+b;}
}

import pkg.*;

class UseKit {
    public static void main(String[]args) {
        String s = new Kit().glueIt(args[1],args[2]);
        System.out.println(s);
    }
}

And the following directory structure:

test
   |--UseKit.class
   |
   com
     |--KitJar.jar

The current directory is test and the file pkg/Kit.class is in KitJar.jar

According to the answer, the java invocation that produces the output b c is

java -classpath com/KitJar.jar:. UseKit a b c 

Please explain the use of the operators ":" and "."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光无声 2024-08-21 07:29:11

: 是 Java 类路径中条目的分隔符。 . 表示“当前目录”。因此,类路径 com/KitJar.jar:. 意味着在两个位置查找 Java 类文件:com/KitJar.jar 和当前目录。

: is the separator for entries in a Java classpath. . means "current directory". So the classpath com/KitJar.jar:. means to look for Java class files in two locations: com/KitJar.jar and the current directory.

陌路终见情 2024-08-21 07:29:11

接受的答案是正确的,但它可能提到类路径分隔符实际上是依赖于平台的,正如评论中指出的那样。

有关详细信息,包括类路径通配符的说明以及如何清理 CLASSPATH 环境变量的详细说明,请参阅 设置类路径 技术说明(和/或 设置 *nix 版本的类路径)。

The accepted answer is correct but it could have mentioned that the classpath separator is actually platform dependent as pointed out in comments.

For more information, including an explanation of class path wildcards, and a detailed description on how to clean up the CLASSPATH environment variable, see the Setting the Class Path technical note (and/or Setting the Class Path for the *nix version).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文