Computer Science 351: Questions and Answers

Frequently asked questions about lab assignments, homeworks, lectures, or any other topic of CS 351 will be posted here.

If you have a question you'd like answered send email to compsci-351@uwm.edu. In your email, please give the following information:

  1. Name of simplest test case that your program fails.
  2. Exact test that fails or errors out. (You can fail a test by giving the wrong answer which assertXXX(...) checks. Or you can fail by crashing with an assertion error or some other exception.)
  3. Exactly what the failure is: which Exception was thrown, or what JUnit says is wrong.
  4. What you think the data structure looks like at the point your code is called. (Tell us whether you have checked your guess in the debugger.)
  5. The snippet of your code (whole method typically) that went wrong. Mark the line where the exception was thrown from, if any.
  6. Explain then either
    1. Why you think your code should do what the test wanted, and why you think it shouldn't crash with that exception, OR
    2. Why you think the test case is doing the wrong thing.
    You are probably wrong in this part, but that's fine. If you weren't wrong, you wouldn't need help!

NB: See Java 8 API.

NB: See how to access your grades.

Homework #7

Q: What should the calculator do upon division by zero?

A: Throw an exception (the one thrown by actually dividing by zero is right) and clear the stacks.

Q: The Homework said that we could copy code from lecture, but there is no lecture7 repo.

A: That's right, but maybe you recall when we did a generic array container class?

NB: Last minute changes to the assignment description were not in printed copy. The web age has more explanation of the "default" value.

NB: We pushed a change to your repo at 8am Tuesday March 5. If you cloined your repo Monday night or very early Tuesday, make sure to "Team > Pull" as soon as possible. Don't skip this step; or you will be prevented from pushing your assignment.

Homework #6

NB: We see people's sort code creating a new sequence, or creating new nodes (no new Node(,,,)), by calling things like addAfter. Don't do this! We asked you to do insertionsort on the linked list directly.

NB: testA assumes that you initialize the precursor in the constructor, not in its field.

Q: I pass all the tests (TestHexBoard, TestExhaustive even random testing) and all the efficiency tests except testLong.

A: Look at that test and see what it's calling, then make sure that all the methods that it calls are "constant-time" (don't have loops or call methods with loops).

Q: ... but addAfter needs to call CENSORED because of the special condition?!?

A: Actually under that condition, there's no need to call it.

NB: Please add the following test case to TestExhaustive:

  public void test0000() {
	  ss.sort(comp);
	  assertEquals(0,ss.size());
  }

Q: The random test used HexTileSeq. Changing to Sequence didn't work. What's wrong?

A: Oops. You're right it's generating bad code. I have installed a fix: take this version of RandomTest.java and place it in the default package. Then run this file, not the one in your JAR. The generated code will still have "raw" warnings. Fixing that cannot be done with an easy change, so I hope you can live with it.

Homework #5

NB: You will likely lose points if your code has extraneous conditions. Especially: PieceCollection is using a dummy node---dummy nodes are added to simplify things so one doesn't need special cases. So your code should use "if"s sparingly: basically only for error checking, or other necessary reasons.

Q: There are TODOs in HexBoardEditor but the homework doesn't say what we need to do. It seems to be already implemented.

A: You're right. There's nothing to do.

Q: test27 in TestHexBoard complains about the exception that my implementation of next() throws. It is expecting a "concurrent modification exception" but we are not required to implement "fail fast" semantics for the hex board iterator.

A: You are correct -- the test is too strict, but before you ignore it, ithas a useful function. If you are failing this test you are probably doing unnecessary work in your next() implementation. Read the paragraph in the homework starting "When you implement the iterator", especially the last two sentences. And then see if you can get rid of an if in your code.

Q: I don't understand this line from test1:

self.dummy.prev = c[1] = c[1];
It seems to do an extra self assignment.

A: Oops. Yes. The extra assignment is fortunately harmless in this case. No need to change it, but rest assured that it really should just say

self.dummy.prev = c[1];

Homework #4

Q: I don't see why testE says that the data structure isn't well formed. The head and tail all look good.

A: Look at testH to see a similar structure that is well formed. Something was missing in testE. You also might profitably read the Meaning of the fields section again, especially the last sentence.

Homework #3

Q: Where is "standard output" ? Is it a file somewhere?

A: As Prof. Boyland said (briefly!) in lecture on Thursday, System.out is standard output, as can be seen by its javadoc.

Q: How can I get the "lecture3" repository Prof. Boyland developed in lecture?

