CS151 Object Oriented Programming
Homework 4
Cool JNI Exercise
This exercise is going to give students exposure to Java Native
Interface (JNI) concept. You are required to write two programs.
C++ Program
Write a C++ program named dosCommand.cpp using MSVC++ that does the
following:
- This C++ program is going to be called from the Java Program
- The program is going to take "one" real parameter. The parameter
is the command to be executed in MS-DOS. (For example, dir, help, ver)
- The program is going to execute the inputted command.
- Output of the command is going to be captured within the C++ program in an
array of characters (1D array or 2D array, any data structure, your choice)
- A method from the Java program will be called to pass the output back to
the Java program.
Java Program
Write a Java program named j2dosDriver.java using JDK 1.3 that does the
following:
- The program is going to take one parameter (the MS-DOS command to be
executed)
- This Java program is going to call a native C++ program (docCommand.cpp)
- It is going to pass the inputted MS-DOS command String to the C++
program
- It expects a data structure with the command output will be passed back
from the C++ program
- In the Java program, it is going to print out the output passed back from
the C++ program
Extra Credit
Extra credit is built in in the program. In order to do this homework, you
have to research how JNI program is built, how to use javah, how to build DLL in
Windows, how to map Java types. to C++ types. While most of the concepts will be
covered later in the class, it is essential you do your research as needed. (If
you wait for the lectures, it is going to be too late.) Good Luck :)
NOTE: What to handin:
- Use a good word processor to writeup all the written assignments. Print
them out and handin in class.
- Handin DETAIL running instructions and the actual program (source + class
files + html file, etc). Print instruction and program listing out, and hand
them in with the computer diskette.
- No late assignment will be accepted
- DO NOT EMAIL ANY assignment to me. Handin in class
- Points will be taken off if you violate any of the above.