I have homework that asks me to use a .class file for my project, but I don't know how to use those files in a .java file. This is the project structure
agentes.class
datos_confidenciales.class
II_Parcial_2007_1.doc
Main.java
numeros.class
I mean, I got to make a class called Main
that implements the numeros interface
, the numeros interface is in numeros.class
file
I've googled but no results.
CodePudding user response:
The .class files simply need to be on the classpath when you compile. How exactly you configure that depends on how you compile (on the commandline or in an IDE; in what IDE).
Here is the documentation for the classpath. Here is a related question for setting the classpath.
The class path is the path that the Java runtime environment searches for classes and other resource files. The class search path (more commonly known by the shorter name, "class path") can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
CodePudding user response:
One option is to decompile the class-file, which will get you a java-file of the interface that was compiled.
If you don't want to use a decompiler, write a small application that will reflect the numeros
class and prints out all methods and their parameter-types and return-types, so you can implement it.
Of course you could always use an IDE, with the class-file in module-path, your IDE will assist you to implement the interface.