A: Scroll down! We have instructions below the General section.

Q: The homework refers to a file test/sample.hex but my Homework #3 repo doesn't seem to have it?

A: Oops: we neglected to get it to you. Fortunately it was provided in Homework #2's repo as well. Copy it over.

Q: Can you give a sample edit sequence using HexBoardEditor ?

A: Here is a MOV file (no sound). The program was stopped and it printed this result to System.out.

NB: The skeleton code refers to WIDTH as the width to use for hex tiles. That comment is wrong. Use getHexWidth instead.

Homework #2

Q: I tried to use the code on page 313 (page 302, 3rd edition) to do the clone, but it doesn't work.

A: That code should not be used. It's worthless for this assignment. Think about what needs to happen and why. (Which test are you failing? What goes wrong with the incomplete code we give you?)

Q: For the method isCurrent, how can I show that there is no current index?

A: Read the segment of comments at the start of the class that begins

// Implementation of the HexTileSeq class:

Q: In addAll it says "The current element of this sequence if any, remains unchanged." but if I leave currentIndex unchanged, then the test fails. Is the comment wrong?

A: No the comment is describing WHAT the operation does. It does not describe HOW you are to implement it. The "current element" is an ADT concept about abstract states. The comment doesn't say that the similarly named field currentIndex cannot change; it says nothing about the implementation (the HOW).

Homework #1

Q: I can't run Main since applets are no longer in Java.

A: Copy this file (Demo.java) into your default package and run it instead.

Q: What is the expected output of the Main (or Demo) program?

A:

NB: if statements are unnecessary in toPoint or toPolygon. Don't use them.

NB: There are some important Java arithmetic facts that apparently people don't know. If you get errors in test66, test yourself whether you could figure what this will print:

int w = 15;
System.out.println("Q1: " + (w/2 + 0.5));
System.out.println("Q2: " + ((int) 7.9));
So if your code has w/2 in it, or a cast, you should be able to figure out why it isn't working.

Q: I don't understand what HEIGHT_RATIO is, "the amount down each row is from the last"

A: Look at the diagram on the first page of the homework. Consider the row of hexagons <1,1,0>, <2,1,1>, <3,1,2>, ... . Suppose we drew a line through this row of hexagons. Then look at the next row of hexagons <2,2,0>, <3,2,1>, <4,2,2>, .... Draw a line through this row of hexagons. What is the amount down this row is from the last, as a fraction of the width?

Q: I'm stuck on this locked test:

assertEquals(???,h.toPoint(1000).x)

A: What hexagon is h referring to? Find it in the picture on the first page of the homework. Suppose that the picture is the computer window that the hexagons are being displayed on. Suppose further that the hexagons are 1000 pixels wide. What is the x coordinate of the pixel at the center of the hexagon in question?

Q: Where is Terrain.java?

A: You're supposed to create it!

Q: I'm failing the long toPolygon method by being off by one for some values. The homework says to round, and I am rounding.

A: Make sure you are not rounding until the very last moment, when you are creating a Point to return. In particular if toPolygon calls toPoint then it is rounding prematurely.

General Questions

Q: How do I run RandomTest? (Relevant if the homework indicates there is a RandomTest.)

A: The easiest way to run RandomTest (for homeworks that include it) would be to right-click the included lib/homeworkX.jar file in Eclipse's package explorer, and select "Run as" -> "Java Application". If RandomTest is included in the homework, you should see it under "Matching Items". Run it. It will run several million tests before giving up. If it completes the whole number, this shows that your implementation of the methods tested are likely to be correct. If it stops and outputs a particular test case, this means your code has failed one of its randomly-generated tests, and you can debug based on its output. Feel free to copy the output into a JUnit test so you can use the debugger to step through it.

Q: I don't know how to implement hash code. What should I do?

A: The hash code should combine integers derived from the fields that are compared for equals. An integer field is usable as is. A double can be converted into an integer for hash code purposes using a method in class Double. When you combine values, the tutorials frequently use "31" to spread the values apart from each other. You may want to use a larger spread. Here's one example tutorial on hash code .

Q: Can we add our own helper methods?

A: In principle yes, but if you do the homework "properly" you shouldn't need to add helper methods, unless we mention them. But if (for example), you don't know the "this(...)" syntax for calling one constructor from another, then a helper method can avoid the need to duplicate code (good to avoid).

Lecture Example

Q: Do we have access to the examples shown in lectures? Where do we find them?

