CSCI 241 Labs: PreLab 1

Introduction to Linux and BlueJ


Introduction

The beginning of this document introduces you to procedures and commands for working in the UW-Parkside Computer Science Department lab; the end introduces BlueJ. The Linux command section contains all commands you will need this semester. Another (more extensive) handout, "Getting Started in UNIX", complements this document and is available in the lab. These handouts will be useful all semester, so keep them with you when you are working on lab machines.

Activating your Computer Science (CS) Lab account

The Computer Science Department has established policies that all lab users must follow. They are summarized in the account policy sheet. Make certain you read, understand and follow these policies.

The very first time (and only the first time) you use a computer in the lab, you need to activate your account. Your Computer Science (CS) Lab account will have a DIFFERENT login ID and password than the one you use for other UWP access.

Logging In

Your lab login id and password are associated with your lab account, not with one particular machine. Use them at any machine in the room.
  1. The computer system you use in the Computer Science Laboratory runs the Linux operating system. Linux is a variant of UNIX, and our lab currently uses CentOS linux.
  2. If the screen is blank, press any key to bring it to life. The monitor may be turned off; turn it on if necessary (our monitors will go to sleep after a short time with no computer use). PLEASE keep your fingers from touching the screens - they are not easily cleanable. You should now see a screen with the current date and time. Press the Enter key (or roll the mouse wheel). Now you should see a dialogue box where you can enter your "Username:". Enter your CS department login name and press Enter. Then, one more dialogue box appears asking for your password. Type your password in the box and then press the Enter key.
  3. If your login is successful, there will be a short delay (needed to load your profile) followed by the display of some startup Gnome windows (Gnome is your Desktop Manager Program.) Close any windows that show up by clicking on the X in the upper right corner of the window.
  4. Look in the upper left corner and click Applications. You can use this menu item to reach just about anything you need to use. In the Favorites list which appears, click Terminal. You will now see a window whose title includes your login, machine name (login-name@vegetable-name) and current directory location (~, which means your home directory, /home/student/login-name). The cursor should appear to the right of a prompt which looks like: "[login-name@vegetable-name~]$".

Logging Out

When you are finished working on a computer you must log out. For security reasons, we recommend you do NOT use the "Switch User" option. Failure to log out properly will potentially result in other students gaining access to your account.

First, close all browsers and application programs currently running. Logging out while certain applications are running can leave them running even after you log out, tying up resources and leaving a potential security risk.

Click on your name (found in the upper right corner of the screen). Select the option, "Log out". Another dialogue box will appear, from which you can confirm that you want to log out. DO NOT shut the machine down; others may be using it remotely.

Working in X Windows and Linux

The computer science lab machines run the Linux operating system, a variant of UNIX. X Windows runs on top of Linux, giving us windows and menus in which to work. A desktop manager named Gnome runs on top of the X Windows server. Various window managers also work in the background. Your account has already been set up to run a window manager.

Linux Commands

This section summarizes a few of the basics of working within Linux. Linux commands are typed into an xterm (a terminal window). To open an xterm you can click Applications-Favorites-Terminal (as described above). A window will open with a prompt that looks something like
[smith@cabbage~]$
where smith is your login name and cabbage is the name of the machine at which you are working.

Linux commands are case sensitive. Most commands are typed in all lower case, but make certain you type them exactly as they appear below.

Linux Printing Commands

  1. lp prints a copy of a file to the printer.
    lp LabOne.java prints the file LabOne.java to the printer. It prints one logical page per physical sheet of paper.
  2. To submit your assignments, you will NOT need to give a printout to your instructor. You will upload a copy of your .java file(s) to Canvas. However, if you wish to print for your own review, we recommend printing files through BlueJ. BlueJ also allows you to print 2 logical pages on one physical sheet of paper (used to save paper while work is in progress). Most applications (like BlueJ, mentioned earlier) have a print command in their menu system. This is generally the easiest way to print.

    Warning!
    Do not print binary files. In particular, do not print files with a .class extension. The results are unpredictable, including possibly printing hundreds of pages and/or hanging the printer.

  3. lpq displays the jobs currently waiting in the print queue. You can see if your file is still waiting to be printed.

  4.  
  5. Most applications (like BlueJ, mentioned earlier) have a print command in their menu system. This is generally the easiest way to print.

Submitting a Programming Assignment Electronically (two required ways)

Each programming assignment (not labs) must be submitted in two ways:
  1. Submit your projects through a BlueJ menu option. You MUST be running BlueJ in our lab to do the submission; it does NOT work with your home computer BlueJ installation. This process copies your BlueJ project, and all its files, into a directory that your instructor uses for grading.
    Each submission is time-stamped so that we will know it has arrived on time. From here, your instructor can compile your program(s) as well as run it/them with test data.
  2. Upload each .java (source file) you create/modify to Canvas. Your instructor can write comments on this copy and assign points.
  3. If, after submitting a project, you discover that you want to change what you have submitted, you may simply submit through the menu option again. The earlier version(s) of your program(s) will be replaced by the new version(s).

Using a USB Storage Device

Many students use USB storage devices to transfer files between computers. These are also called flash memory or pen or jump drives. In our lab, these drives must be mounted and unmounted on the machines in order to access them underneath the root directory.

