Instructions for editing, compiling and running Java Programs on Windows 9x/Me/NT4/2000 Machines: [Note: If you use any flavor of Unix or Linux, then you probably will want to use the Approach 3, from the command line. In this case, procedures are very similar to what are given here, but some details will vary. If you want to program on a Mac, you probably will need to consider using CodeWarrior for C/C++/Java - I don't know any reasonable alternatives.] Approach 1: Use the BlueJ IDE. See the extensive notes in the BlueJ directory. BlueJ is a free, simple-to-use graphical interactive development environment. We keep a copy of this IDE on the course website, in the BlueJ directory. Just follow the instructions to set it up on your computer. Approach 2: Use a different graphical IDE such as JPad or Borland J-Builder. Note the following: - There is a freeware Java IDE named "Bluette" which works acceptably, but requires more manual setup and is not as 'bulletproof' as JPad, in my experience. If you want to use a freeware IDE, I suggest BlueJ. - You may also use Microsoft Visual J++, but you must - Set up a full Visual Studio 'Project', which is somewhat more complex than we need. - Use Microsoft's Java compiler instead of Sun's Java Development Kit (JDK) - This is not a real problem for what we're doing here, and the MS compiler is actually quite fast.) So, we'll just consider JPad (or JPad Pro) from www.modelworks.com - the others are generally similar but more complex or difficult to use (in my opinion.) Note that you can download an evaluation copy of JPad or JPad Pro from www.modelworks.com. It's good for roughly 15 days, at which point you need to register it to continue using it. But you should be able to figure out whether you like it or not in that time, and it is not expensive. Note also that Boucke 111 has a JPad license for a small number of seats - you can certainly use it effectively when a Java lab is not going on there. The first step is to write or otherwise obtain the .java and .html files that plan to use. In Lab 4, these files were in the web directories http://www.cse.psu.edu/~mudgett/ist230/labs/lab4/GCD_Simple or http://ritter.ist.psu.edu/ist230/labs/lab4/GCD_Simple Simply download these. [Note: On your personal machine, your security settings should permit you to be able to just right click the file name and use 'Save As' from the context menu to save these files anywhere you please. However, from university machines such as the Boucke 111 laptops, security settings frequently do not permit right clicks on web links, and certainly do not generally permit saving files to any directory except A:\ (floppy drive), C:\Temp, or your Desktop or your U-Drive. The Boucke 111 machines, by default, save these files to C:\Temp\Temporary Internet Files.] Once downloaded, you should place these in a convenient directory that is easy for you to access - label it in such a way that you can easily tell what it is. This is known as your 'working directory'. [Note: If your are, for example, in Boucke 111, you cannot write anywhere that you want. In this case, create a new subdirectory of your Desktop, C:\Temp, or your U-Drive, again clearly labelling] Now open Jpad. Go to the File menu, click Open, and navigate to the .java file which you want to edit or compile, which is in your working directory. Make your changes, click Save (or use Save As if you want to change the name - the name 'javafilename' in 'javafilename.java' should correspond to the name of the class within. For example, the class name of the Lab 4 program is GCD, so the .java file must be named GCD.java - you really must name them this way.) You are now ready to compile your edited .java file. If you're in Boucke 111, the laptop already has the Java Development Kit (JDK) installed. If you're using a different machine, such as your own personal machine, you may not. In this case, you need to download and install the latest JDK (which is currently JDK.1.3.1_01) from http://java.sun.com/j2se/1.3/download-windows.html This is a free download, but may take a little while if you're connected via analog modem (e.g., 56K or 33.6K) - it's about 35 MB. When you've downloaded this, just double click the executable (.exe) file, and it should begin to install. Just follow the directions. I recommend that you install it right off the C:\ drive - just use the default - the installation directory should be something like C:\JDK1.3.1 If you accept the default, then JPad should have no trouble finding it. Now you are ready to begin compilation. Go to the JDK menu, and click Compile javafilename.java (in this case GCD.java). If it is the first time you have run JPad, it will ask you if you want to run the JDK setup script now. Click yes - JPad will now find the directory that holds your JDK, and also saves that location so that it can find it in the future. Otherwise, it will simply try to compile the .java file using the java compiler, javac. If you get actual errors, then you have a syntax error, and will need to re-edit and re-compile it. If you get a "deprecated" warning, then you need not worry - this merely means that your program used an 'older' style Java method which will (someday) no longer be supported, but is currently. In fact, GCD.java uses a deprecated method, but it is fine. Assuming that you could get your program to compile without actual errors, then javac writes a .class file to the same directory that your .java file is in, with the same surname (e.g., in this case, GCD.class.) Now, if you have more than one .java file, compile each of these in turn. I assume that you already have an .html file written which will call this Java applet (in this course, I will write these for you.) To test your applet, simply go to the JDK menu again, and click Test Applet. You will get a dialog screen - simply navigate to your working directory, and select the .html file (not the .java or .class file - this is an applet, which requires a browser or the java 'appletviewer' to run.) Now click OK, and your applet should begin to run. Approach 3: Use the command line tools. Please first familiarize yourself with Approach 1, using an IDE. We will not actually use an IDE here, but some of the steps will be the same. For Unix/Linux, the steps are fundamentally the same as for the Wintel platform, but certain procedures will be different, such as setting the path for the JDK command line tools. [Note: I will be giving instructions geared more to Windows NT4/2000. The procedure for Win9x/WinMe are very similar - there may be slight differences in setting your path, and remember that in an MSDos box, you cannot get more than 8.3 file names (8 letter surname with 3 letter extension - with Win9x/Me, it really pays to keep your directory/file names SHORT!)] To begin, either locate the JDK subdirectory or download/install the JDK as described in Approach 1. It is recommended to use the default directory directly off the root directory (e.g., for this example would be something like C:\JDK1.3.1). Now, you should set the path for the JDK. In Win NT4/2000, right click My Computer to give you the System Properties dialog (there are other ways to get here also), and then click the Environment tab. You need to edit the 'Path' variable. To do this, highlight the 'Path' line in User Variables - go down to the text box and append C:\JDK1.3.1\bin to whatever directory is already there. For example, in mine, I have C:\win32app\salford already there. So, the new path should read C:\win32app\salford;C:\JDK1.3.1\bin Note the semicolon separating these two entries. That's it. Now you should be able to access all the command line tools from any directory, including your working directory (as in Approach 1, you should create a working directory and place your .java and .html files in it.) Now, run the 'Command Prompt' (in Win9x it's called MSDos Prompt.) Change directories to your working directory (this is why I suggest keeping the working directory close to the root C:\) Type the command dir, which should display all your .java and .html files. You now need to edit them. You can use any text editor, either by typing in the executable name from the command line or by starting in the Windows GUI. For example, from the command line you could type notepad GCD.java to edit GCD.java using the notepad text editor. There are many other editors available, but you should use a strictly plain text editor - avoid word processors like MS Word, Lotus WordPro and Corel WordPerfect, which place additional markups in the file. These will cause you serious problems. Reasonable choices are emacs (there is a reasonable version which works OK on Win NT4/2000, but not so well on Win9x/Me), Vi for Windows (the famous Unix editor) and one called Synedit (these are all freeware) - there are many others also. Now, make any needed corrections to your .java file(s), as in Approach 1. The only difference is that we will compile and run these programs directly from the command prompt. Once all .java files have been edited, you can compile them via the following command (assuming you are in your working directory.) javac javafilename.java (in this case, javac GCD.java) As in Approach 1, you should check for actual compile errors, again ignoring 'deprecated method' errors. Now, you can test the applet by typing the command appletviewer javafilename.html (in this case, appletviewer GCD.html) This will (hopefully) display your applet, which you can now test for proper operation. Final Notes: It takes a lot more time to actually write these instructions down than it does to actually execute them! This is not a difficult procedure. - Just pay attention to details. If you don't have a reasonable knowledge of command line details, such as changing directories, creating and removing directories and files, and executing programs by typing in the executable name, then it may make sense to use an IDE like JPad. - However, in the long run, a working knowledge of the command line is important if you plan to be more than a 'user' of the computer. - Computer professionals are expected to be able to work at the command line. - If you understand the rudiments of the command line, then it's actually no more difficult to use javac and appletviewer (and in many ways, it's easier.) A few useful command-prompt commands: cd (change directory) examples: cd (changes to your home directory) cd gcd (changes to the subdirectory gcd of your current directory) cd C:\Temp\gcd (spells out the entire directory path of the directory you want to change to) cd .. (changes to the directory above your current directory) mkdir (make a new directory) examples: mkdir gcd (makes a new subdirectory, gcd, of your current directory) mkdir C:\Temp\gcd (spells out the entire path of the new directory) rmdir (removes a directory - be careful - you can mess things up with this) example: rmdir gcd (removes the gcd subdirectory from your current directory - generally requires that you've already removed any files from it - see below) del (deletes a file - note for Unix, use rm instead of del) examples: del GCD.class (removes the file GCD.class from your current directory) del C:\Temp\gcd\gcd.class (spells out the entire path of the file you are deleting.) del *.class (Removes every file of the form xxx.class in your current directory - use it carefully.) del * (Be very, very careful with this - it wipes out EVERY file in your current directory - never use it unless you are sure which directory you're in and know you want to clear it out completely. Usually used when you want to completely remove a directory.) You can, of course, do many of these operations (e.g., creating and removing files and directories) from the Windows GUI, and you may prefer to do so. However, it is often faster not to constantly be switching back and forth from command line to GUI. DRM 09/23/01