A: You can use eclipse to import the lecture examples using repository path

/afs/cs.uwm.edu/users/classes/cs351/public/lecturen.git
Replace n at the end with the corresponding week number.

On-Line Lecture Transcripts

If there is an on-line lecture using the "chat" tool, the transcript generated is a file whose name ends in ".cht". This is a record of the series of actions during the lecture: wriing a line in the discussion forum or on the board, or ediing the same. You can pick up the "cht" file from the "public" folder of the AFS volume of the course: /afs/cs.uwm.edu/users/classes/cs351/. You can acess AFS either directly if you install OpenAFS software, or indirectly through andrew.cs.uwm.edu using an SFTP-enabled file transfer agent, such as WinSCP or FileZilla. Once you get the file, load it into the "chat" tool using the "File>Open..." menu. The "chat" software is available on the software depot page from the main course web page.

Homework Solution

Q: The handout says to check the solution to previous homework for examples. Where do we find them?

A: You can use eclipse to import the solution using repository path

/afs/cs.uwm.edu/users/classes/cs351/solution/homeworkn
Replace n at the end with the corresponding homework number and note that there is no .git at the end. When you try to import the homework solutions using default settings, you may encounter an error that says files already exist. To fix this, there are two things you need to do:
  1. At start up, choose a different workspace
  2. On import dialog, on the step where you can choose the local destination of git repo, type in a different name at the end of the path e.g homework2_solution.
Alternatively, you can ssh into andrew.cs.uwm.edu (see instructions), change directory to the above path.

Accessing AFS through andrew

Q: You said our grades are on AFS and so is the quiz solution. How do we access files in $CLASSHOME/...?

A: You should ssh into andrew.cs.uwm.edu (see instructions). Then you can change directory to the place of interest, e.g. your grade directory or the solution file and look at a file using more.

NB: While on andrew, you can check the status of a homework git, what you have pushed or not:

git --git-dir=/afs/cs.uwm.edu/users/classes/cs351/401/loginname/git/homeworkn.git log

Eclipse Problems

Q: I accidently deleted a file. How can I restore it?

A: There are two ways: one is easier but can only restore an entire directory, the other is more complicated but can restore a single file.

First way, in "Package Explorer", right click on the folder where the deleted file belongs to, and select "Replace With" -> "HEAD Revision". Then click "OK". This will replace ALL files in the directory with the ones in last commit. So if you changed any other file in that directory, make sure commit the change on that file before using this approach.

Second way, select "Git Repository Exploring" from "Window" -> "Open Perspective" in menu bar. Then, look "Git Staging" tab in a sub-window. If you didn't do a commit (you shouldn't!) after having accidently deleted the file, you should see your deleted file in "Stage Changes". Right click the file and choose "Replace with HEAD Revision", the file should be restored.

Q: When I try to "push" I get an error: rejected: non fast-forward.

A: That message means you need to "pull" first before "push".

NB: See instructions to merge if you have any problems with push..

Q: It says I can't run my programs because of a major/minor version error.

