CSCI 201 Lab 1

The goal for this week's lab is to learn about the computer environment and applications you'll use in your CSCI 201 labs. You don't need to have a broad knowledge of computers to write simple programs, but there are a few skills you'll need and this is your chance to learn a practice a few of them. Here's what we'll cover.

  1. Controlling applications in a windowed environment
  2. Using files and directories
  3. Accessing class information on the Internet
  4. Sending and receiving email
  5. Using FTP to submit assignments
  6. Running Java in a command session

Controlling applications in a windowed environment

If your computer is turned off, power it on. If your computer is running Windose, reboot it. When the computer gives you a choice of choosing between running Linux and Windows XP, do the right thing.

Your instructor will provide you with your Linux user id and your initial password and tell you how to log into Linux. This password will work on the UNCA Computer Science workstations in RH004.

The running computer should display a desktop similar to the following picture:
Hey. It doesn't look that different from Windows does it? In fact, the Linux and Windows user interfaces are derived from a common standard defined about a decade ago. The initial display may be slightly different on other versions of Linux. The Computer Science machines use the GNOME desktop. You can find entire books on GNOME, even one of the Dummies© books.

The "Taskbar" and "Start" button

At the bottom of the screen is the bottom edge panel. It is very similar to the Windows "Taskbar".
Bottom Edge Panel
The leftmost button, the one that looks like a paw print, is the GNOME Menu button. It is similar to the Windows "Start" button.

Select the GNOME Menu button with the left mouse button and you will see a menu that allows you to run applications by selecting them with your mouse.

Move your mouse so that the cursor moves up and down the selection of items on the GNOME menu. Notice that when you move the cursor to a menu selection with a right arrow, a sub-menu is displayed showing you more even more selections.

Navigate through the GNOME menu to start a text editor called gedit. You'll find it by going from Programs to Applications to gedit.
GNOME menu for gedit

The titlebar and its controls

Observe the window for the gedit application.
For you Windows users, it's deja-vu all over again. At the top of the window is the titlebar which shows the name of the application that is running. On the right side of the title bar are three control elements: _OX. The rightmost button, Close button, is the close windows button. This button terminates the running application and closes its window. The middle button, Maximize button, is the maximize button. It expands the window to the size of the full screen. This is rarely anything you'll want to do. Only the left-most or minimize button, Minimize button, remains. This control suspends the application. There is a window "list" at the bottom of the screen that can be used to revive suspended applications.
Window List

Moving and resizing the window

If you press the leftmost mouse button within the titlebar of a window, you can drag the application to different locations within the screen

If you move the mouse to the edges or corners of a windows, the cursor will become a two-headed arrow. If you then press and hold down the leftmost mouse button, you can change the size of a window.

Trying it out

There's no point in giving more explanation. It's time for you to take your gedit for a spin around the display. Move, resize, minimize, and unminimize. If you have any trouble, get the attention of your lab instructor or the person in the adjoining chair.

Running applications

Directly below the titlebar of gedit is the menubar, a row of words such as such as File and Edit. If you press a word on the menu bar, you will rewarded with a pulldown menu, which can be used to direct the actions of the applications. Below the menu bar, you'll often find a toolbar, containing many icons that represent frequently performed actions, such as printing.

Using files and directories

If you've taken, CSCI 107, you should have learned quite a bit about directories and files in Lab 2 of CSCI 107. If this is your first exposure to this concept, settle in for a few minutes of serious study. A file is a collection of data, generally formatted for use by a specific application, such as a database or spreadsheet. A directory is just a collection of files; it can be thought of as a file folder. Directories are maintained in a tree-like structure; that is, directories may contain other directories.

File names

Files and directories are identified by their names. Under Unix, names are case-sensitive. That is, the filename LAB1.HTML is quite different than lab1.html.

In both the Unix and Windows worlds, a file may be referred to using its path name. The path name really is a path which you take to locate a certain file. As mentioned, directories can be nested within each other to form a tree structure. The path name is made up of the filename, preceded by the names of the directories which contain that file. The directory names are separated by slashes: forward slashes, /, in Unix; and backward slashes, \, in Windows. (By the way, it was Unix that first used the slash.) Here are some example path names in Unix and Windows:

