CSCI161: Introduction to Programming I

Spring 2008

Programming Environment: Linux and Eclipse (lab1a)

 


Goals
- to become acquainted with the Linux/Gnome environment
- to learn how to turn in assignments using submit
- to give instructor contact information

Overview
For this lab, you will login to a workstation running Linux/Gnome with your personal account. You will arrange your screen so that you have a terminal window as shown below. You will create a folder for storing your work for this course and then create a small text file containing some basic contact information. You will save that file and submit it to your professor much as you would submit an assignment for grading. These steps are detailed below. Each step is summarized in bold and then described in more detail.

 

In the second part of this lab, you will type in a Java program and learn to use the Eclipse Integrated Development Environment (IDE). Finally, you will create a second small Java program on your own but based on the previous one. Together, the three submitted documents will be graded and will count as a regular assignment.

How to Use the Linux/Gnome Environment

Log in: You should see a login panel asking for your user id. Type your user id (first initial, middle initial, your whole last name). Press tab to move to the password field. Type your password (first and last initials and last 4 digits of your student ID) using the number keys above the letters and not the numeric keypad. You won't see your password on the screen. Press enter to login. You should see the word 'fedora' in a startup message as your desktop is initialized. Note that your email address is  userid@cs.millersville.edu

Open Terminal: Although overall this is a graphical interface, you can interact with the system by typing commands. If you connect to the lab machines over the Internet, you will use a similar terminal interface with typed commands.

Click the Terminal icon on the upper tool bar/launcher panel (see figure above).

You will type commands in this window. If you wish to adjust its size, drag the lower right corner. Many of the mouse gestures work the same under Linux as in Microsoft Windows.

Change Your Password: Anyone who knows you well can guess your password. You should change it to something you will remember but is not guessable. It should not be a word, should contain a non-alphabetic symbol in the first 6 characters, and should be at least six characters long. Upper and lower case are significant. Think about it before you change it. It is non-trivial to fix a forgotten password, so make it something you'll remember and won't mistype. Do not type password numbers with the numeric keypad.

To change your password, type yppasswd in the terminal. You'll type your old (given) password, the new password, and then the new password again to make sure you have it right. What you type is invisible here.

Create and Open 161 Directory: In the terminal, type mkdir 161. This will create a new directory (folder) named ‘161’ in your home directory (/home/students/<userid>).  Now type ls (for ‘list directory contents’) and you will see your new directory in the list.

You will create and modify your programs for this class in your 161 directory.

Move to 161 Directory in Terminal: The current directory is displayed as part of your terminal prompt,
  userid@machine:<working directory>$

The terminal starts at your home directory every time you start a terminal session or login. You can tell you’re in your home directory when the prompt has a ‘~’ (tilde) as the working directory (between the colon and the dollar sign). 

In order to work with your files for this class in the terminal, you must make sure that the terminal's working directory is 161. Do this by typing cd 161 (for ‘change directory’) at the prompt. You can check what the current working directory is by typing pwd or looking at your prompt. The output of pwd should be ‘/home/students/<userid>/161’.  Note the ‘161’ on the end.

Create Information File: We will be using the Eclipse integrated development environment (IDE) in this class. To open Eclipse, type eclipse & in the terminal window. The & (ampersand) instructs the operating system (in this case, fedora Linux) to run Eclipse in the background, leaving the terminal free for new commands.  Alternatively, you could click on the Eclipse icon in the upper tool bar/launcher panel (the purple icon – see figure above).

Eclipse will display a window asking for your workspace directory (see figure above).  Delete the word ‘workspace’ and replace it with ‘161’.  The workspace directory should now be ‘/home/students/<userid>/161’.  Click on the box below which asks if you want to use this as your default workspace directory so that this window is not displayed each time that you open Eclipse.

Create a new Eclipse project by selecting File-> New -> Java Project.  Type ‘Lab_1’ as the Project Name. In the Project layout portion of the panel, click the Configure Default link. On the new panel, Click the Project button under Source and output folder. Click Apply. Click OK. Select the Use project folder as root for sources and class files button. Note that these settings should now be the default for future projects so you will not have to repeat this. But it is a good idea to check to see that this button is correctly selected each time. Finish the project creation by clicking the Finish button at the bottom of the window.

The first time you use Eclipse, it typically starts up with it’s Welcome window displayed (see the figure below).  Each of the icons in this window give you an introduction to some part of the Eclipse system, except the one on the far right that looks like a downward-turning arrow.

 

That rightmost icon of the arrow will launch the Workbench.  Go ahead and click on that.  Your window should now look like this:

 

Now, create a new text file by selecting File -> New -> Untitled Text File from the Eclipse menu.  This will create a blank text file that will be opened in an editor pane (called ‘Untitled 1’) in the middle of the Eclipse workbench.  Your cursor will automatically move to the top of the blank editor pane.

