Prelab 5: Debugging "Buggy" Code

This lab will require you to have a very good understanding of the introductory chapters to JAVA.

MAKE SURE YOU HAVE READ AND UNDERSTAND CHAPTERS 2 AND 3 in GREAT IDEAS IN COMPUTER SCIENCE

Turn in written answers to all of the indicated questions in each section as your prelab

Understanding Unix Commands

You will have a Unix "quiz" that will count towards your lab grade at the beginning of lab period. Make sure you are familiar with Unix commands.

Unix Basics

Make sure that you know more than just what the commands do. You should be able to use them in a logical combination to follow such instructions as:

Make a lab5 folder in your cps001 directory.
Copy files to display your lab 3 files on the web

The UNIX quiz will count as 2 points for your grade on this lab.


There are some things which the tutorial above does not cover, but which you need to know to work comfortably in Unix.
When you are working in Unix, you are always working in some directory. A directory in Unix is exactly like a folder in Windows. To find the directory you are currently in, use

pwd
pwd is short for 'present working directory'. If you do pwd in your home directory, which is the default working directory after you log into Unix through F-secure, etc., you should see something like

/afs/acpub.duke.edu/users/m/m/xyz123
where xyz123 is your acpub id. /afs/acpub.duke.edu/users/m/m/xyz123 is the name of your home directory. Notice that it begins with a forward slash. There are two ways to use a directory name. Directory names that begin with forward slashes are absolute. Directory names that do not begin with a slash are relative to the present directory. You have a cps001 directory in your home directory. There are two ways to get into it:
cd /afs/acpub.duke.edu/users/m/m/xyz123/cps001
cd cps001
The first, because it is absolute, works no matter which directory you execute it in. The second, because it is relative, only works from your home directory because the cps001 directory is inside the home directory.

The absolute directory name above is rather long. Fortunately, you don't have to remember it or keep typing it in all the time. You can use the shortcut
cd ~xyz123/cps001
instead of
cd /afs/acpub.duke.edu/users/m/m/xyz123/cps001
You can use ~xyz123 instead of /afs/acpub.duke.edu/users/m/m/xyz123 for any Unix command, not just cd.

Finally, . (a period) in Unix is short for the present working directory, and .. (two periods) is short for the parent of the current directory. For example, if you do
cd ..
in your cps001 directory, you go to your home directory. If you use the same command in your lab1 directory, you go to your CPS001 directory. If you do
cd .
in some directory, you stay in that directory.

Questions to be handed in

Debugging

Read the debugging handout distributed in lecture and found below.

Debugging
It has a lot of useful advice as to how to go about debugging your code in a systematic fashion. Once again, make sure you have read chapters 2 and 3 so that you are familiar with most of the JAVA rules. Errors arise mostly when these rules are not followed.

Questions to be handed in

Practice with operator precedence and Modulus and Divide

You should understand the order in which JAVA operators are applied in an expression. For example, does 8*4+6 equal 38 or 80? Please become fimiliar with precedence of operators such as && and || (logical AND and OR). Also, make sure you understand the difference between logical and bitwise AND and OR. The JAVA tutorial will help you here.

For this lab, you will need to become familiar with the behavior of the mod (%) and div (/) operators in JAVA.
Command Explanation
% Modulus calculates the remainder when dividing two numbers Example: 5 % 3 = 2
/ Division: It is important to note that with integer division, numbers are not rounded to the nearest value. Rather, the remainder (or decimals) would just be truncated. Example: 27 / 7 = 3

Questions to be handed in


JRNF
Last modified: Sun Feb 9 16:32:27 EST 2003