Notice, that both of the above path names start with a slash, which means that both emanate from a special root directory. Path names that begin with the root directory are also called absolute file names. Windows has the additional complexity that absolute file names may start with a drive letter, as in A:/autoexec.bat. This tells us that the file is located on a specific drive. Generally, drive letter A is the floppy disk drive and C is the hard disk. In Unix, all devices, including hard drives and cdroms, fit into the normal directory structure. You may also notice that our example Windows file name contained spaces while the Unix file name did not. Although you can put a space in a Unix file name, you would only offend the true Unix gurus.

Notice that both of our example names end with ".html". In both Unix and Windows it is common for file names to end with a period followed by an extension, "html" is our examples. The extension generally identifies the type of the file. You'll be generating a lot of files with the extensions "java" and "class" this term.

Both Unix and Windows support relative file names. These are path names that do not begin with a slash and are considered to emanate from the current working directory, the directory in which you are currently "located". When you first login, your current working directory is your home directory which will be something similar to /candler/users/YOURID. So, if you are John Q. Smith and you are in your home directory when you reference the file X11/mwm, you are really talking about absolute file name /candler/users/smithjq/X11/mwm.

Graphical display of files

Most computer users, especially those of the Macintosh sect, use directories and files with absolutely no idea of how a slash is used in file names. They use file "explorers". Many, but not all, versions of Linux have a graphical file interface called Nautilus. However, we really don't do that many fancy things with files in CSCI 201, so we're going to just use the old-fashion Unix file commands. After all that's what all the true Linux gurus do.

Linux file commands

Start up a Linux terminal session. You can do this through the GNOME menu via Programs to System to GNOME terminal, but it's easier just to click the icon on the bottom edge that looks like a paw-print in front of a monitor. Now you can type raw Unix commands into your terminal session.
Linux terminal session

First type the command pwd, print working directory. This will give you the name of your home directory which is where you are currently located. Any relative file name, a file name that doesn't start with a slash, that you reference must be located within this directory. As mentioned above, the command should respond with /candler/users/yourid indicating that your home directory is stored on candler, a Computer Science file server.

[user@mach dir] pwd

In our displays of computer output; the responses of the computer will be normal navy, the prompts of the computer will in bold navy, and text typed by you will be bold maroon.

You can list the contents of a directory with the ls command. To make it a bit more interesting try ls -a and then ls -l. The options -a and -l are separated from the command ls with spaces.

[user@mach dir] ls
[user@mach dir] ls -a
.   csci    .dt         .emacs  .kde       .wastebasket 
..  .cshrc  .dtprofile  .gtkrc  .solregis
[user@mach dir] ls -l
total 4
drwx------    2 lincolna man          4096 Aug 15 16:39 csci

The bare ls command lists just one directory within your home directory. Adding the -a, for all, option causes several control files to be listed. In general, control files start with a period and are normally "hidden" by ls. Adding the -l, for long, option gives more information about your file. In the example above, you see the owner, size, and creation date of the files along with other information.

You can change your working directory with the command cd. However, it's rare that we do so in CSCI 201 so we'll not worry about that for a while. You can create a directory with mkdir. Go ahead and create a directory called csci, its subdirectory csci/201, and its subsubdirectory csci/201/lab1 with the commands shown below.

