CSC15 Assignment 1: Unix and Javac

Due Thursday, 9/10/03


This lab is intended for you to:
  1. Learn basic Unix "survival skills"
  2. Set up the environment you will use for the rest of the semester
  3. Learn how to enter and compile a couple of basic Java programs.
  4. Take a glimpse at the joys and pains of programming by modifying some simple program lines.


Unix is an advanced operating system that predates Microsoft windows by many years. It is used by scientists, software developers, compute science researchers, and is the backbone of most internet resources. It is not as easy to use as Microsoft Windows but is more powerful, especially when it comes to computer networking. The version of Unix we will be using this semester is "Solaris", which runs on Sun workstations in Adams 204.

Unix has improved in usability in recent years. In particular, there are now "graphical user interfaces" available. When you log into your account, you'll see a graphical desktop called "CDE" - for "common desktop environment". This environment behaves somewhat differently from that of Microsoft Windows - be sure you follow the demonstration and note its peculiarities. You'll be required to familiarize yourself with this environment after some initial instruction.

To log in to the Solaris Workstations, first select "options" on the log in screen, then select "session" and then "common desktop environment(CDE)". Then type in your username. Your username should be the first character of your first name plus up to 5 characters of your last name, plus a number (usually 1). For example, if you are Jane Smith your username would probably be jsmith1. But if there's another Jane Smith on campus you might be jsmith2. Your password is initially set to your social security number.

When you first log on, you'll see a number of windows come up. The one that's important is called "file manager". You can quit/destroy the other ones. The file manager displays files in your directory.

The unix file system is similar to the file system of DOS and Windows 98, but there are some important differences. First of all, there is no "A" drive or "C" drive. Instead, there is a "root" directory called "/" and all directories are arranged in a hierarchy. Your "home" directory is displayed in the file manager - it should be something like /home/jsmith. Note that the "/" is in the opposite direction of MS Windows directory names, which uses "\" just to be original.

