CSCI 201 Lab 1 -- Linux version

The goal for this week's lab is to learn about the computer environment and applications you'll use in your CSCI 201 labs and classwork. 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 you computer is running Windoze, 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. If you've used Solaris before, you're welcome to use it again in the CSCI 201 labs. However, this lab is written for the Linux computers.

The running computer should display a desktop similar to the following picture:
GNOME at UNCA CSCI
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 icons 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.
gedit
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 a collection of files and other subdirectories.

File names

Files and directories have names. In both the Unix and Windows worlds, these names are series of directory names 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 file names in Unix and Windows:

Notice, that both of the above file names start with a slash, which means that both emanate from a special root directory. These are 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. 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 names do not begin with a slash and are considered to emanate from the current directory. So, if your current directory is /usr/bin and you speak of the file X11/mwm, you are really talking about /usr/bin/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 a 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 will 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 find press 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 current directory. The search for all relative file names (the ones that don't start with a slash) begin here. The command should respond with /burnsville/users/yourid. This indicates that your home directory is stored on burnsville, a Computer Science file server.

pensacola% pwd
/burnsville/users/YOURID

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.

pensacola% ls
csci
pensacola% ls -a
.   csci    .dt         .emacs  .kde       .wastebasket 
..  .cshrc  .dtprofile  .gtkrc  .solregis               
pensacola% 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. For example, you see the owner, size, and creation date of the files.

You can change your working directory with the 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.

pensacola% mkdir csci
mkdir: cannot create directory `csci': File exists
pensacola% mkdir csci/201
pensacola% 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.

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 is given in the table below:

Mark Boyd boyd@cs.unca.edu
J. Dean Brock brock@cs.unca.edu
Susan Reiser reiser@cs.unca.edu
Charlie Wallin wallin@cs.unca.edu

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.


//********************************************************************
//  Lincoln.java       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 Lincoln.java. 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 PC directory containing the file. In our example, that is csci/201/lab1.
  2. The name of the files to be transfered. We'll use Lincoln.java.
  3. The name of your drop-off directory. In our example, we'll use alincoln1809.

Starting the FTP program

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

Connected to ftp.cs.unca.edu.
220-Welcome to ftp.cs.unca.edu, Sat Aug 10 15:25:15 2002
220-
220 FTP server ready.
User (woodfin.cs.unca.edu:(none)): 

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 @bulldog.unca.edu. For example, if your bulldog user-id is alincoln, your email address is alincoln@bulldog.unca.edu. 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 ftp.cs.unca.edu.
220-Welcome to ftp.cs.unca.edu, Sat Aug 10 15:25:15 2002
220-
220 FTP server ready.
User (woodfin.cs.unca.edu:(none)): ftp
331 Guest login ok, send your complete e-mail address as password.
Password:
230-This is the anonymous FTP server of the Department of Computer Science
230-at the University of North Carolina at Asheville.
230-
230-
230 Guest login ok, access restrictions apply.
ftp>

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 /burnsville/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/alincoln1809
250-Abe Lincoln's CSCI 201 dropoff
250-
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 Lincoln.java.

ftp> put Lincoln.java
200 PORT command successful.
150 Opening ASCII mode data connection for Lincoln.java.
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,177,122)
150 Opening ASCII mode data connection for /bin/ls.
total 2
-rw-rw-r--   1 brock    csci201       31 Aug 10 14:21 .message
-rw-rw-rw-   1 bruce    csci201      632 Aug 10 14:42 Lincoln.java
226 Transfer complete.
ftp> quit

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.

pensacola% 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:

C:\>java
'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 connect to the csci/201/lab1 directory and use javac, the Java compiler, to compile our program.

pensacola% cd csci/201/lab1

pensacola% javac Lincoln.java

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.

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.

Logout