A: The problem was that the project was compiled on a machine with a higher version of Java (e.g. 7) than the current setup can handle (often Java 6). Clean the project and try again. ("Project > Clean ..." and then just clean the current project -- the one that doesn't work. No need to clean everything).

NB: A similar problem can happen if you use a non-default JRE in the project. Then nothing works, and you have a nasty red exclamation point on the entire project. You will need to go to Project Properties and choose the Java Build Path and then select the Libraries tab. The JRE library selected is marked as bad, delete and then "Add Library > JRE System Library > Workspace default JRE". Then it will clean automatically and rebuild.

AFS and Kerberos Installation

NB: It is no longer necessary to install OpenAFS on your home computer for CompSci 351

NB: In the instructions that follow, if you are on the campus network, you can use AD.UWM.EDU as the Kerberos realm (cell is still cs.uwm.edu) instead of CS.UWM.EDU and then use your University password.

Installation on Windows (64 bit)

  1. Go to Openafs.org/windows.html
  2. Select the section Kerberos for Windows (MIT or Heimdal)
  3. Select Heimdal Kerberos, which takes you to a webpage at "Secure Endpoints"
  4. Select the latest Heimdal Kerberos (1.5.1 or later) for 64 bit. Run/Install this. (Typical install is fine)
  5. Next, on the same "Secure Endpoints" page, find a link to Network Identity Manager v2 (available separately) and click there.
  6. That brings you to a new page, scroll down to the download section and get the 64 bit regular download (not the SDK download). Run/Install this. (Typical install is fine)
  7. Now assuming you downloaded Heimdahl (not MIT) KfW, on your windows machine, bring up the following file in NotePad running as Administrator:
    C:\ProgramData\Kerberos\krb5.conf
    
    Add a line after the line [libdefaults]. This new line should say
        allow_weak_crypto = true
    
    Then "Save" the file. If it doesn't let you save, then you probably didn't run NotePad as an Administrator. Quit NotePad and try again, this time running NotePad as an Administrator. (Apparently it's possible to run a program as administrator by using Control-Shift-Enter from the Search box under Start. Another possibility is to right-click the notepad application and choose "run as administrator".)
  8. Finally verify that this is working by doing the following in a Command Prompt window:
    kinit yourid@CS.UWM.EDU
    
    Type your CS kerberos password. If on campus, you can use AD.UWM.EDU instead with your panther password. If this succeeds, then continue. Otherwise, tell us the error.
  9. Finally, you can install OpenAFS itself. Go back to the Windows download page for OpenAFS and download the latest 1.7.X distribution. When you run it:
    1. Choose "Typical Install"
    2. On the "Configure AFS Client" Page: Choose "cs.uwm.edu" as the default Cell (NOT openafs.org). And DISABLE "Integrated Logon". Other things should be enabled.
  10. The computer will need to restart. Let it restart and then log in again.
  11. Make sure the network is running (open a browser window).
  12. Start "Network Identity Manager". You might have to look for it.
  13. It will say you don't have credentials. Click to obtain new credentials.
  14. The dialog window will list your Windows logon and ATHENA.MIT.EDU. Change it to your Panther ID (not your student ID!) and CS.UWM.EDU (or, if on campus, AD.UWM.EDU).
  15. If the network is running, it should ask for your password. This is your kerberos password. (or if using AD.UWM.EDU, your panther password).
  16. If it works, you end up with a green credential. A delay of 30 seconds is OK.
  17. If there is a long delay (a minute or more) or a brief error message and THEN the green credential thing comes up, AFS is not working. Perhaps you specified the wrong cell (cs.umw.edu ?). You will need to check the AFS information about your credential. Look at the Advanced view and see if you see something obviously wrong.
  18. Now you can use Eclipse. On Windows, remember to use backslashes. and START with two of them: \\afs\cs.uwm.edu\users\classes\cs351\...
If you have problems, please indicate how far you got through these steps. Also, give the output of the following three commands (run in a Command Prompt window):
  1. net view \\afs
  2. kinit yourpantherid@CS.UWM.EDU
  3. aklog -d -c cs.uwm.edu

NB: If you install Openafs 1.6.X on a Windows machine, don't expect us to be able to help you if it doesn't work. OpenAFS 1.7.X is recommended for all Windows installations.

Installation on MacOSX

  1. Download the software from http://openafs.org/macos.html.
  2. Install the DMG that you have downloaded. ("Click icon to install") "This package will run a program .." (Continue)
  3. On the Client Cell Configuration, select cs.uwm.edu. Optionally cs can be the alias, but you won't need an alias.
  4. Install on the main hard disk. It will ask for your local password to get permission to install.
  5. Then if using Lion or later (e.g., Mountain Lion), open a terminal and use vim (see VIM documentation) to edit /etc/krb5.conf. At the prompt ~ $, type the following
    sudo vi /etc/krb5.conf
    This will ask for the local password, and then bring up the file. Make sure that you have at least the lines:
    [libdefaults]
    allow_weak_crypto = true
    default_realm = CS.UWM.EDU
    
  6. Now you have finished the installation.

    In order to use OpenAFS to access your class files, you will need to get kerberos credentials and use them to get AFS tokens.

    kinit yourpantherid@CS.UWM.EDU
    aklog
    Kerberos credentials (and the associated AFS tokens) expire after a time (typically 10 hours, sometimes 25 hours -- it can be set in your krb5.conf file).

Installation on Linux

If asked the following questions, here are some recommended answers:
AFS cell?
cs.uwm.edu
size of AFS cache?
1000000 (that is, one gigabyte)
run AFS now?
yes
encrypt AFS traffic?
yes
dynamically generate contents of /afs?
yes
fakestate?
yes
You should ensure that /var/openafs/cache has at least as much space free as you promise in your cache response. Best is that the cache is its own partition. The file system should be ext2, ext3 or ext4. Once you have installed it, continue with the instructions for MacOSX.

Troubleshooting an AFS/kerberos installation

Some OpenAFS errors are easy to fix. Use aklog -d in a command prompt / terminal window to determine the problem.

Error 56 (Authentication server unavailable)
This means you are trying to use the AFS client service to get tickets. This doesn't work. You have to use Network Identity Manager (Windows) and/or aklog (any).
No credentials cache file found
You haven't got Kerberos tickets with Network Identity Manager yet. First get tickets and then if the Advanced view doesn't show AFS tokens, then run aklog again.
enryption type des-cbc-crc disabled
You need to edit krb5.conf to allow weak cryptography as described above.
KDC has no support for encryption type
You need to edit krb5.conf to allow weak cryptography as described above.
error -1765328234
You need to edit krb5.conf to allow weak cryptography as described above.
missing XXX.dll
This means you installed MIT kerberos for windows 32 bit but are on a 64 bit machine. You should have gotten the 64 bit version from Secure Endpoints. Look carefully for the 64 bit link on the OpenAFS installation page. Uninstall the old NIM and re-install the correct one.
clock skew
This means your system clock is more than 5 minutes off the AFS server. You should make sure you have the right time zone (US Central) and then reset your system clock to agree with an external source, e.g. your cell phone.
Couldn't get openafs.org AFS tickets
If you get an error message about openafs.org, this means you accepted the default cell as openafs.org instead of changing it to cs.uwm.edu. I don't know how to change it after installation (you could uninstall and reinstall and this time make sure to set the default cell), but you can also run aklog with a cell option:
aklog -d -c cs.uwm.edu
The Network Identity Manager also has a way to get tickets from cells other than the default cell. It's in a hidden dialog. Go to the Options>AFS page, and then select your panther ID (half way up the page) and then select the AFS tab, and then add cs.uwm.edu as a cell to use in the bottom dialog.
ktc 7
If you had OpenAFS working, and it stops working, and this is the error, it can be fixed by rebooting. Otherwise, this is a hard error to fix. This error no longer happens with the OpenAFS 1.7.X IFS client.
RPC server is unavailable
If this error happens when you try to navigate to \\afs\cs.uwm.edu this means your computer is not letting you access the AFS server. You probably have an overactive firewall.
client not found in kerberos database
You are using the wrong realm. You should use CS.UWM.EDU or AD.UWM.EDU, not a lowercase name or MIT.EDU etc.

NB: On Linux or MacOSX, the command line is used to authenticate to AFS. On Miller, I wrote a script called klog. You can make yourself a similar script. The only two things you MUST have are

kinit PantherID@CS.UWM.EDU
aklog -c cs.uwm.edu

Q: On my Windows Vista PC, I can get a kerberos ticket, but don't get permission to access CS 351 files.

A: You need an AFS token. The network identity manager defaults to openafs.org, but you need to change that (File>AFS>Preferences) to cs.uwm.edu. Then add 'cs.uwm.edu' as a cell to automatically get tickets for. Once you have a kerberos ticket, it will get your AFS tokens for you.

Q: How do I get to the CS 351 from my windows PC?

A: Use the ANC path: \\afs\cs.uwm.edu\users\classes\cs351\...

Q: On my MAC/Linux computer, when I try to kinit, it says

client not found in the kerberos database.
A: This means the default realm is not CS.UWM.EDU, and so you have to specify it on the command line, or make it the default realm.

Q: If I get past the error I just mentioned, I get a new error:

Cannot get any kdc for realm CS.UWM.EDU
A: This means that your computer is prevented from accessing the KDC. This can happen if you are off the network, or have a paranoid firewall, or are using UWM's "Public" WiFi system.

Q: What should krb5.conf have in it?

A: Actually you don't need to have much of anything, unless you are using Heimdahl in which case you must "allow weak crypto" but the following is a reasonable contents:

[libdefaults]
allow_weak_crypto = true
default_realm = CS.UWM.EDU

[realms]
CS.UWM.EDU = {
  kdc = kerberos.cs.uwm.edu
  kdc = kerberos-1.cs.uwm.edu
  master_kdc = kerberos.cs.uwm.edu
  admin_server = kerberos.cs.uwm.edu
}

Q: On my Mac, I got the kerberos tickets; now how do I get AFS access.

A: Use "aklog" from a terminal window, or use one of the Third Party tools mentioned on the OpenAFS download page for MacOSX.


CS 351 FAQ / John Tang Boyland boyland@cs.uwm.edu