A basic question: I'm using the command line to compile and run my java code (javac and java commands respectively). Our professor provided us with a .class file we can use in our future projects. The class filename is U.class, and our professor told us which methods are in included in this class so we can invoke them in our own code. My question is, how can I tell Java I want to use this .class file in my code and how would I type it in the command line so to compile this (using javac)? The following is how my source code looks like so far:
import U; // This line marks an error.
public class DemoU
{
public static void main(String[] args)
{
U u = new U();
String[] myJavaFiles = u.system("dir");
u.displayArray(myJavaFiles);
}
}
I've placed both files, DemoU.java and U.class, in the same folder, and I try to compile everything using javac DemoU.java.
.to your classpath.import, you don't need it as both classes in the same folder.classfile. Then just put that JAR in your classpath when you are building/executing. Done!. Simply providing a class file can be tricky, coz you don't even know which package that class is supposed to be! You need to put it in a correct directory structure if it is not in default package.