Colorado State University

Recitation R2 - Linux and Java Expressions
Spring 2014

CS160: Foundations in Programming


The purpose of this lab is to learn about the Linux operating system and to write more Java code:

Linux File System

Your GTA will describe the hierarchical file system used in Linux. Make sure you know what each of the following identify:
~
.
..
/
current directory
home directory
file extensions


Useful Terminal Commands

Your TA will show you how to use the "man" command. For each of the following, write down what action is performed.

man
pwd, ls, cd
cp, mv, rm
mkdir, rmdir
cat, diff, less
Launching programs from a terminal: &

Your TA will show you how to look at the history of commands, how to recall previous commands, and how to search the history buffer, and how to edit recalled commands. In addition, you will learn how auto completion works.


Text Files

Perform the following actions:
  1. Use gedit to create the Name.txt: gedit Name.txt &
  2. The file should contain one line which has your first and last name.
  3. Save the file.
  4. Copy Name.txt to another file called Name.bak.
  5. Compare the contents of the two files using the diff command. Are they the same?
  6. Open Name.bak as a second tab in gedit.
  7. Add a second line to Name.bak with your student ID.
  8. Compare the two files again. Are they the same?
  9. Remove Name.txt.
  10. Move Name.bak to Name.txt.
  11. Cat the contents of Name.txt. Is your student ID present?

Java Programming

Create a new Java Project named R2, and make a class named R2. Your GTA will help you to print out the values of the following mathematical expressions: NOTE: Remember to use System.out.println( ) to print out the values of the expressions.

Initially you can use numeric constants in the print statements, but before you complete the program add the integer and double variables and use them in the computation. For example:

int var1 = 12;
int var2 = 7;
double var3 = 7.0;
double var4 = 12.0;


In a comment block at the bottom of your program, answer the following questions:
  1. Explain the difference (or lack of it) in the result of 12 / 7, 12.0 / 7.0 and 12.0 / 7.
  2. Explain the difference (or lack of it) in the result of 3 - 7 * 6 and (3 - 7) * 6.
  3. Explain the result of 0.1 + 0.2 - 0.3

Show your R2.java program to the TA for grading and submit it to the RamCT drop box to get credit for this lab.

© 2014 CS160 Colorado State University. All Rights Reserved.