To begin:

  1. Insert the USB device on the front of the computer underneath the table.
  2. After a brief delay, a window will appear listing the contents of this device. An icon for the device will also appear on your desktop.
  3. Stored files will be found inside a directory at:
    /media
    The name of the directory where the files are located depends on the brand name of your flash drive. For example, if the brand is Kingston, you might find the files at this location:
    /media/KINGSTON/*
    These files can be accessed with normal Linux commands like cd, ls, cp, etc.

When finished, you will need to remove the device using these steps:

  1. Close any windows displaying the contents of the device.
  2. Right-click on the device's icon and choose Eject Volume.
  3. Unplug the device from the cable before logging out and turning off the monitor.

Other Useful Linux Commands

    Although a Linux command exists to change your password, it is easier do so by opening a browser and navigating to:
    https://www.cs.uwp.edu/account/activate  Follow the directions on the screen.

  1. who tells you who is currently logged onto the system.

  2. ps -u tells you the status of all your active processes (i.e., the programs that are running on the machine in front of you).
    Here is sample output from ps -u:
     USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    hansen 26902 0.0 0.1 1740 988 pts/8 S 13:00 0:00 -bash
    hansen 26963 0.1 1.0 8192 5296 pts/8 S 13:01 0:05 emacs -font 10x20
    hansen 28737 0.0 0.1 2324 688 pts/8 R 13:49 0:00 ps -u
    Professor Hansen has three processes running: a command shell (bash), an editor (emacs) and the ps command. The first two are stopped. The status of the last one is running. The PID (Process ID) column tells you the unique number assigned to each process.

  3. kill -9 PID kills processes.
    kill -9 26963 will kill the emacs session that Professor Hansen is running.

    Warning! Use kill judiciously. There is almost always a more natural way to terminate a program. Only use kill when a program is so hung there is no other alternative.

Sending Labs to Your Partner's Account

During lab each week, you will be working with a partner, and programs you create during lab time will be saved in only one of the two accounts. At the end of lab, the other person may also want to have a copy of these program files. Because account access is protected, you cannot directly copy files from one student's account to another's.

For the following instructions, the student currently logged in will be referred to as "Student1", and the student who will receive a copy of the files will be referred to as "Student2". We will assume you want to copy all the files in the Lab01 directory. So that only one file need be transferred, the first part of these instructions explain how to create a zip file:

Student1:

  1. Make certain you are in the directory that contains the Lab01 directory. You may need to cd to the proper level (to go up one level, type cd ..).
  2. Enter one of these commands: This creates a zip (compressed) file containing all of the Lab01 directory contents, including any subdirectories that might exist. For security reasons, our campus email does not allow .zip files to be attached to email messages. If you wish to use RangerMail, you should name your file with the slightly different file extension (zipp). You'll rename it later.

Here are two sets of instructions (you can use either one) to transfer this zipped file to Student2. The first way is by attaching the file to an email message, and the second way is by using secure file transfer protocol (sftp).

  1. The following instructions use the campus RangerMail program as the email client (program). Very similar directions apply if you use a different email server such as yahoo or hotmail. This method of file transfer is handy if Student2 wishes to get a copy of the lab files on their home computer. It is also a good way to send files to yourself to retrieve at home.

    1. Using Firefox, go to the UWP Logins page and log into RangerMail.
    2. Choose to send a new message.
    3. Enter your partner's email address in the To box.
    4. Type "Lab01 Files" in the Subject box.
    5. Look for the "Attach files" button (with the paper clip) above the "From:" field. Choose Browse and navigate to your Lab01.zipp file, and click Open.
    6. Important! You must click the Attach button.
    7. Click the Send button.
    8. Log out of RangerMail.

    To receive the lab files, Student2 should follow the procedure below:

    1. Log in to any lab machine.
    2. Using Firefox, go to the UWP Logins page and log into RangerMail.
    3. Select the message containing the attachment.
    4. On the Parts line you should see Lab01.zipp. Click on it.
    5. A window will appear asking if you want to save the file. Make certain "Save to Disk" is selected, then either save to your desktop (the default) or click on the Desktop button to navigate to the location where you wish to save the file.
    6. Rename the ".zipp" file as ".zip".
    7. Log out of RangerMail and close Firefox.

  2. The two students can also use secure file transfer protocol to transfer the zipped file directly into another lab account.
    1. Assume that the two lab partners are working on the machine named radish. Student1 types the following command on his/her machine:
      sftp student2@radish.cs.uwp.edu
      note: this assumes student2 is the person's login name
    2. A prompt will appear asking for Student2's password. Student2 should type this in, then press Enter.
    3. The terminal window doesn't look quite the same as a normal terminal window, but Student2 can still use Linux commands such as cd, ls, etc. to go to the location where she wants the copied file to be placed.
    4. Student2 then types
      put Lab01.zip
    5. The zipped file will then be placed in the proper location. Student2 is still logged in to her account at this time.
    6. Student2 should type exit to stop running sftp and return the machine to Student1's account.

Student2 should log in as usual to her account, then:

  1. In a terminal window, cd to the directory where you saved the Lab01.zip file.
  2. Type the command unzip Lab01.zip to unzip the file.

Beyond the Basics

The goal of CSCI-241 is to teach you the fundamentals of object-oriented computer programming. These fundamentals apply regardless of the type of machine, operating system or object-oriented language you choose. To accomplish this we will use the Java programming language and an integrated development environment (IDE) named BlueJ. The remainder of this document introduces you to each of these.

BlueJ

BlueJ, like other IDEs, provides the user with many tools for developing Java programs including an editor, access to the compiler and a debugger. There are many other IDEs available for Java including Eclipse (originally created by IBM, but now a non-profit open source foundation), Forte, NetBeans (both by Sun), JBuilder (by Borland) and CodeWarrior (included with some textbooks). BlueJ was designed particularly for students just beginning to learn object-oriented programming using Java.

You'll use BlueJ in the very first lab.