Appendix C

Java Quick Reference and Installing Software

C.1 JAVA ELEMENTS

Compilation and Interpretation of Application

image

image

image

image

image

C.2 TRANSFERRING FILES FROM THE CD

The Maple and Java worksheets and programs given on the CD do not need any special installation. You just need to pick a directory/folder on your computer where you want them stored, and copy the appropriate folder from the disk into that directory. Of course you will need to insert the CD into the CD drive, and open that drive to see the contents of the CD. (On Windows computers you get to that drive by clicking on the My Computer icon.)

C.3 USING OUR MAPLE WORKSHEETS

You open one of our Maple worksheets by starting Maple on your computer and then opening the worksheet from within Maple. Of course you must have Maple installed on your computer for this to work, and that is done with the installer that comes on the Maple CD.

We have written the Maple worksheets with Maple Versions 6–9.5. We have not tried to specialize the worksheets to just the latest version, so most every command should work with any recent version of Maple. You may get a complaint from Maple when you first load the worksheet that it was created with a more recent version (that the Maple people would not mind you running out and purchasing), but that should cause no problems. You may find that the response shown in the text does not quite match that given by your version of Maple. In any case, learning how to cope with ever-advancing software and hardware is part of the learning experience we wish to present.

C.4 USING OUR JAVA PROGRAMS

The Java programs on the CD are almost all source (.java) files and therefore need to be compiled before they will execute. There are a number of ways in which you may work with and execute our Java programs. The least painful is probably to use a complete programming workbench like Code Warrior or the Forte Suite. With these you need only punch some buttons to compile, debug, and execute programs. We view these programming environments as powerful tools that will increase the productivity of professional programmers. However, we believe that the more basic approach is preferable for the purpose of this introductory book.

The basic approach to Java programming that we prefer is to use an editor to modify the Java source file, save the file, and then execute the resulting class file from the prompt (command line) of a shell. In this way the beginning programmer learns that there are just two basic types of files to deal with, and that they are universal for all operating systems. In contrast, the programming environments often produce an assortment of files containing formatting and other such information, with the user not sure just what is truly needed to write and run a program.

On Windows computers you may use a text editor such as Notepad to modify Java source file. You should not, in contrast, use a word processor such as MS Word, since it formats text by inserting control characters that are invisible to you but stop the Java compiler from getting its job done. We prefer using the WinEdt [WinEdt] editor on Windows, which also provides immediate access to a shell in the same directory as the source (it is also excellent for image).

On Unix systems we recommend the free gnu emacs (especially xemacs) editor [Gnu]. It is powerful and permits compilation and execution from within the editor. It is excellent too with image. In addition, the jEdit Java editor is an excellent and free Java editor that is written in Java. Thus, it runs identically on all operating systems and provides some very useful color coding of codes.

Once you have your .java file open in an editor, you need a shell or command line from which to issue the javac and java commands. On Unix this is easy if you first change to the appropriate directory and open your editor from there. It is equally easy on Windows computers if you open a shell from your editor. However, if you use the Start > Run > Open > Command route, then you will have to navigate the Window’s file directory structure with the dir and cd commands.

C.5 INSTALLING PTPLOT (OR OTHER) PACKAGES

The first step in setting up PtPlot is to download its latest version and then uncompress it.1 The plotting package we call PtPlot is part of a larger Java project called Ptolemy [PtPlot], all free for downloading.

After you have properly unzipped or untarred the PtPlot package, a directory such as PtPlot5.2 should be created. The number 5.2 here is the version number of the PtPlot package that we are now using; there may be a newer version when you do your download. For our examples, we have renamed the directory in whi PtPlot resides as simply PtPlot, with no version number attached. On Unix, we assume that your PtPlot directory is ˆ/java packages/PtPlot, where the ˆ indicates your home directory. On Windows, we assume that your PtPlot directory is . Advanced users may prefer to keep the version number C:PtPlot 2 in the directory name, or use a different organizational system. However, if this is the first time that you have installed a Java package, we recommend that you use the same directory names as we have.

Now that we have placed the PtPlot package in its own directory, we need to tell Java where to find it. As a matter of convention, the Java compiler javac and interpreter java assume that the value of a variable named CLASSPATH contains the information on where packages such as PtPlot are stored. This type of variable that controls the environment in whi programs run is called an environment variable. On account of the programs in the packages having already been compiled into class files, the variable that directs Java to the classes is called the 1“1 CLASSPATH. To get PtPlot to work under Java you need to modify the CLASSPATH variable to include the location where PtPlot is stored:

Windows 95: Open the autoexec.bat file (usually C:autoexec.bat) in a text editor such as Notepad. At the end of the file, add the line

image

