Spring 2006
Williams College
Using Java
-> javac Hello.java
Assuming the program is free of compilation errors, a class file "Hello.class" will be created. This file contains the compiled representation of the program. To execute the program, you run the Java virtual machine with the command:
-> java Hello
The command line argument to java is the name of the class whose main method you would like to run.
Try this yourself by copying the file
/usr/mac-cs-local/share/cs136/examples/Hello/Hello.java
to your home directory, compiling it, and running it.
Next, open the Hello.java file in emacs. You will notice that emacs is now in Java mode (to the left of the line number). You can actually compile your Java program from inside emacs using M-x compile, hitting return, then typing javac followed by the name of the java file.
Creating tar Files
The formate for creating a tar file is:
-> tar cvf name-of-tarfile files-or-directories-to-tar
Tar files end with the extension .tar. You can tar up a directory of files by typing the tar command in the parent directory and giving it the directory name. For example, to create a tar file of all the files in the lab0 directory, which is in the cs136 directory, then from the cs136 directory, you would type:
-> tar cvf lab0.tar lab0/
When this file is "untarred," it will create the directory lab0 (if it doesn't already exist) and will put all the files into it. To create a tar file lab0.tar that contains files Odd.java, Date.Java, Conway.java, and conway.txt from the directory where those files live, you can use this command:
-> tar cvf lab0.tar Odd.java Date.java Conway.java conway.txt
You could also make a tar file of all the files in the directory (but not of the directory itself, as above), by typing:-> tar cvf lab0.tar *
To make a tar file of just the java files in a directory, you would type:
-> tar cvf java.tar *.java
You can list the contents of a tar file with:
-> tar tvf lab0.tar
To compress your tar archive, you use the gzip command:-> gzip lab0.tar
This will create a compressed file called lab0.tar.gz. You can uncompress it with the gunzip command:-> gunzip lab0.tar.gz
or the -d flag to gzip:-> gzip -d lab0.tar.gz
Either of these commands get you back your file named lab0.tar. And you can extract the contents of a tar file with:-> tar xvf lab0.tar
Beware! This will extract the files with no concern for whether it is overwriting files in your directory. For this reason, it's a good idea to create a new directory, mv the tar file into the directory, and then extract it there. As was mentioned above, if you are extracting a directory, the directory will be created if it doesn't exist. If it does exist, it will add the files to the direcotry or overwrite them if they already exist.You can both uncompress and extract your tar file simultaneously with the command:
-> tar zxvf lab0.tar.gz
Using turnin
-> turnin -c 136 lab0.tar.gz
Logging Out