Here's a basic tutorial. If at anytime you're stuck and couldn't figure out what to do, start over by opening a new terminal from the "file manager" window. If you don't see a file manager window, right click on the background, select files, then select file manager.

  1. Click on the "file" tab in the file manager and select "open terminal". You see a window with a "%" prompt pop up. This is the equivalent of the DOS command prompt in MS Windows.
  2. Click on the terminal window and type "tcsh" - I won't explain what this is right now - just do it. This should always be the command you type first when a new "terminal" comes up. If "tcsh" doesn't work, type "csh".
  3. Type "pwd" - this command shows you what directory you're currently in.
  4. Type "ls" - this command shows the contents of the current directory - don't be surprised if there's nothing there - that's why we're here! As you might have guessed, "ls" corresponds to "dir" in DOS.
  5. Type "ls -a" - As with MS Windows, there are some hidden systems files that are not usually visible. This command will display all files and directories in the current directory.
  6. Type "ls -l" - This is the same as ls but gives you additional information for each file and folder.
  7. Type "netscape &" - guess what this does! Go to the CSC15 class webpage at http://www.cs.hofstra.edu/~cscccl/csc15/. If the netscape command doesn't work, see the instructions for remote login at the end of this document.
  8. Download the file ".cshrc" from the homepage. This is a configuration file that sets up your account (similar to autoexec.bat on old Windows). Make sure it's saved in your home directory.
  9. These files should now be in your home directory. Type cd followed by ls to verify this. (it must be in your home directory)
  10. Now it's time to learn some more basic commands:
    Basic Command Summary
    1. cd (directory name): change directory to named directory
      cd .. : go to parent directory
      cd /(path) : absolute directories begin with "/", the root directory.
      For example, if you are in directory /shared/csc/local, typing "cd .." will take you to the /shared/csc directory.
    2. Typing "cd" by itself will take you to your home directory.
    3. pwd : tells you the current directory you're in.
    4. cp file1 file2 : copies the contents of file1 into a file called file2.
    5. ls : lists directory contents
    6. mkdir dirname : creates a new directory called dirname in the current directory
    7. mv file1 file2 : renames file1 into file2
    8. rm file1 : deletes file1
    9. rm -rf dirname : deletes the named directory and all its contents. Use with care!
    10. more filename : a quick way to view the contents of a text file.
    Many of these operations can also be performed using the mouse in the "file manager" window. However, you'll need to learn these commands if you want to use the Sun workstations remotely using telnet (I'll show you how to do that later). Besides, all serious computer users know them!

    Let's now practice these commands (please do not deviate from instructions)
  11. Make sure you're in your home directory (type "cd") and that you've downloaded cshrc into this directory. Please note, however, that any file that begins with ".", such as ".cshrc", are hidden files that don't show up when you type "ls". Type "ls -a" to see all files in your directory.
  12. Type "mkdir csc15" - what does this do? You should creat a directory for this class because you'll be using your account for other classes as well.
  13. Type "cd csc15" - you're now in the directory you created.
  14. Type "cd .." - you're back in the directory you were in before
  15. Log out. (this will put into effect the .cshrc file you downloaded) Right click on a blank part of the screen and select log out.
  16. Log back in, open a new terminal, and type "tcsh" or "csh" - always type this when you open a new terminal.
  17. Go into your csc15 directory (forgot how to do that? look above!)
  18. create a subdirectory inside csc15: "mkdir cs1"
  19. Download the file "Keyboard.class" from the class homepage, and put it into the cs1 directory. For now, the cs1 directory should contain ONLY this file.
  20. get back into your csc15 directory (you can do this from the cs1 directory by typing "cd .." - check above).
  21. Time to write a program.
    To do that you need to learn how to use an editor. A very powerful (though less easy than MS word) editor used by programmers is "xemacs" - type "xemacs &" - you'll see a window come up. (if no window comes up, see the instructions for remote login at the end of this document.) You should recognize a toolbar with familiar buttons such as "file", "edit" and "help". Select "file" and open a file called "firstprog.java"
  22. Type in the first program provided on the first attached sheet. You do not have to type in all the comments marked with //, but put your name in comments at the top.
  23. save it under the name "firstprog.java" in the csc15 directory.
  24. Make sure you're in the csc15 directory. Now you need to "compile the program" by typing "javac firstprog.java". Did you get any errors? If you did, that means you had a typo while copying the program, so go back and edit the program, save it, and try again.
  25. Run the sucessfully compiled program by typeing "java firstprog".
  26. Change the line while "(counter < 10)" to "while (counter < 5)". Recompile and run it again. Congratulations! You're on your way to becomming a real computer geek! (just kidding).
  27. Quit emacs (click the "file" menu option)
  28. You can start emacs and open a file at the same time by typing xemacs (filename) &
  29. Time to write a program with graphics! Start emacs again and copy the second attached program. Save it as "secondprog.java". The compilation procedure is the same for this program.
  30. Run the program with "java secondprog". The window dimensions don't look right. Try experimenting with changing certain lines so that the window is centered in the screen, and the button is centered in the window. The line to look at contains "setBound".

You are to turn in the printouts of the two programs you typed in and modified. Make sure the printouts have your names on it. To print, type (in the same directory where the file resides) print204 filename. This will always print to the lazer printer in Adams 204.

Final Note: you are expected to remember what you learned today, for these skills are required throughout the semester. Practice these skills further on your own time.


Instructions for Remote login :

Some of the machines in Adams 204 are not configured correctly. They do not have some software such as netscape available. For these machines, you need to log in to a remote host instead, effectively making your computer a "thin client". You need to log out first if you are currently logged in. At the log in prompt, select options, then remote login. Select "enter host name" under remote login, and type in "husun3.hofstra.edu". Remember this procedure. Note: to reset the machine to its normal state, select options and choose "return to local host".