Save the autoexec.bat file and restart your computer.

Windows 98/ME: Click Start and then Run under that. Key in the command name msconfig, and press Enter. The System Configuration Utility should appear. Select the tab named Autoexec.bat and look for a line that says SET CLASSPATH. If you cannot find that line, click, and enter. If the New SET CLASSPATH = C:PtPlot SET CLASSPATH line already exists, select it, choose Edit, add a semicolon ; to the end of the line, and then add after the semicolon. The semicolon is C:PtPlot a separator that tells Java that it should look in more than one location for class files. Make sure that the checkbox by the CLASSPATH line is checked, and click OK. Answer Ye s when Windows asks you whether you want to restart the computer.

Windows NT/2000/XP Open the Control Panel (Start, Settings, Control Panel in NT/2000, or Start, Control Panel in XP). Open the System icon (you may need to switch to the Classic View in Windows XP). Under the System Properties window, se lect the Advanced tab, and choose Environment Variables. Two lists should be shown. One contains environment variables just for you, and one contains environment variables for all users on the system. In your personal environment variable list, look for CLASSPATH. If you cannot find the CLASSPATH variable, click New, enter for the variable name, and for the value. If the CLASSPATH C:PtPlot CLASSPATH variable already exists, select it, choose Edit, add a semicolon; to the end of the current value, and then add after the semicolon. The semicolon is a C:PtPlot separator that tells Java that it should look in more than one location for class files. Click OK until you get back to the Control Panel, and then restart your machine.

Solaris: We assume that you do not have system authority for your computer, and so will install PtPlot in your home directory. We suggest that you make a subdirectory called java packages in your home directory and install PtPlot there:

image

If the ˜ is used to represent your home directory, this assumes that you will be installing the PtPlot package in ˜/java packages/PtPlot/

Your CLASSPATH variable that needs updating is contained in the initiation (init) file .cshrc in your home directory. Because this file name begins with a. it is usually hidden from view. Beware; it is easy to mess up your .cshrc file and end up in a quagmire in whi you cannot enter commands. For this reason we suggest that you first create a backup copy of your .cshrc file, in case anything goes wrong:

image

Next, open the .cshrc file in a text editor. Because this file may contain some very long lines that must be kept intact, if your text editor has an “automatic word wrap” feature, make sure it is turned off. Next look for a line that starts with setenv CLASSPATH. If you cannot find that line, add setenv CLASSPATH ˜/java packages/PtPlot on its own line at the end of your .cshrc file. If the setenv CLASSPATH line already exists, add a colon: to the end of the existing line, and then add ˜/java packages/PtPlot after the colon. The colon is a separator that tells Java that it should look in more than one location for class files. Save your .cshrc file, then close and reopen all shells that you have open (or log off and then back on).

Once you have the CLASSPATH variable set, you should make sure that it is working. To check, go to a command prompt in a shell and enter

image

The complete value for the CLASSPATH variable should be printed to the screen, for example:

image

If your changes do not take, carefully follow the directions again, then ask for help.

At this point, you are ready to try out PtPlot. Get the file EasyPtPlot.java containing a sample plot program from the disk or the Web and enter

image

If the PtPlot package was installed correctly, you should get a nice graph on your screen. If this does not work, ask for help.

C.6 INSTALLING JAVA DEVELOPER’S KIT

Sun Microsystem’s Java Web site [SunJ] contains the latest, and free, version of JDK, the Java Developer’s Kit (presently j2sdk1.4.1). Though most operating systems have all that is needed to run Java programs, you need the developer’s kit to compile Java programs from a source file. The actual JDK tools occupy about 7 MB, with its (optional) documentation occupying more than ten times this space (the documentation is in HTML). This means that you may want only the tools if space is an issue.

On Windows computers, JDK is usually placed in , while on C:jdk1.2in Unix it is in /usr/local/jdk1.2. Once installed, you need to update the PATH and the CLASSPATH environment variables so that the shell knows where to find the Java compiler and classes you make. This is essentially the same procedure we used to include the PtPlot classes in the CLASSPATH. Under Windows you need to go to the System control panel and then select the Environment tab. You then need to add (or whatever file JDK was installed into) to the ;C:jdk1.2in PATH variable. Likewise, the CLASSPATH need to be added, for example,

image

Finally, you need to reboot for the changes to take effect.

1  If you have never done this before, you may want to do it with a friend who has. In Windows, you use WinZip [WinZip] to unzip files. In Unix, you try double-clicking on an icon of the file, or decompress it from within a shell with gunzip and tar -xvf.

2  If you use the Windows automatic installer, you should install to C:PtPlot, rather than C:ptolemyPtPlot5.2, if you want to follow our examples verbatim.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.117.233