[英]How to include existing code/class file when compiling in Java
I am a complete newbie with Java.我是 Java 的新手。 I use notepad++ to write Java code, and then compile and execute using command line on the Windows Platform我使用notepad++编写Java代码,然后在Windows平台上使用命令行编译执行
How do I reuse existing code or a class file?如何重用现有代码或 class 文件? 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 . 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.java file (sort of lie c/c++) or using compiler options.我是否需要在B.java文件(有点谎言 c/c++)或使用编译器选项中指定它。 What compiler options?什么编译器选项?
You're looking for the import
statement, and the Using Package Members tutorial.您正在寻找import
语句和使用 Package 成员教程。
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.我建议您使用 IDE 编码 java,它会让您调试更快。 I recommend Netbeans or Eclipse ||我推荐 Netbeans 或 Eclipse || http://www.netbeans.org/ or http://www.eclipse.org/ http://www.netbeans.org/或http://www.eclipse.org/
You can use import the A.java class in B.java like this您可以像这样在 B.java 中使用导入 A.java class
import A.java;
By doing like this A class will be available in B class.通过这样做,A class 将在 B class 中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.