CS 201 - Homework 0 - Unix and Java warm-up

Due: Wednesday 2/13 at 8am

This homework will introduce you to our computer lab, some basic Unix commands, a text editor like Atom (or Emacs or vim), how to compile a simple "Hello World" application in Java, and how to submit your code via the course submission script. Each student must complete this homework individually, but you can get as much help as you want, either from other students, or from the lab tutors. Check the course web site for tutor hours.

We recommend that you try to work on our lab machines for HW 0, even if you're planning to work on your own laptop for the rest of the course. But if you want, you can also try to get everything working on your laptop (see below).

  1. Go to the MBH 632 lab and familiarize yourself with the Linux machines. Log in with your usual username and password. (If you cannot log in, see section below.) Once logged in, move the mouse in the upper-left corner to start applications. Two important ones are near the top of the list: "Terminal" and "Web browser". You can also find them in the "dock" at the bottom of the screen, or by right-clicking on the desktop. In the dock (or via Alt-F3) you get the "Application Finder", with which you can search for other applications such as Atom or Emacs. Spend some time exploring the interface, and try to figure out how to start a web browser and the file browswer. If confused, ask other students or the lab tutors.

  2. Go through the CS 201 Unix tutorial. This will teach you how to use basic Unix commands.

    Identify the function of and experiment with these Unix Commands:

    ls        cd        cp        mv        rm        mkdir     pwd
    man       history   cat       more      grep      head      tail
    
    Learn these commands -- you will use them often.

  3. Make a directory cs201 in your Unix account for CS 201 work. Use the Unix command "chmod go-rwx cs201" to make this directory accessible only by you.

  4. Make a subdirectory hw0 in this new directory.

  5. Familiarize yourself with the text editor Atom. You can start Atom from the command line and supply the name of the file you'd like to edit (even if it doesn't exist yet). For instance:
    atom myfile.txt
    
  6. (Optional, if you have extra time at your hands) Go through the CS 201 Emacs tutorial. This will teach you how to edit files with Emacs.

    Identify the function of and experiment with these Emacs Commands:

    C-x C-s    C-x C-c    C-x C-f    C-x C-w    C-g    C-a    C-e
    C-d        C-_        C-v        M-v        C-s    C-r    M-%
    

    Note that we don't require you to use Emacs. You are welcome to use any editor you want, and most likely Atom (which is installed in the lab) or Sublime Text (another popular choice) will be much easier to learn. Later in the semester we will switch to Eclipse, an integrated development environment for editing and compiling code. However, as a computer scientist, it is very useful to know at least one editor that is purely text-based, and doesn't require a mouse, so you can modify files when you are logged into a server via SSH or Putty. Emacs is one popular choice; another is vi/vim. In both case you will need to learn all the control sequences, but it is worth it!

    (For some fun, survey the CS faculty what editors they use. Be prepared for some strong opinions. If you ask me, real programmers use emacs :)

  7. As described in the Unix tutorial, copy the file ~schar/cs201/examples/hello/Hello.java into your hw0 directory, compile it, and run it. Then, edit it to add your name in a comment at the top, and change the program so it prints something different. Recompile, and run it again.

  8. Submit your program Hello.java using the HW 0 submission page. Be sure to submit the source code (the .java) file, not the compiled code (the .class file). Pay close attention to the output of the submission script, and make sure that it reports "Success".
    If you get an error when trying to submit (e.g. "invalid username"), please send me an email and include the error message.
Congratulations! You are now ready to write and compile your own Java programs for this course.


If you cannot login to the lab computers


If you want to work on your own computer

If you cannot login to the lab computers, or if you're adventurous, you can try to work on your own computer. This will likely involve installing the Java SDK and an editor. Note that we will only provide limited support for this option for now, and more detailed instructions will be added later. If you're up for it, try the following:
  1. On a Mac, open a terminal window; on a PC, open the Powershell. Both will give you a Unix prompt or something very similar (though on Windows you'll have to type backslashes \ instead of forward slashes /).

  2. Type "javac -version" to see if you have java installed already. If it prints a version number starting with 1.8 you are all set, and can skip to step 4. If you get a higher number it would be a good idea to uninstall this version of Java first. (The latest version of Java is NOT compatible with some of the software we will be using in this course.)

  3. Download and install the JDK 8 from the Java SE Development Kit 8 Downloads page. Click on "Accept License Agreement" and download the appropriate file for your computer (Mac OS X x64 or Windows x64). Follow the instructions there and all should be well. Open a new terminal window and repeat step 1 to check that it worked. On Windows, you will likely have to edit the path as well to add the folder where javac can be found, (something like C:\Program Files\Java\jdk1.8.0_201\bin ).

  4. Install a text editor, e.g., Atom.

  5. Follow the lab instructions above to create a cs201/hw0/ folder from your Terminal, for instance on the Desktop or in your Documents folder (use "cd" to navigate there first).

  6. Save the file Hello.java in the folder you created.

  7. Complete the lab (steps 7 and 8 above). Use the text editor you installed to edit the file. Note that you cannot access any of the files starting with ~schar/ since they reside on our server.