Lab 1
Goals:
learn elementary UNIX commands (ls, cd, ps, kill, less, mkdir)
learn to use an UNIX editor (nano, emacs21, vim, etc.)
learn to compile and run Java programs at the command line (javac and java)
learn to download and unzip a .zip file from the web
Task A: Learn Some Elementary UNIX commands
Log-on to the lab machine under Linux using the same user-name and password as last semester. (If the computer is running Windows, you may need to restart the computer.)
Observe the KDE windows interface. In the Linux window, the "K" icon in the lower-left-hand corner of the screen acts similar to the "Start" button under Windows. Some other icons along the bottom of the screen will launch some useful applications:
the teminal-screen-with-sea-shell icon opens an terminal window "shell" where you can issue command-line arguments
the file-folder-with-house icon will show you a GUI view of your "home" directory
the globe-with-something-partially-surrounding-it icon opens the Konqueror web browser
Click on the teminal-screen-with-sea-shell icon to open a shell. Experiment with the following Linux/UNIX command:
Command |
Example |
Description |
ls |
ls |
List the subdirectories and files in the current working directory |
mkdir |
mkdir cs2 |
Creates a new directory named "cs2" |
cd |
cd cs2 |
Change the current working directory to the subdirectory "cs2". Use "cd .." to go up one level in the directory tree. |
emacs21 |
emacs21 Test.java |
Invokes the emacs text-editor using the file called "Test.java" |
less |
less Test.java |
Display the contents of the file "Test.java" on the screen |
javac |
javac Test.java |
Invokes the java compiler on the Test.java file to create the Test.class byte-code file |
java |
java Test |
Executes the Test byte-code file in the Java virtual machine |
mv |
mv src dest |
Renames the file "src" to the file "dest" |
cp |
cp src dest |
Creates a copy of the file "src" in a file called "dest" |
ps |
ps -a |
Show all the processes that are running to find their process ID #'s, PIDs |
kill |
kill -9 123 |
Terminate the process with PID of 123 |
If you have not already done so, create a subdirectory in your home directory called "cs2".
Task B: Using the emacs21 Text Editor
In the shell window, change to the cs2 subdirectory.
Invoke the emacs21 editor by typing "emacs21 Infinite.java" at the shell prompt
In the emac21 window, type in the following Java program
public class Infinite { public static void main( String [] args) { System.out.println("Start of main"); while (true) { } // end while } // end main } // end class Infinite
File | Save (current buffer) (or use the keyboard shortcut ctrl-x followed by ctrl-s)
File | Exit Emacs (or use the keyboard shortcut ctrl-x followed by ctrl-c)
Compile this code using the command: javac Infinite.java
Run the code using the command: java Infinite
Open another terminal shell and look at the processes executing by using the command: ps -a
The processes labeled "java" are from your program (and the JVM) in the infinite loop
You can kill the java program by clicking in the window where you started the program and typing ^c (<ctrl> key and the 'c' key at the same time)
Do another "ps -a" command to see that the "java" processes do not exist any more.
(Alternatively, you could have issued a "kill -9 ###" command with the ### being the actual PID number of one of the "java" processes found by issuing the "ps -a" command.)
Task C: Downloading and unzipping from the course web-page
Using the Konqueror browser, go the course web-page: http://www.cs.uni.edu/~fienup/cs062s06
Click on the MemoPadApp.zip link and "Save to disk" in the cs2 subdirectory.
In a shell window, change to the cs2 subdirectory.
List the files in the directory and look for the file "memoPad.zip".
Decompress the "memoPad.zip" file using the command "unzip memoPad.zip"
Remove all the .class files by using the command "rm *.class"
List the directory to see what files remain
Compile the Java file containing the "main" method by "javac MemoPadApp.java"
List the directory to see what files were created
Run the memo pad application by "java MemoPadApp"
(You may need to grab the lower-right hand corner of the frame and make it bigger to see the text in the textboxes that you type. Strange!)
Examine the code in the MemoPad.java file
Task D: Get the description of Homework #1 and start it!