(it implements a run() method). Essentially, this class replaces the main() routine. number of time steps the temperature distribution is output. calls are given in tempCalcRoutines.h and the source for these routines is given in tempCalcRoutines.cpp.
Campione, M. and Walrath, K., "The Java Tutorial: Object-Oriented Programming for the Internet", the "Hello World" example of [7]). in the files ColorContourPlot.java, ColorContourCanvas.java other languages. Additionally, by not embedding this code within a user interface, allocate and pass one-dimensional arrays of values. In order to create applications which have the form indicated in Figure 1, one needs to know how to write Java In this run() method, we have changed the output process to be one which displays identical to the Fortran program and does not use any of the object oriented features of C++ (i.e. interfaces and how to call routines written in C, C++ and Fortran from Java. One may notice that the C++ program is nearly Even though the temperature values are associated with a two-dimensional set of nodes covering the plate, we is displayed below, and the associated Java code is contained within TemperatureApp.java. Hopefully the interface construction tools will support Java 1.1 can create a two-dimensional array structure which access the data allocated as a one dimensional array. a variety of other tasks associated with creating "applications". is given a lower priority, so that on machines whose implementation of the Java virtual machine doesn't time-slice their incorporation in a visual programming system or a software infrastructure which supports distributed computing. abstract way, we discuss the process of writing interfaces for a specific example. Java interfaces and implementing native methods can be combined to create a Java/"other language" application. methods. The process of creating a Java interface to C, C++ and Fortran routines. The main driver routine is given below (as well This intermediate class serves to isolate user interface details is capable of writing a modest Java interface which accepts input and displays output to a user. it does not third and fourth sections we detail the construction of the Java classes which form the primary components of the This was done intentionally so that the code would serve as an example of codes which are likely Flanagan, D. "Java in a Nutshell", O'Reilly and Associates, 1996. to be used (and/or written) by the majority of those involved in scientific/technical computation. equation in a two dimensional rectangular region. core computational component is written in C, C++, or Fortran (see Figure 1). The program written in "another" language, The Java class that encapsulates the C, C++ or Fortran code components, Integrating The calculation component thread The third step in writing the interface is to write the Java class that implements the interface. a color contour plot of the data, rather than write the output to a file. Jackson, J. and McClellan, A., "Java by Example", SunSoft Press 1996. The Java class that encapsulates the C, C++ or Fortran We outline Specifically, within the code which gets executed when
is done as a separate thread [6]. application. In the second section we present the example which will form the basis of our discussion, and in the This was done because the standard method for exchanging data that this situation will change in the near future.
In the first part of the main routine, the problem and run parameters are set, memory is allocated and the temperature Lastly this routine also includes a main routine of it's own for testing purposes. the C, C++ or Fortran code components. These software components were developed in conjunction with the research supported by Air Force is evolved in time increments of size dt by calling the routine evolveTemperature() and at some predetermined is well described in a variety of books [1][2][3] [4] and we will assume that the reader
One may wonder about the In looking over the Java code, one should take note that the computationally intensive part of the application are evolving as well).
from the details of calling external routines. The command javah is applied to TempCalcJava.class. In this loop, the temperature of the plate procedure in it (e.g. this is a multi-step process: See "Native Method Implementation Process" for a diagram of these are given in tempCalcRoutines.f. On PC/Windows platforms the PATH variable must include of native methods is Java 1.1 based, after the initial construction, we compiled and worked with this code using this means creating a Java application that possesses program control buttons and fields for data input. It is in this class that the connection between the external routines and This means executing. describe, principally by means of an extended example, the process of creating a Java interface for a program written put up with all the warnings that are generated. This user interface was constructed using tools that generate Java 1.0.2. main() driver routine (the initializeTemperature and evolveTemperature routines). The example program is one that The process of writing a Java interface Addison-Wesley, 1996. In the Java 1.1 compilation step one must specify the flag "-deprication" and just execute "java TempCalcJava". The complete code is given contains the parameters as data members and also contains the methods (declared native) which are invoked by the task, then this allows the task to be executed without ``freezing'' the interface. Native Code and Java Programs. Thus, there is interest in creating with native methods, we assume that the reader has implemented a Java class that has at least one native method The task of calling one thread for the calculation component and one thread for the color contour plot. library that contains their implementations. A time stepping loop is then executed. The color contour plot that results from the execution of the program is given below. a procedure where one separates the construction of the interface from the external codes with the introduction line" version of the program by executing the main routine of the class i.e. A noticeable feature of the process is that we utilize three steps, rather than two. and ContourResolutionDialog.java. the Java 1.1 compiler. The second step in the process of creating an interface is to create a Java wrapper class that encapsulates as in the file tempCalc.cpp); the include file for the functions which the main routine codes components. Figure 1. In one aspect, this report is the presentation of an extended example demonstrating how this knowledge of writing Unfortunately, C, C++ and Fortran do not contain (as Java does) Our example concerns the creation of a Java interface for a program which solves the heat The routines create2dArrayStructure() among equal priority threads, the computationally intensive component will not cause the user interface to "freeze". are initialized, and then a time stepping loop is executed. variable must include the directory containing the native method implementation shared library. Lastly, and no less importantly, this class provides an encapsulation of the external routines which facilitates If one is running a computationally intensive the Run button is hit (the code fragment is given below) we create threads for the separate components of the application--- C++ example is very close to what might be composed in C). Oaks, S. and Wong, H., "Java Threads", O'Reilly and Associates, 1997. Cornell, G. and Horstmann, C., "Core Java", SunSoft Press, 1996. This class is also responsible for "loading" the external routines. In addition to providing samples of the mechanisms for data exchange, the example also reveals the choices we made we also allow the user interface to change independently (this is important because the Java user interface classes The purpose of this document is to While people are debating whether or not Java is good for computationally intensive tasks, the fact is that (and choices you will have to make) concerning the dividing line between the Java interface and routines written applications in which the user interface, or other "application packaging", is written in Java, but the routines into Java based systems for distributed computing and/or visual programming. As outlined in the discussions on implementing native methods [1][7], routines written in C, C++ and Fortran from Java comes under the heading of implementing and using "native"
calls. As the calculation proceeds data is output periodically. and destroy2dArrayStructure() in tempCalcRoutines.cpp demonstrate how one values does not preclude using a two-dimensional array structure to access the data. in C, C++ or Fortran. soon and these nuisances will disappear. need for the intermediate step; that of writing an intermediate class that ``wraps'' the C, C++ or Fortran code. Minimally components that one wishes to write interfaces for. In the first section we outline the process that we follow for creating applications of the type described by The Fortran version of this program is given in tempCalc.f and the supporting routines The requisite Java classes are contained It facilitated having the external code run as a separate thread. It also seems unlikely the directory containing the native method implementation dll. This intermediate class also facilitates the incorporation of external Originally we didn't have three steps, but adopted this practice for several reasons: The starting point for the process of writing a Java interface is to have a program or a selected set of code
in the inter-language procedures more easily. steps. At this point, if the native method implementation process is successful, one should be able to run a "command Abstract : The purpose of this report is to document some Examples in C++ and Fortran are given (as is readily seen the
The process that we use for creating Java interfaces consists of the three steps indicated in figure 2. computes the evolution of the temperature of a rectangular plate. Rather than discuss the process of writing interfaces in an C, C++ and Fortran are the primary languages for those who do scientific/technical computing. Daconta, C., "Java for C/C++ Programmers", Wiley Computer Publishing, 1996. While, for completeness, we will outline the steps required to create and implement Java classes This program is typical of many computationally intensive applications; data is allocated, parameters and values Here too, other documents [1][7] describe the process of interfacing Java to in TempCalcJava.java. However, since our implementation The interface Since this routine has native methods, one must create the dynamically linked library (DLL) or shared standardized and platform independent constructs for creating user interfaces, managing threads, networking, and Since the inter-language calling procedure for Java is evolving, this allows us to accommodate any changes the corresponding Java routines is made. By using this intermediate class we have isolated that component of the application which contains inter-language of the technical aspects of creating Java interfaces for codes written in languages other than Java. of an intermediate "wrapper" class. for the library containing the native method implementation. On UNIX machines running solaris the LD_LIBRARY_PATH To facilitate the execution of the program as a separate thread, this class implements the Runnable interface utilize classes). distribution is initialized. Using one-dimensional sets of data Problems which occur at this point are often caused by incorrect, or non-specification, of the path which is searched (In this case written to a file tempOut.dat). in C, C++ or Fortran. Office of Scientific Research Grant F49620-96-I-0327 and National Science Foundation/ARPA Grant NSF-DMS-961584. with other languages is through one-dimensional arrays; Java is no exception. In this regard the class allocates the required arrays,