CSCI 111 LAB 2
previously CSCI 15a

Lab Times: See course home page

TA: See course home page

Worth:10 points


In this assignment we will be examining how the javac compiler works and learn some new Unix commands.

  1. An important process to be learned early is how to use the compiler to help us debug our programs.

    Some simple rules to follow.........

    Common compile time errors that most users make include


    Use ssh (through Putty) and WinSCP to get onto a UNIX machine. Since WinSCP only lets you have a command prompt for one command at a time, and it will not allow user input, it is often easier to use both tools: winSCP for editing and putty of UNIX commands

    Once logged in, get into your public_html directory:

    cd public_html

    If you have not already made subdirectories, do it now (particularly 2 through 4).

    Once you have the directories set up for the course, you can then get into your csci111 and lab 2 directory.

    cd csci111/lab2

    Copy the following java source file, this file contains errors that you will correct. Don't worry we'll walk you though this example...

         cp  ~amk/courses/csci15a/15a_examples/DrawACircle.java    ./  
    .

    Don't forget the period slash at the end of the above command. Now try to compile the DrawACircle.java file. You saw how to compile java programs in lab 1. You should expect to see a number of errors. There are 4 compile time errors in the DrawACircle.java program that need to be fixed. The compiler will not catch all the errors at first and it may even report them in the wrong place. So expect to see initially three errors.

    Note all lines that start with // are comments and are there to descibe the program and provide detail you and others of what is going on in the code.

    The first error reported is

     
    DrawACircle.java:34: ';' expected.
                    return Math.cos(RadianAngle)
                                                ^ 
    

    This error says that we are missing a semicolon at the end of line 34. Use pico (or WinSCP editor) and add that missing semicolon. (Your compiler might say error on line 35 and point to the }. It is the same error --- basically a ; should be at the end of line 34. So when the compiler gets to line 35 it notes that it sees the curly bracket and yet the code is missing a semicolon.) See this page lab 2 for how to get to a certain line. Save the file and recompile.

    The first error should now be gone and now on to the second error.

     
    DrawACircle.java:104: '}' expected.
    }
     ^
    

    This error is misleading since the real error is elsewhere in the code. But it is a simple error to fix. We are missing a curly bracket in our code, every block of code must begin with a { open curly bracket and end with } a close curly bracket. Unfortunately the compiler can not tell us where it is missing but only that one or more is missing. The missing curly bracket is on line 45.
    Count and match up the curly brackets in the ComputeUnitCircle class and you will see that there is a missing bracket there. This can be a very hard error to find, since you must search the code and match up all open and closing curly brackets. Use pico (or WinSCP editor) and add the missing curly bracket and recompile the file.

    Now save your .java class, recompile it, and you will see that new errors have shown up. After this compile you now see:

    DrawACircle.java:58: cannot find symbol
    symbol: class Applet
    public class DrawACircle extends Applet
                                     ^
       
    

    This is a misleading error also since the real problem is not on line 58 but much earlier in the code. The real problem is that the compiler is missing the definition of the Applet class. The problem is that we forgot to import the library that contains the Applet class. So we must add the correct import statement in the import section of the lab (on line 15 or so) of the DrawACircle.java file. Do not remove the other import statement.

    	import java.applet.*;
                                     ^      
    

    Then save and recompile the file. There should now be a new error.

    DrawACircle.java:89: cannot find symbol
    symbol  : variable mycircle
    location: class DrawACircle
                    x=(int)(mycircle.ComputeX((double)degrees/180*3.14)*24+25);
                            ^
    

    This is a very simple error and it is even giving us the right line the error is on. The error is that mycircle is misspelled( capitalization is important) and should be changed to myCircle . Fix this error and recompile.

  2. Create a web page called lab2.html to display the corrected applet. You can accomplish this task in a similar manner as Lab 1 and the .html file there but (of course) with the proper class in the applet tag. Problems - maybe you made mistakes like these?

  3. Use the man command to look up the following commands. Write a short desciption of each command. Lookup "finger", "who", "uptime" and "mv" commands. Here is an example of using the "man" command to look up the "w" command.
        
              man w  
    
    

  4. Make another file in your lab2 directory called README. In it, write short descriptions of the four commands you looked up. Save it. We want to be able to see it with your other work for lab2 so add one more reference link to your lab2.html file <p> <a href="README"> README </a> <br>

  5. Make one more reference link in your lab2.html that will link to the edited source code.

  6. Submission:

    Web Page Submission Required Contents:

    1. A link to lab2 directory or lab2.html from your csci111 course page (should have been done already in Lab 1),
    2. Exercise number 2 (the lab2.html web page) with
      • the correct applet from item #1 (above) running on it
      • a link to the README file
      • a link to your corrected source code (looks a lot like the link to the README does but it links to the source).

Unix Commands


w
who is logged on to the system with process information

rwho
who is logged on to the local network of Unix servers

ping
network packet time from host to another machine

traceroute
the route an Internet connection takes for sending packets

vi
visual editor

emacs
another visual editor created by GNU organization

mv
move and rename command

ps
find my current processes

kill
shutdown processes

checkdisk
check quota and available disk space

talk
simple chat tool

date
today's date and time

cal
calendar

ln
link to a directory ( short cut to a path )

mkdir
create a new directory

finger
 
who
 
uptime
 

Web Sites
check these out