CSCI 235 Lab 1: Introduction to CS Lab

The goal of this lab is to familiarize you with the equipment and software in the CS Lab.

What is it called?

The computers in the Computer Science Lab run different software from what you may be most familiar with, which is likely to be some version of Microsoft Windows or Apple’s Mac OS X. What you see may be called any of Unix, Linux, Ubuntu, or even GNOME. Here is what each of those actually means:

So now we know what everything is, right?

What hardware is in the lab?

There are twenty-five computers in the lab (Science 154), with the imaginative names cslab01 through cslab25. You might want to know their names, because you can use any of them over the campus network.

The machines that you can see are supported by several more that are hiding in a closet. You won’t need to be directly aware of those, but they are set up so that you can use any of the twenty-five lab machines interchangeably. If you work on one computer, you will see all of the same files when you come back later and work on another one.

Getting down to business

Complete the following tasks.

Log in on the console. Our lab is separate from the rest of the campus facilities, but we have set it up so that your account name and password are the same as for your standard campus (Novell, portal, Banner, etc.) account.

Explore the desktop. After you log in, you should find yourself looking at a GNOME desktop—and most of it will be blank space. But it has menus at the top, and some buttons and other useful things will show up at the bottom.

First, a bit of terminology for the mouse. When we don’t say, use the left mouse button, which is what you’ll use the most. ‘Click’ means press and release once; ‘press’ means to hold it (and keep holding it while you move). The X window system was designed for a three-button mouse; usually if you have only two buttons, you can simulate the third by pressing on the scroll wheel. The rolling the scroll wheel will scroll what you are pointing at.

Select Firefox in the Applications, Internet menu to launch a web browser. Then type the URL for this lab in the address box:

http://cs.wheaton.edu/~cgray/csci235/labs/unix1.html

That should bring up an online copy of this lab.

Launch a Terminal window, too; you’ll find it under Applications, Accessories.

Now look at the bar at the bottom of your screen. You should see a button there for each window that is open (one for Firefox and one for Terminal). Clicking on one of those buttons will do one of three things:

Looking at your files In the Places menu, select Home folder. That will launch a file browser, similar to the Mac OS Finder or the MS Windows Explorer. It will be looking at your home folder.

Now bring your Terminal window to the top. What you type in this window will be interpreted by a program called a shell, which treats what you have typed as a command to run a program.

For a first command, type

ls

and hit the Enter key. This command lists the contents of the current directory (folder). You should see the names of the same things that you can see in the file browser window.

Most commands have three parts:

  1. the command name,
  2. options and switches, which usually begin with either ‘-’ or ‘--’, and
  3. arguments (usually the names of files or directories).

We could ask ls for more information with one or more of several options:

Names that start with a period (often pronounced ‘dot’) are normally hidden; the last of these options says to show them, too. Try giving ls various combinations of options; each option should be separated from what comes before it by one or more spaces.

When you use -a, you’ll see that there are some names starting with dot. Two of these names are special:

After the options, you can give ls the name of a directory/file (or more) that it should list; if you don’t supply a name, it will list .. So try listing the contents of ., .., and other directories that you can see. Combine those with options, too, as in

ls -l .
ls -a -F ..

Notice that Unix commands tend to be short and a bit cryptic. It may be a little intimidating, but you should be able to remember the ones you need most often.

Making directories and wandering about You might take more than one course that uses these computers; so it would be a good idea to make a directory for this class. You do that with the command mkdir:

mkdir cs235

If you now list the current directory, you should see the one that you have made. Notice that Unix commands typically do not print anything when they work; mkdir will complain if it doesn’t work, but if all you get is your command prompt, the command worked.

You can change the current directory with cd. But before going somewhere else, it is good to know where you are; the command

pwd

will print the current working directory. You should see something like /homes/msnerd, except with your user name instead of msnerd.

Now change into the directory you’ve made, and print where you are:

cd cs235
pwd

If you want to go up to the containing directory, use the special name dot-dot:

cd ..

It is also good to remember that you can always go home by giving cd without an argument.

