Spring 2006
Williams College
Data Structures and Advanced Programming
Old Announcements
1. You should never have a statement that looks like:
if (var == true) or if (var == false)
in your code. Rather, you would have
if (var) or if (!var)
2. You also shouldn't have:
if (some_condition){
return true;
} else {
return false;
}
in your code. Rather, you would have:
return (some_condition);
3. You don't need to call toString in a print statement. Instead of:
System.out.println(a.toString());
just have:
System.out.println(a);
4. In a for loop, if you get to a condition where you know you are going to return true, just return true rather than storing it in a variable and returning it after the for loop.
5. Java has what is called short circuit evaluation. If it is evaluating (a && b && c && d), it would stop evaluating as soon as it found a variable which was false. If a were false, b, c, and d would never get evaluated. If it is evaluating (a || b || c || d), it would stop evaluating as soon as it found a variable which was true (since the whole expression is true if one of the parts is true).
WARNING: scp will always overwrite files when it copies without telling you, so be sure you make backups before you scp or that you are very careful that you are doing what you intend when you scp.
Rather than use a third-party program under Windows to copy and move around files to work on the FreeBSD machines (which is fine), you can also use the Unix scp command (secure copy). You can type man scp at the prompt to get detailed help about it, but I'll give you the basics here:
If you are on one of the freeBSD machines (say gobra.cs.williams.edu) and you want to copy from cortland, since both gobra and cortland are on the same network (cs.williams.edu), you only need to use the machine name to scp or ssh, and here is an example of how to copy the files from your lab3 directory on cortland to the directory you are in on gobra:
-> hostname gobra -> pwd /home/faculty/stacia/cs136/lab3 -> scp cortland:cs136/lab3/* . Password: bash: line 6: /usr/mac-cs-local/bin/136: No such file or directory FrequencyList.java 100% |*****************************| 0 00:00 Table.java 100% |*****************************| 0 00:00 WordGen.java 100% |*****************************| 0 00:00 -> ls FrequencyList.java Table.java WordGen.java ->
What is shown above is that I am on gobra in my cs136/lab3 directory and I want to copy the files from the same directory on cortland. WIth the scp command, the first argument is the machine name followed by a colon, and then you give the path relative to your home directory on that machine (for example, if I had just said scp cortland:* . then it would have copied all the files in my home directory over) followed by the filename that you want to copy (* means all the files) and then you type dot to mean to copy the files to your present directory with the same name. You will get a warning about not being able to fine a file, but ignore it. You will need to type in your cortland password. As you can see above, my three files were copies over successfully. You could also create a tar file of the files you want to copy, then copy over the one tar file.
If you then want to copy them back over to cortland from, say, gobra (or whatever freeBSD machine you happen to be on), you would do the following:
-> scp * cortland:cs136/lab3/ Password: bash: line 6: /usr/mac-cs-local/bin/136: No such file or directory FrequencyList.java 100% |*****************************| 0 00:00 Table.java 100% |*****************************| 0 00:00 WordGen.java 100% |*****************************| 0 00:00 ->
Here, you are saying to copy all the files in the current directory to your account on cortland into the cs136/lab3 directory.
The general syntax of the scp command is:
scp [options] fromhostname:fromdirectory/filename tohostname:tohostdirectory/filenamewhere the current host is the default hostname.
For example:
-> ssh latuka.cs.williams.edu
You will be asked if you want to add the host to your known hosts list, say yes, and you'll need to enter your unix password. Java 5 will soon be the default version of java on the freeBSD machines, but in the meantime, you should create a .local_bashrc file in your home directory with the following line in it (you did something similar for the mac machines already, this will set you up on the freeBSD machines):
source /home/faculty/stacia/shared/136
The first time you add this, you should then source the file from the command line with:
-> source .local_bashrc
Then you should be able to edit, compile and use turnin. The only problem is that your cortland files will not be in your freeBSD home directory, so you'll have to copy them over. Always be sure to keep track of which is the most current version of your program.
-> javadoc -tag pre -tag post X.java
Don't forget it's due Wednesday 1pm.
-> turnin -c 136 00skw_lab0.tar.gz The authenticity of host 'witrik.cs.williams.edu (137.165.8.79)' can't be established. DSA key fingerprint is df:60:83:b1:05:d9:8e:34:67:30:52:84:d3:97:22:01. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'witrik.cs.williams.edu,137.165.8.79' (DSA) to the list of known hosts. Password:You should answer yes, and then you will need to type your unix account password. If you successfully turn in your lab, it will tell you so.
-> emacs foo.java
at the command line. If you want to create a new file, you have two options (actually probably 200, but I'll give you two here):
-> emacs Odd.java
at the prompt. This will create the file Odd.java and emacs will open up in the place where you edit (not that first notes buffer).
-> turnin -c 136 lab0.tar.gz
source /usr/mac-cs-local/bin/136
to your .local_bash_profile file, but you only have a .bash_profile file in your home directory, so you will need to use emacs to create the file. You do this by typing (in your home directory):
-> emacs .local_bash_profile
and then you add the above line (source etc.). It will be the only line in the file. So then you save the file and exit out of it and then type at the command line:
-> source .local_bash_profile
If you don't do this last part, when you try to turn the lab in, it will say "command not found: turnin".
-> /usr/local/bin/kinit
then your original password, then at the prompt type:
-> kpasswd
to change your password.