Laboratory 0: Linux, Java, and CodeLab
September 5-6, 2007
Objectives
The objectives of this laboratory are
- to become familiar with the Linux operating system,
- to gain practice editing, compiling, running and revising a Java
application,
- to learn how to use CodeLab.
Pair Programming
Throughout the semester we will be using an instructional technique called
pairs programming. Except for graded labs, you will be assigned a partner
at the beginning of lab and you will work in pairs throughout the entire lab,
switching roles as instructed during the lab.
- Locate your partner and introduce yourself
- Select one person to start as "driver". This person will type at the keyboard until the directions tell you to change.
Part 1. Logging into the Linux System
Linux is an operating system similar to the Windows operating
system. An operating system is the software that allows humans to
interact with the computer hardware. The operating system manages the
software tools such as text editor, email, web brower, etc. One of the
main differences between Linux and Windows is that Linux is an
open-source operating system published under the GNU Public License
which means that it is free. In addition, Linux has some speed and
security benefits over Windows. Because of
Linux's speed and stability, it has steadily been gaining market share
in the business and scientific communities.
The Linux operating system can be configured to present a variety of
different interfaces. The interface that we will be using is
KDE. You will only need to select the interface once. In
order to set KDE as your default interface:
- Right click on the Session link at the bottom left of the screen
- Check the KDE session box
- Click Change Session
To use Linux, you must first identify yourself to the system. This is
done so that the system knows who you are, what permissions you have,
and what your preferences are. To identify who you are, you have a
username. You also have a password, so no one else can
pretend to be you. When you start Linux, you will see a
prompt --i.e., a request from the computer for some information.
Your Linux login and password are your Trinity login name and password
(the ones you use to access web mail). At the prompt for login,
you should enter your Linux username and press Enter. When the
system requests your password, enter your Linux password and
press Enter. If you type your username or password
incorrectly, you will have to start this over.
Desktop Settings Wizard. If this is the first time you login
to KDE, the KDE Desktop Wizard will run. Run the wizard. The only
settings you need to change from the defaults are the country
and language settings on the first page. Both should be U.S.
Once you have logged in correctly, you should then see the KDE
desktop.
The KDE Desktop Environment
KDE is a network desktop environment for Unix/Linux
workstations. It fills the need for an easy to use desktop for
Unix/Linux workstations, similar to the desktop environments found
under the Mac OS or Microsoft Windows. The main ways of accomplishing
tasks using KDE are either by clicking on the KDE icon panel at the
bottom left of the screen, or by selecting tools from the KDE menu
(which is reached via the KDE icon panel). The KDE panel and menu are
shown below:
The panel icons provide the following functionality:
- The gear icon with the superimposed K displays the menu.
- The pencil and paper icon provides a quick way to show the desktop.
- The house icon provides quick access to your home directory with all
subdirectories.
- The globe with spikes icon launches the Konquerer web browser (which we won't use).
- The envelope icon launches the Kmail mail client
- The red and white life ring launchs KDE help.
Part 2. Starting the IceWeasel Browser
IceWeasel is a web browser for the Linux operating system and
is equivalent to Mozilla Firefox which you may be familiar with
on Windows. IceWeasel is a robust browser that is safer than most
other browsers and is quite speedy. To start IceWeasel, click the
Start Application icon (which looks like a gear with a large
"K" superimposed on it) on the lower left corner of the
KDE panel and then select Internet -> IceWeasel web browser.
To see the CPSC-115 homepage, type the following URL in the address box.
http://www.cs.trincoll.edu/~ram/cpsc115/
From there, navigate to Lab 0.
Part 3. Creating Directories
Much information used by computers is stored in files. A file is a
collection of information that is stored under a name. Files on the
computer can be thought of as similar to manila files in the
traditional office environment. Files may be collected into
directories which are collections of files. Files are typically
represented with a file-folder type icon. Directories may contain
files and/or other directories, while files may not contain other
files or directories. Directories are organized into a hierarchical
structure. An example of one possible directory structure:
On a networked file system such as we have in lab, everyone does not
have their own disk. Instead, each user has their own home
space. This home is the directory into which the user is placed when
they log into the system and is typically a directory labeled with the
user name. Each user may create files and directories only within
their own home directory. To create a directory for
holding information related to the CPSC-115 course within your home
directory:
- Click the Personal Files icon (which looks like a house) on the KDE panel. This will open the file manager window in your home directory:
- Once you have the file manager window displayed,
right-click anywhere inside the window and then select
Create New -> Folder. Name the new folder cpsc115
(all lowercase). Remember how to find this folder because you
are going to need it.
Now that you have created your own directory, you must change the
permissions so that no one else may access your files. This will
ensure that your CPSC-115 files remain secure by setting access
permissions on the cpsc115 directory. To see permission
information (and more) of a file/directory, right-click on the
file/folder, select Properties (it may take a minute or two for
the Properties window to appear), and then click the
Permissions tab.
Now, change the access permission of the cpsc115 directory as
follows:
- Right-click on the cpsc115 folder.
- Select Properties option. This will open a window allowing you to modify various properties of the directory:
- Select the Permissions tab.
- Select the Advanced Permissions button. This will open a
window that shows various classes of users (Owner (yourself), Owning
Group, and Others). It may take a while for the window to
appear. Checking and unchecking various options allows or disallows
other people from accessing your directory:
- For the Owner class, leave all options checked.
- For the Owning Group class, uncheck all options.
- For the Others class, uncheck all options.
- Click OK in the advanced permissions window.
- Click OK in the properties window. You may see an error message with the heading Konquerer. Do not worry about this. Simply click OK.
- Close the file manager by clicking on the "X" in the upper, right corner.
Throughout the term, you should maintain the access permission of the
cpsc115 directory as above so that no one besides you can access your files.
Pair Programming: Change drivers and repeat parts 1 through 3
above using the other person's account. To log off KDE, right click on
the desktop and select "Logoff".
Part 4. The KWrite text editor
Create a directory named lab0 inside your cpsc115
directory to store the files you will create in today's lab.
KWrite is a simple text editor, with syntax highlighting,
dynamic word wrap and more. Launch KWrite by clicking the
Start Application icon (which looks like a gear) on the
KDE panel and then selecting
Debian->Apps->Editors -> KWrite. Now, perform the following.
- Enter both partners' names at the top of the file.
- Save the file to your cpsc115/lab0 folder by selecting File/Save and indicating your cpsc115/lab0 folder in the folder chooser window. Name the file lab0.txt.
- Close the file by clicking in the upper left corner of the KWrite window or selecting File->Exit
As computers become indispensable in everyday life, it is very
important to be aware of ethical issues surrounding computer
usage. In your lab0.txt file, give a computer-based example
of each of the following unethical behaviors:
- breaking into a room or office,
- going through someone's desk,
- vandalism,
- harrassment,
- plagiarizing.
Then save and print your file. You will be using KWrite to record your
work in future labs. Feel free to explore the features of the editor.
Part 5. Compiling and Running the HelloWorld.java Application
Download the HelloWorld.java program by clicking on its
link and then using the browser's SaveAs menu
to save the file in your lab0 directory.
To compile and run HelloWorld.java, open a terminal window by
selecting Programs->System->Terminal Program (Konsole) (you may
also click the Terminal Program icon (which looks like a
monitor) if present in the KDE panel). When the terminal window opens
and the ~$ prompt appears, use the following commands to
compile and run the HelloWorld.java application.
- cd - This command changes the working directory to the one
specified. Set the working directory to cpsc115/lab0 by entering the
following.
cd cpsc115/lab0
- javac - This command compiles the application into Java bytecode
and then save the compiled file with the .class extension.
Compile your Java source file by entering the following.
javac HelloWorld.java
- java - This command interprets the Java bytecode of a compiled
file and produces an output. Run your program by entering the following.
java HelloWorld
As a result, something like the following should appear on your desktop.
Part 6. Editing and Re-running the HelloWorld.java application
Next, perform the following.
- Open the source code HelloWorld.java by clicking anywhere
inside the KWrite window. The program contains the following code:
private String greeting = "Hello World!";
Change "Hello World!" to some other message by editing the
above statement. Select
File -> Save to save the updated file. Re-run the program and
observe the change in its behavior.
- Notice that the name of the class in HelloWorld.java is
HelloWorld. The rule in Java is that the Java source file must
have exactly the same name as the class the file contains.
Change the name of the class in HelloWorld.java to
HelloMoon, save the updated file, and then try to re-run
the program.
A system error will occur when Java tries to load the
HelloMoon class into memory but cannot find it. You can
fix this error by changing the class's name back to HelloWorld.
Save the updated file and re-run the program.
- A syntax error is an error generated by the compiler when it
cannot correctly parse (translate) your source program. There are lots of ways to
generate a syntax error: misspelling Java keywords, forgetting to declare a
variable before using it, misspelling a previously declared identifier, even
forgetting a semicolon at the end of a statement, etc.
Delete the semicolon after the statement that begins System.out.println() and
then re-run the program.
This time you should get an error message:
HelloWorld.java:6: ';' expected
}
^
1 error
Replace the semicolon and run your program again.
Pair Programming: Change drivers and repeat parts 4 through 6
above using the other person's account.
Part 7. Using CodeLab
As part of the CPSC-115 course, you will be required to complete some
exercises using a web-based interactive application. In each CodeLab
exercise, you will be asked to complete a small task and type the
answer in the provided answer area. Once you have pressed the
Submit button, the CodeLab system will judge the correctness of
your answer and will offer hints if the correct answer is not
provided. CodeLab exercises must be completed by the due date, but you
can provide multiple answers to each exercise until the right answer
is entered (provided that this is done before the deadline).
The CodeLab site is located at
http://www.turingscraft.com/
NOTE: If CodeLab does not load properly on your workstation,
it may be necessary to install a Flash plugin for your browser.
To do so, type the following command at the prompt in a Terminal
window and just follow the instructions::
/home/cpsc115/flashplayer/flashplayer-installer
In order to access the CodeLab system, you must register:
- Open the IceWeasel browser and enter the URL: http://www.turingscraft.com/.
- Select the register link in the upper right-hand portion of the screen.
- Select "I am a student in a course using CodeLab" radio button and hit Continue.
- Enter the course access code of TRICOL-6489-2630 and hit Continue.
- Select Trinity C. from the dropdown menu and hit Continue.
- Enter your email address and hit Continue. This must be a valid email address.
- Enter your name and hit Continue.
- Enter a password and hit Continue.
At this point you can now access the system. In order to familiarize yourself with CodeLab, you will complete a few CodeLab exercises:
- Go to the main CodeLab site: http://www.turingscraft.com/.
- Select the login link in the upper middle of the screen. This will bring you to the login page.
- Enter your CodeLab username and password and hit Go. This will bring you to the main CodeLab interface. You should see a workspace similar to the following. Your view will not have the INBOX nor BASEMENT options.
- Expand the JAVA, JAVA, JAVA section by clicking on the plus sign (+) in front of the JAVA, JAVA, JAVA heading. The JAVA, JAVA, JAVA section should now contain at least two subsections, the first of which is Intro to CodeLab.
- Expand the Intro to CodeLab section by clicking on the plus sign (+) in front of the Intro to CodeLab heading. This should result in the display of two exercises, labeled 20501 and 20502, under the Intro to CodeLab heading.
- Select the first exercise (20501) by clicking on the 20501 link. YOu should have a screen that looks like:
- Type your answer in the text area located below the Submit button and press the Submit button. If your answer was correct, you will received a green correct message and the box before exercise 20501 will turn green. If your answer was incorrect, you will recieve a red error message that includes hints about how to solve the problem and the box before exercise 20501 will turn red.
- Complete exercises 20501 and 20502 until you are comfortable with the interface.
- To leave CodeLab, select Exit from the main menu across the top of the screen.
Pair Programming: Change drivers and repeat part 7
using the other person's account.
On Your Own Time
Linux is an open-source operating system that is built on the well-known
UNIX operating system, the most popular command-line based operating
system for workstations and multi-user servers. So, most Linux commands
(including all the commands you learned today) are actually UNIX commands.
Familiarize yourself with more basic UNIX commands, by reading "Introduction to the UNIX operating system" in the UNIX Tutorial
for Beginners available at
http://www.cs.trincoll.edu/~pyoon/unixtut/
and complete Tutorials 1 and 2.
What to hand in
Make sure to write your name and laboratory section (Wednesday or
Thursday) in a comment within the HelloWorld.java file.
Save your work. Upon completion of your laboratory exercises, have your work checked by the laboratory instructor or TA. Turn in a printout of your
HelloWorld.java file.
You're done. Great work!