GEOL 706
LAB 5 - Introduction to Java Applications

Get Ready for Java - A Simple Example - Get JRG - Complex Arithmetic

This lab need not be turned in and will not be graded. However, you should be familiar with this material by the middle of the term. Everyone in the class should have access to a Linux, Windows, or MacOS computer for the duration of the course. You will be modifying, compiling, and running short Java programs that implement the exercises found in the text. Any computer made after 1995 should be able to run the neccessary Java system software. Please see the instructor if you are having difficulty getting access to such a facility.

All of the programs mentioned below are available for download on the Internet in the archive file: Make a ``jrg'' folder on your desktop and put the jar file in there. Unzip this archive with the following commands entered in a Terminal window:

cd desktop/jrg
unzip jrg-src.jar

1. Get Ready for Java: Make sure you are familiar with the computer you will use for the lab exercises in this course. To make changes to the Java-language programs that implement the exercises, you will need a Java Development Kit (JDK) version 1.1.3 or later. The code here is compatible as well with version 1.2 of the JDK, called the Java 2 Platform.

2. A Simple Example: Examine the Java-language program ``''. The program would only be about ten lines long if it were not loaded with comments, meant to be a little tutorial in Java and object-oriented programming.

Copy to a folder on your hard disk, where you will work on the code for the course exercises. On a Sun (in a CommandTool) or on a Windows95 PC (in a DOS window), you could compile and execute the stand-alone application with:

% javac
% java loop
Some Windows98+ installations of the JDK require you to type:
% "c:\Program Files\JavaSoft\JDK\1.2\bin\javac"
% "c:\Program Files\JavaSoft\JDK\1.2\bin\java" loop
(On a Mac, drag the icon over the DropJavac icon, and then drag the loop.class icon over the JBindery icon.) Note that compilation produces two new binary object code files: loop.class and looplet.class, both defined in the file. loop.class is the stand-alone application. Experiment with leaving out lines of program code, one at a time, to see what error messages javac gives you. Why would loops in C usually start at zero? Change the program so it actually counts to 10. Change it so it counts only even numbers.

3. After a look at, you should see that it also compiles into an Applet as well as a stand-alone application. The Applet code is looplet.class. A web page has been created that will allow you to view the Applet. It is called looplet.html. Click on the link to view the page and run the Applet.

4. Get JRG: At this point you should obtain the two Java Archive (.jar) files below, which contain all the files ending in ``.java'' and ``.class'', respectively. If you obtain just your own copy of the ``.java'' source code files you can use the javac compiler in the JDK to create all the ``.class'' files. The jar application that comes with the JDK will extract individual files from the achives:

An appropriate extraction and installation command might be:
	jar xf jrg.jar

As an alternative, you can click on the FTP link to the Java code directory, and copy all the files there to your hard disk directory for the course. Make sure you use binary transfer mode for all files except the ones ending in ``.java'', the Java source code text files.

You may want as well the 4 Mb binary data file simult.ts file in the directory. You can then run the DixieSimultmod application (no compiling needed). You will need to have all the other .class files that form the course version of the JRG package in the same directory:

% java DixieSimultmod
Press the Animate button to see the wave propagation, or click reapeatedly on the slider control's advance arrows. The movie shows the propagation of an acoustic wave through a heterogeneous velocity model in cross section, synthesized by a finite-difference solution of the acoustic wave equation. When you are done with the demonstration, select Exit Java from the Viewmat File menu.
A similar demonstration is also available in various WWW formats; click here to try out your browser's capabilities. Warning: almost guaranteed to crash your browser.

5. Complex Arithmetic: Examine, compile, and run the application ``''. You're right, Java does not handle complex numbers as neatly as FORTRAN. Change the program to print the result of dividing z2 by z1.

Complex multiplication and division are taken care of by the ``mul(z1, z2)'' etc. methods defined in the complextest class. Define a method (say, ``add(z1, z2)'') to add two complex numbers. Change the program to print z1+z2 as well. The JRG package has a class Complex with all these methods, that we will use frequently, but you can just use what is in to polish up your memory of complex arithmetic.

6. List your directory and, if you like, browse through the Java programs set up for you. These are converted out of Claerbout's book, and will be used in later labs. The ``.java'' files beginning with small letters are the ones used in the class exercises; the ones starting with capitals are part of the JRG package that supports the exercises. The Web location for RG system documentation is ``''; the JRG package is under constant development.

Get Ready for Java - A Simple Example - Get JRG - Complex Arithmetic