How to include existing code/class file when compiling in Java
I am a complete newbie with Java. I u开发者_StackOverflowse notepad++ to write Java code, and then compile and execute using command line on the Windows Platform
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.java file (sort of lie c/c++) or using compiler options. What compiler options?
You're looking for the import
statement, and the Using Package Members tutorial.
You can use import the A.java class in B.java like this
import A.java;
By doing like this A class will be available in B class.
Java Packages Tutorial
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/
精彩评论