Tutorial 1: Unix, Emacs, StructureBuilder, JDK


Introduction

This tutorial covers:


I. Unix

  1. register comp212, which will create your own comp212 subdirectory. For this tutorial, further create a tutorials/01 directory, which will contain any (other) files you're asked to create. You will be expected to keep all your comp212 work in this directory. Do NOT modify the permissions on this directory. Doing so may result in 0's on some assignments.

  2. Using man ls, read about a file's permissions. If you own a file with permissions -rw-r--r--, can your friends read it? Can they write to it? Who can get to your comp212 directory?

  3. Read what the following flags to ls do: -l, -A, -F, -t, -d. What are the permissions for your newly-created personal ~/comp212/?

  4. Use cp -p to copy the file silly.txt from comp212's tutorials/ to your directory while still preserving its august timestamp. Verify to yourself, that your copy doesn't have a newer date.

  5. Use chmod to make your copy of silly.txt file readable by yourself only.

  6. Using alias, how would you abbreviate ll to be shorthand for ls -FlAt? (You can use an abbreviation other than ll if you like.)

  7. Make a symbolic link (ln -s) to this tutorial file in your own directory, called unixtutorial.html. What is an advantage and a disadvantage to symbolic links?

  8. If you haven't already, use chsh to change your shell to tcsh (or, anything besides csh or sh). Linux users including myself may be used to bash. This is a one-time task. See /etc/shells for the full pathname of valid shells. If curious, you can see ~ian/.tcshrc for some tcsh-specific customizations.

  9. In your new shell, what key do you press to repeat previous commands?

  10. In your new shell, what key do you press for filename completion?

  11. Does this same key work in emacs, for filename completion?

  12. An unfortunate fact of life is that programs crash. In Unix, you have the option to close these programs without having to reboot or log back in. The command I'm talking about is kill. To use this very powerful command, the computer needs to know just what it is exactly you want dead. This is accomplished by something known as a PID (process identification) number. In Unix, anything that "runs" has a unique number assigned to them. You can find out PIDs using the program top or ps. Once you have the PID of the program you want stopped, you just type kill "PID" ("PID" being the PID of the program you want to kill).

  13. Ok, another cool thing. Do you know how to copy and paste in unix? Well, in case you didn't, try highlighting some text by using the left mouse button. What you just did is the same as the Copy function in Windoze. Now, go to where you want to paste the text and click the Middle button on the mouse. It should automatically paste what was highlighted. This little feature should aid you when you start programming.

  14. redirecting I/O. Read about I/O redirection and piping in the "About Unix Commands" chapter of owlnet's unix handout.

    To do: Use >> to append the output of cal 1752 to your answer file. (See the man page to see why the 1752's calendar is strange).

If much of this material is new to you, don't worry. This tutorial covers much more than you need to know for the course. Of course, if you don't understand something, it is up to you to come to us for help.  For assistance, you can:


II. Emacs

There isn't as much to say about emacs. I'll just say that it is the preferred editor of choice for advanced CS classes. Or course, you are allowed to use any editor you want, but most of us labbies are most familiar with emacs. Emacs has evolved a lot since it's beginnings. Many people say it's a bloated program. It does too much. In the spirit of recursive acronyms, emacs was said to mean "Emacs Makes A Computer Slow." Now, though, emacs works fine on modern machines. It is an amazingly configurable program. In fact, you can even read your email or newsgroup postings and more using just emacs. This part of the tutorial will just cover a few basic things. If you want to learn more, check out the owlnet Unix help pages on emacs.

  1. Now, the most confusing thing for emacs newbies is understanding the notation used for commands. If you check out the Emacs reference card You will see commands like:

    What this notation means is:

    Some other good keyboard commands include:

  2. Emacs isn't perfect though. From personal experience, it can freeze on you sometimes for no apparent reason. Therefore, I suggest you save frequently.

  3. Another cool thing is that for commands, there is also tab-completion. Try opening a file using C-x C-f. If you just type the first couple letters of a file you want and press tab, emacs will try to complete the name of your file when you press Tab. This is good because as computer scientists, we are lazy.

  4. Emacs also has an auto-save feature. If you notice some files that show up in your directory starting with a #, it's one of those files emacs saved for you. In the event of a crash or any other situation where you were forced to exit emacs without saving your work. Emacs has an option to recover the last auto-saved version. Pressing M-x and then typing recover-file will help you get that file back. There are a tremendous number of commands that can follow a M-x. If you forget exactly the one you want, don't forget the tab completion to help you figure out which one you're looking for.

  5. Another feature of emacs lets you change the type and size of fonts and much more. Try holding down the Ctrl key and pressing the left mouse button while emacs has the mouse focus. Now, try holding down shift and the left button. I'll leave it to you to play around with it.

  6. There's a lot more I could talk about but I'll cut the tutorial a little short. I'll just say that if you ever see someone writing code in emacs and it looks really colorful, it's just a configuration. The best part is that you can have all those cool colors too! Talk to one of the labbies about how if you're interested.

III. StructureBuilder

StructureBuilder (SB) is a tool to create UML class diagrams and automatically generating Java stub codes.  It also can reverse engineer Java source/byte code to produce the UML corresponding UML diagrams.  In this lab tutotial, we will use SB to illustrate the design of our Pizza program.  Perform the following steps to create the UML diagrams for the Pizza design below.

pizza.png (7975 bytes)


IV. Compiling and Running a Java program

Go to your directory ~/comp212/tutorials/01 (which you just created). You should have the files PizzaClient.java, Pizza.java, AShape.java, Circle.java and Rectangle.java in this directory (which can be checked by the command ls -al, which lists files: all of them (-a), in the long format (-l).

Compiling from the command line

First compile the file PizzaClient.java by giving the command:

javac PizzaClient.java

Now you can actually start executing the program with the command:

java PizzaClient

You'll see an output that says something about which pizza is a better deal.

Compiling from the inside emacs

There is another more convenient way to run the edit-compile-debug cycle from inside the emacs editor. For an intro to emacs, you can see Owlnet's emacs intro, useful-commands summary, or reference card (html or ps).

Load up the file PizzaClient.java in an Emacs buffer by the command:

C-x C-f PizzaClient.java RET

From within Emacs, give the following command:

M-x compile

or simple type the keystrokes

ESC c

In the minibuffer, Emacs will suggest to you the compile command to use. This should be javac PizzaClient.java, as above. Simply press RET after this. The compilation will begin and the details will be shown in a special Emacs buffer called *compilation*. If there are any errors, they will appear in this buffer. As there are no errors in *.java, the compilation should finish successfully and you should see a message like:

Compilation finished at .....

To run the program, now go to the Unix prompt and as before,

java PizzaClient

and you'll again see the familiar output again.

Warning: if you rename a file, ESC c may suggest the wrong file name. In that case you can edit the file name on the command line before typing RET.

D. X. Nguyen, Aug. 27, 2000.
dxnguyen@cs.rice.edu