CS 367: Introduction to Data Structures

Spring 1998

Assignment 1: Java in the Unix Environment

Due: Tuesday, January 27


The purpose of this assignment is to help you get familiar with the UNIX environment and to learn how to compile and run Java applications and applets. You should use your course accounts on the instructional Unix workstations for the assignment. Check the home page for CS 367-5 for information about Unix Orientation Sessions and about activating your account. You should activate your account and create a directory for this assignment. (mkdir assign1 will create a directory called assign1, and cd assign1 will put you in this directory.)

  1. A simple Java program was handed out in class on Tuesday, 1/20. It's the "Hello World" program that you may have seen sometime in the past. In any case, it's simple enough that you should be able to figure out what it does even if you haven't seen it before. You should create a file called HelloWorld.java that contains exactly that code. You can use emacs or vi to create the file.

    After creating the file, you should compile the code by typing:

    javac HelloWorld.java

    If all goes well, this will produce a file called HelloWorld.class. To run the program, type:

    java HelloWorld

    To create a file called helloworld.out that contains the output of the program, type java HelloWorld > helloworld.out. Turn in the helloworld.out file using the Assingment Handin instructions on the 367-5 assignment web page.

  2. Click to see a simple Java applet. It has a similar function to the "HelloWorld" application, but it's designed to run in the context of a web page. For now, don't worry about how it works. Create a file called HelloWeb.java that contains exactly the code for the applet. Compile the HelloWeb class as you compiled the HelloWorld class; that is type javac HelloWeb.java.

    To run your HelloWeb applet, you'll need to create an html file for a simple Web page, such as this html file. Call this file HelloWeb.html. After creating the file, type netscape & and after the netscape window has popped up, type in the box marked "Location:":

    file:/wherever/HelloWeb.html

    where /wherever is the full pathname of the directory where your html file is stored. You can get this pathname by typing the Unix command pwd in the directory that contains the html file.

    Turn in a printout of the page you see when you view the html file in Netscape.

    CORRECTION: turn in a description of where the message appears on the web page.

  3. This third exercise involves creating and running this example Java program that uses a command line argument. Create a file called Fibonacci.java that contains this program. Compile the program, and then run it by typing java Fibonacci 50. Create a file called fibonacci.out containing the output of the program, and turn in this file following the Handin instructions mentioned above.

    What happens if you give a negative number, such as -1, to your Fibonacci program? Turn in a brief explanation of how you would change the code to fix this problem.

Summary of what to turn in:

  • electronically, using the Handin instructions:

    1. your helloworld.out file from exercise #1.
    2. your fibonacci.out file from exercise #3.

  • on paper:

    1. a printout of the page created by your HelloWeb applet in exercise 2.
    2. an explanation of what happens when you give the Fibonacci program a negative number, and how you would modify the program to fix this problem.


    vernon@cs.wisc.edu