Links Quizes/Exams Assignments Proctor Lab Hours Office Hours Sylabus Announcements
General Questions and Answers
 
Q: What is chaining?

A: In general, any method that returns a reference to an object can be used for chaining additional method calls on that returned reference. Typically we return this, but as in the toString() example, we return a reference to another object and then call a method on that object (as opposes to another method of this object).

Chaining is just a convenience mechanism. Using the hashCode() example, if we did not chain method calls, it would look like

String s = this.toString();
int hashValue = s.hashCode();
return hashValue;

Instead of having all these local variables to hold intermediate values, we can just

return this.toString().hashCode();





Q: My program works fine on DOS at home, but when I FTP it to sunpal, I can't get it to run. What's going on?

A: If you're trying to run code using telnet or ssh from your home computer, and your program includes calls that create separate windows, the problem is not from your code but telnet/ssh is unable to do any GUI functionality with Java. I would suggest you to physically go to the Sunpal lab and test your program there since we are going to grade your program using these Sunpal stations.



Q: When I transfer my code to sunpal after writing it in windows, I get these weird ^M characters at the end of each line. Is there a way to get rid of them without having to go to each line and delete them?

A: The reason for the ^M is that dos/windows and unix use different symbols to represent newlines in text files. You can use the command dos2unix to get rid of the ^M's. Here's the format:

dos2unix $sourcefile $destfile

where $sourcefile is the name of the file to convert, and $destfile is the name of the file to write to. If you have $destfile the same as $sourcefile, it will overwrite the dos version of your file, which in the lab is usually what you want anyway, but you have a choice of creating a new file if you want.