[user@mach dir] mkdir csci
mkdir: cannot create directory `csci': File exists
[user@mach dir] mkdir csci/201
[user@mach dir] mkdir csci/201/lab1

You may have noticed that there was no confirmation that the directories were actually created. Unix is like that. It only speaks when something goes wrong, like when you tried to create the directory csci which already exists. Type the ls command if you want to see if the directory csci/201/lab1 was actually created.

Remember the "drwx------" you saw associated with the directory csci when you typed the ls -l command. The "drwx------" informs you that this directory and its subdirectory can only be accessed by you. If you want to learn more about Linux file permissions (and you should), take some time to read our Unix File Permissions tutorial.

Below is a summary of the commands that we have learned in this section, plus a few that you may find useful in the future.

pwd Print Working Directory:
Prints out the full pathname of the directory you are currently in.
cd directory Change Directory:
Changes your current directory. If you don't specify a directory as an argument, cd will bring you back to your home directory.
ls directory ... List:
Lists the contents of a directory or directories. If you don't specify a directory, ls will list the contents of the current directory. You may also supply filename(s) to ls in order to get more information about files.
The ls command also supports options: "ls -a directory" lists files that are normally hidden, and "ls -l  directory" lists more information about your files
mkdir directory ... Make Directory:
Used to create a directory or directories.
rmdir directory ... Remove Directory:
Used to remove an empty directory or directories. The directories to be removed must not contain any files.
more file
less file
These two programs will let you view your file a screenful at a time. They both offer special viewing options such as paging backwards through a file and pattern searching. less is the more sophisticated of the two and has features that aren't found in more.
rm file1 ... Remove:
Removes the given file or files.
mv file1 file2
mv file1 ... fileN directory
Moves a file or directory. In the first form, file1 will be moved to (renamed as) file2. The second form will move a number of files into a directory which you specify as the last argument. Note that directory names can be used in place of the filenames in either of the forms, to move or rename directories.
cp file1 file2
cp file1 ... fileN directory
Copies files. In the first form, file1 will be copied to a file called file2. The second form will copy a number of files into a directory which you specify as the last argument on the command line.

To learn more about working with Unix files and directories, take a look at this more comprehensive Unix file system tutorial.

Directory Creation Checkoff

This is your first checkoff point. Show your lab instructor your Linux terminal window, so that he/she can verify that you have created the right directories.

Accessing class information on the Internet

If you don't know how to use a browser, such as Netscape or Internet Explorer, then:

Microsoft Internet Explorer is not supported for Linux. The reasons for this are best left to anti-trust lawyers. Netscape is supported, but we won't use it. We'll use Mozilla, an open source browser with a Netscape 6 parentage. You can start Mozilla through the GNOME menu or with that red Godzilla-like icon at the bottom of your screen.

Once Mozilla is running, load the following URL:

From there you should find a link to the course lab page. Follow it to Lab 1. From this point on, you are expected to complete this lab, and all future labs, by viewing the lab instructions in your browser.

Sending and receiving email

At UNCA, you must be able to read and send mail from your bulldog account. This is the email address that UNCA faculty will use for "official" classroom correspondence. There are two ways to read and send mail from your bulldog account:

We're going to assume that most of you will use WebMail since it allows you to read email using any Internet browser. We're also going to assume that most of you have already used WebMail. If you haven't, you need to read UNCA's Web Based E-Mail User's Guide.

Some of you may already have an off-campus email account you'd like to use for course-related mail. If so, you must set up your bulldog account to forward email to your off-campus account, because some UNCA faculty will not send confidential course-related email to an off-campus address. You can ask the folks in the Computer Center for help in setting up mail forwarding.

Lab email assignment

Your first task is to read your bulldog email to obtain the name of your 201 drop-off directory. It should be contained in an email message from the course instructor. Remember this information but do not share it with others.

Your second task is to send a short note to your lab instructor telling him/her about your computer experience. The email address of your CSCI 201 lab instructor can be found in the table below:

J. Dean Brock
Rebecca Bruce
Joe Daugherty
Susan Reiser
Charlie Wallin

Using FTP to submit assignments

FTP, or File Transfer Protocol, is a very simple program that can be used to transfer files between different computers. In CSCI 201, you will use FTP to transfer program solutions to your assignment drop-off directory stored on the UNCA CSCI file server.

Preparing to FTP

You need a file to ftp. You can get one by cutting the following Java code and pasting it into your gedit application.

//       Author: Lewis and Loftus
//  Demonstrates the basic structure of a Java application.

public class Lincoln
   //  Prints a presidential quote.
   public static void main (String[] args)
      System.out.println ("A quote by Abraham Lincoln:");

      System.out.println ("Whatever you are, be a good one.");

Now save the file in your csci/201/lab1 directory under the name Be sure that you "click" through all three directories, csci, 201, and lab1, in the process of saving this file!
File Save example

Before you can transfer the file you must know the name of the directory that you will use when submitting your homework. This is your personal ftp directory and it should never be used by others. Your ftp directory name is like a password, it should be kept secret.

The original FTP program

The ftp program "speaks" the FTP protocol to a file server when it transfer files. The ftp program was one of the first two Internet applications. It is a text-oriented program that may seem a little quaint compared to today's graphic-oriented programs, like the ones you'll be writing in Java. We are going to use the original ftp program because it is the only FTP uploader that "ships" with every copy of Windows XX and Unix. So you should be able to follow this procedure at home or school, no matter what computer is sitting in front of you.

Transferring files to your drop-off directory

Remember, you can going to transfer a file (and later files) to your drop-off directory. You'll need to know three pieces of information to complete this task.

  1. The name of the directory containing the file on your PC. In our example, that is csci/201/lab1.
  2. The name of the file to be transfered; we'll use (Items 1 and 2 together form the file name relative to the current working directory, in this case, your home directory.)
  3. The name of your drop-off directory. In this example, we'll use alincoln1809.

Starting the FTP program

Go back to your terminal window and type the command "ftp". The FTP program should provide you with the following greeting.

[user@mach dir] ftp
Connected to (
220-Welcome to, Sun Jan 26 16:09:46 2003
220 FTP server ready.
Name ( 

You should type ftp followed by the Enter key at this initial user prompt. You will then be prompted for a password. Just type your email address as your password. Your email address is your bulldog user-id followed by For example, if your bulldog user-id is alincoln, your email address is Your email address will not be displayed when your typed it.

If you have successfully connected, the ftp program should be at its command prompt.

Connected to (
220-Welcome to, Sun Jan 26 16:12:55 2003
220 FTP server ready.
Name ( ftp
331 Guest login ok, send your complete e-mail address as password.
Password:  type your email address here, it will not be echoed
230-This is the anonymous FTP server of the Department of Computer Science
230-at the University of North Carolina at Asheville.
230 Guest login ok, access restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.

Your next step to do connect to the local directory where your files are now stored. This is done with the lcd, local change directory, command.

ftp> lcd csci/201/lab1
Local directory now /candler/users/YOURID/csci/201/lab1

Now you must change to your secret drop-off directory. This is done with the cd command. In our example the secret drop-off name is alincoln1809; consequently, the remote drop-off directory is pub/201/alincoln1809. In general, if your secret drop-off name is LOGINnnnn, your drop-off directory is pub/201/LOGINnnnn.

ftp> cd pub/201/LOGINnnn
250-Unca Students's CSCI 201 dropoff
250 CWD command successful.

Transfer the file(s) that you want to submit by typing the put command followed by the file name. You should receive some indication of successful transmission. Remember, we are submitting

ftp> put
local: remote:
227 Entering Passive Mode (152,18,69,7,37,230)
150 Opening BINARY mode data connection for aliases.
226 Transfer complete.
652 bytes sent in 0.00272 seconds (2.3e+02 Kbytes/sec)

You can use the dir command to list your remote drop-off directory and the quit command to end your ftp session. Don't worry about the format of the dir command. Just make sure your submitted file is listed in the rightmost column.

ftp> dir
227 Entering Passive Mode (152,18,69,7,27,49)
150 Opening ASCII mode data connection for /bin/ls.
total 16
-rw-rw-r--   1 brock    csci201       31 Aug 10 14:21 .message
-rw-rw-rw-   1 bruce    csci201      634 Jan 22 08:59
226 Transfer complete.
ftp> quit

FTP checkoff

Show your lab instructor the output of the dir command.

Running Java in a command session

We're going to run Java the old fashioned way.

We'll be using Sun's J2SDK, Java 2 Software Development Kit, in CSCI 201. You'll find a copy of the J2SDK on the CD-ROM distributed with your textbook. It can also be downloaded from Sun's Java Technology page.

We want everyone to be using version 1.4.0_01 of the Standard Edition (J2SE) of the Java Software Development Kit. Determine your version by typing the command "java -version". You should see something similar to the following output even if you are running Windows at home.

[user@mach dir] java -version
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

If your version is not 1.4.0_01, you need a new J2SDK install.

Suppose if you have installed the J2SDK on your home Windows computer and get the following message:

'java' is not recognized as an internal or external command,
operable program or batch file.

If this happens you need to consult Sun's installation instructions for Windows to find out how to set the path "permanently".

Now let's change our working directory to be csci/201/lab1 (the directory where is located) and use javac, the Java compiler, to compile our program.

[user@mach dir] cd csci/201/lab1
[user@mach dir] javac

The java compiler, javac, translates your program into bytecode. If you now type the ls command, you should see another file called Lincoln.class that was created by the compiler and contains your bytecode.

The class file is used by the java interpreter. To run the file, type the command "java Lincoln". You should be rewarded with the output of the Java program.

Java program checkoff

Show your lab instructor the result of running your program.

Finishing up

Return to the Linux terminal and execute the yppasswd command to change your password to something you can remember. Then use the GNOME menu to find the Log out so that you can shut down the computer and go home.