在 Java 中编译时如何包含现有代码/类文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6723865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:01:33  来源:igfitidea点击:

How to include existing code/class file when compiling in Java

javaclasscompiler-construction

提问by Jinal Kothari

I am a complete newbie with Java. I use notepad++ to write Java code, and then compile and execute using command line on the Windows Platform

我是 Java 的完全新手。我使用notepad++编写Java代码,然后在Windows平台上使用命令行编译执行

How do I reuse existing code or a class file? For instance, I have written a class in file A.java(with the corresponding compiled class file available) and wish to use that class in B.java. Do I need to specify it in the B.javafile (sort of lie c/c++) or using compiler options. What compiler options?

如何重用现有代码或类文件?例如,我在文件A.java 中编写了一个类(具有相应的编译类文件可用),并希望在B.java 中使用该类。我是否需要在B.java文件中指定它(有点像 c/c++)或使用编译器选项。什么编译器选项?

采纳答案by Srikanth Venkatesh

You can use import the A.java class in B.java like this

您可以像这样在 B.java 中使用 import A.java 类

import A.java;

By doing like this A class will be available in B class.

通过这样做,A 类将在 B 类中可用。

Java Packages Tutorial

Java 包教程

回答by Mat

You're looking for the importstatement, and the Using Package Memberstutorial.

您正在查找import语句和使用包成员教程。

回答by Mob

Use can import classes and packages.

使用可以导入类和包。

    import java.io.*; //packages
    import codes.dir.jar; //classes in your packages

I'd advise you to use an IDE for coding java, it would make you debug faster. I recommend Netbeans or Eclipse || http://www.netbeans.org/or http://www.eclipse.org/

我建议你使用 IDE 来编码 java,它会让你调试得更快。我推荐 Netbeans 或 Eclipse || http://www.netbeans.org/http://www.eclipse.org/