Type your name, your phone number, and a short description of why you are taking this class (one or two sentences). Proofread your typing. You can use the mouse to move around.

Save the file using File -> Save As to save and name your file.  Select ‘Lab_1’ in the white middle pane so that it is displayed as the parent folder.  Enter ‘myinfo.txt’ as the File name. Be sure to include the .txt extension.  Click the ‘ok’ button.

Go back to your terminal window (if you closed it earlier, open a new terminal by clicking the icon in the tool bar/launcher panel).  In the terminal window, verify that you are in the 161 directory (type cd 161 if you’re not).  Type ls and you will see your new Lab_1 project directory, which will contain any files associated with the project.  Type cd Lab_1 to enter the Lab_1 directory.  Type ls again and you will see your ‘myinfo.txt’ file.

To display the contents of your myinfo.txt file, type cat myinfo.txt. You could also type part of the file name (as in cat my) and then hit the TAB key to complete the file name. 

Submit your File: For this course and many others in the CS department at Millersville, you will turn in assignments by using a program called submit. This program copies the specified file or directory, usually your project directory, to a special account set up for your course. The account's name will be your professor's last name and the course number. Only that account's owner can see the submitted file(s). If you revise your project or program, you can submit it again. The most recently submitted version is graded, but the older versions are still available for the grader's review. You must be in the folder containing the file(s) you want to turn in. Always make sure you have saved your file(s) before running the submit program.

In the terminal, get a long file listing by typing ls -l (that is the letter ‘el’ -- not the digit ‘one,’ and there is a space after the ls). This should show that you have a file called myinfo.txt and that it is bigger than 0 characters. The listing below shows a file 239 characters long and last changed at 6:20pm.

   -rw-r--r-- 1 sabeach student 239 2005-01-12 18:20 myinfo.txt

Type submit. Type hutchens161 or webster161 (depending on your professor!) to indicate the appropriate grader account. You will be asked which lab you are submitting. Type lab1a. That lab is accepting files ending in .txt. You should now see a message saying that ‘These files will be submitted to grader hutchens161 (or webster161) as lab lab1a followed by the filename ‘myinfo.txt.’  Enter ‘y’ to indicate that this is okay.  If you get a message saying that you have no files to submit, check the name of your myinfo file and rename it to end in .txt.  You can rename a file with mv oldFilename newFilename  (where mv stands for ‘move’).

You should receive a message stating that myinfo.txt has been submitted to the appropriate grader account and lab.

When you get back to a prompt, type submitlog to see a record of what you submitted.

Check your Email: The best way for you to check your email is through the web. Open the Firefox web browser by choosing Applications -> Internet-> Firefox Web Browser from your desktop menu (you can also click the web browser icon in the tool bar/launcher panel at the top of the screen). Note that your email on cs (our server) is not the same as your marauder email. The address for SquirrelMail on cs is

   https://cs.millersville.edu/webmail/src/login.php

or you can go to the main cs page (http://cs.millersville.edu) and click the MUCS OpenWebMail button.  Use your cs userid and password. If you wish to forward your email to an email account that you check regularly, click on options, then Mail Forwarding, and then complete the information on the form. Be sure to check that the forwarding works as you expect by sending your account an email message. You can always check mail here, so it is not necessary to forward the mail anywhere else.


 



Practice Some Terminal Commands: Learning a few terminal (Unix bash shell) commands will make it easier for you to use the system. You'll learn these commands as time goes by. If you are connecting to these machines from outside the lab, you will get a terminal when you connect.

In the terminal, type the commands in the left column. The right column describes what you are doing.

When you complete that series of commands, you should be back at your 161 folder. If not, figure out how to get there. Remember that you always need to move the terminal into ~/161 to work on files for this course.

Command

Meaning

cd

move to your home folder (~sabeach)

pwd

print the current directory name

ls

list files in home (161 should be there)

ls -l

list files, last time changed, size, and permissions

cd 161

move into 161 folder

cd ..

move one folder up file hierarchy

!p

repeat most recent command that started with p (pwd)

cd 161

move into 161 folder

!!

repeat previous command (this gives you an error message because there is no ~/161/161)

man pwd

print manual for 'pwd' command; press spacebar to get next page if necessary; press 'q' to quit

 


This picture shows the file system for a student with userid sabeach.
Her home directory is ~sabeach (or the full path, /home/students/sabeach) with two subdirectories, 140 and 161.

Log Out: From the menu at the top of the screen, choose System -> Log Out userid. You will be asked to confirm; click the ‘Log Out’ button. You are logged out when you see the login panel on the screen. Normally, before you leave the lab, you should log out this way. Save any work before logging out.

You'll login again to start the next part of the lab activity.

Further Exploration: There are many ways to learn about the system and get help. Explore these outside the lab time:
- explore the Help menu
- use Applications/Internet/Mozilla FireFox to get a web browser and visit Java sites on the Internet.