|Implementing Native Methods|
The example highlighted in this lesson implements a simple "character-replace" program called
Replace. You invoke the program with four command line arguments:
Replaceprogram reads from inputfile, replaces all occurrences of char1 with char2, and writes the results to outputfile.
Replaceprogram was originally written by Eugene Kuerner for the alpha version of Java. It's been updated to run with the latest Java release.
The Source Files
- Contains the main program.
- Defines a class named File. This class provides basic file and path manipulation with the expectation that subclasses will provide the actual file management code depending on the file semantics they want to present. InputFile and OutputFile both derive from File.
- Contains the InputFile class (a subclass of File), which implements a read-only input file. This class declares three native methods whose implementations are written in the C programming language and provided in
- Contains the OutputFile class (a subclass of File) that implements a write-only output file. This class declares three native methods whose implementations are written in the C programming language and provided in
Files Generated by
- C header files generated by
- C stub files generated by
- Compile the
.classfiles using the Java compiler.
- Compile all of the C code into a dynamically loadable library named "file". If you don't know how to do this, look at the instructions in Step 6: Create a Dynamically Loadable Libraryin the Step By Step lesson.
- Run the program using the Java interpreter.
|Table of Contents|