Change back into you directory for this class, and pwd to make sure that you are there. Then make a directory lab1 for today’s work, and cd into it. Print to see where you are.

Warning: Unix commands usually act as if you mean what you said; so they won’t normally ask you if you really meant to do something. It is a good idea to pause and think about it before you hit Enter when a command might do some damage. If you want to be cautious, the rm, mv and cp commands described below can be given a -i option (right after the command name) to make them ask before they overwrite or delete anything.

Now you are going to copy a file to use in this lab; use the command

cp /cslab/class/csci235/lab1/PrimeFact.java .

Notice that there is a dot as the second argument; this command says to copy a particular file from the class directory to dot, the current directory. If you use ls, you should see it now.

If the second argument is a file name, you’d copy the file to that name. So you could try

cp PrimeFact.java Silly.java

If you list the directory, you should see both of them.

You rename a file by moving it with mv. So try

mv Funny.java Silly.java

That will not work, because there is no file named Funny.java. If you use -i, you can try

mv -i Silly.java PrimeFact.java

it will ask you if you really want to, because the move would cause the old PrimeFact.java to be discarded.

To delete a file, you remove it with rm. Be careful, because what is removed is gone for good. You could try

rm -i *

The * is a wildcard; it matches any filename. If you say yes, you will remove all of your files in this directory—which is O.K., because you can copy PrimeFact.java from the class directory again.

Inside a file If you want to just look at what is in a file, the easy command to use is less. (Don’t ask why; it’s a silly story.) So, if you have a copy of PrimeFact.java, you can look at it with

less PrimeFact.java

You’ll be able to page through the file; the keys you want to know are that q will quit and space will page forward. If you want to know more, try h for help.

For editing, we recommend that you learn at least a little about working with a program called XEmacs. You’ll usually start it up with the name of a file to work on; you’ll also add an ampersand to the end of the command. So try

xemacs PrimeFact.java &

You’ll notice that xemacs creates a new window to work in; the ampersand tells the shell to prompt you for a new command as soon as xemacs has started, instead of waiting for xemacs to finish.

XEmacs (like its kin) is a very powerful, customizable editor. If you’re going to do very much work, it will be worth taking some time to learn to do lots of things without taking your hands off the keyboard. But you’ll be able to manage for now using the mouse, the arrow keys, and the buttons and menus at the top of the window.

You should be looking at the contents of PrimeFact.java that we wrote in class. Change the author’s name to yours, and the date to today’s. Tip: xemacs inserts what you type if it is a normal letter. If you want to delete the letter you are on, use ctrl-D (hold the Control key and hit D). There are lots of things that you can do; the help in xemacs will often write ctrl-D as ^D. The key that you want to remember is ^G, which is the general-purpose “stop whatever I am doing” key.

When you have made your changes, save the file. (I’ll let you figure out how.) Then go back to your terminal window. If you ls, you’ll see that there is now a file with a tilde on the end of its name: xemacs makes a backup copy of a file when you edit it, which may save you sometime if you manage to make a mess.

Compiling and running a Java program You have a Java program now. To compile it, use

javac PrimeFact.java

If you ls, you should see a new file named PrimeFact.class, which is the compiled (machine-oriented) version of your program. You can run it with

java PrimeFact

Now try changing the number ot be factored, recompile, and run it again.

Note: The compiler javac works on files; so you specify a full filename for it. The java command works on the program, using whatever class files it finds; so the argument there is the name of the program (which is expected to match the first part of the name of the .java file).

There is nothing to hand in this week.

If you have time (it takes about thirty minutes), you might want to walk through the tutorial built into XEmacs. You can start it by typing ESC ? t.

Before you go, please exit XEmacs and log out.

1Or, if you think like a lawyer, the trademark is UNIX (in all capitals). It was originally owned by the Bell Telephone System, back when that was the U.S. telephone monopoly. One of the reasons that UNIX became popular in universities was that Bell could not go into the computer business because of their telephone monopoly; so they close to gave away UNIX to universities for a number of years.