# Matt Wheeler

Greenhorn
since Nov 20, 2001
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Matt Wheeler

Ok, not to beat this horse to death, but what about this?
public class Hold {
public String hold = "a string";
}
class Tryit {
public static void main(String[] args)
{
Tryit tryit = new Tryit();
Hold h = new Hold();
tryit.amethod(h);
}
public void amehtod(Hold h)
{
h.hold = "a different string";
}
}
This does change the value of the string hold in my instance of Hold called h correct? Please say yes.

[This message has been edited by Matt Wheeler (edited November 21, 2001).]
18 years ago
So if in the swap method I just put ai = "vishu"; and bi = "abu"; then a would be equal to "vishu" and b would be equal to abu; after swap returned. Is that correct?
18 years ago
Hold up, I am a little confused. So what you are saying is that a and b after swap(a,b) still contain their initial values of a="abu" and b="vishu" (if I remember correctly)? I understand that their references are not changed by doing bi = ai and bi = temp, but aren't their values changed? If not, how would you change the values so that after swap, a="vishu" and b="abu" which is what I would assume a function named swap should do?
Thanks,
Matt
18 years ago
Ok, so I have a quick, somewhat off the subject question. In the comparison if(t++ > m) is done with m = 0 and t = 0 before the comparison is performed, then it will yield false, but t will be incremented to 1 after the comparison. Is that correct? However, what if the comparison was if(++t > m) with m = 0 and t = 0 before the comparison, then t will be incremented to 1 before they are compared, and the result will be true. Is this correct? Is this a result of operator precedence, or just the way t++ and ++t are defined?
Thanks,
Matt
[This message has been edited by Matt Wheeler (edited November 21, 2001).]
18 years ago
Ok, this has always baffled me, so once and for all. For objects what does == do and what does .equals() do? And could I get an example? Like Object obj1 = new Object(); and Object obj2 = new Object(); What does obj1==obj2 yeild and alternatively what does obj1.equals(obj2) yield? With strings and with wrapper clases, am I correct in saying that the == operator compares references for equality and .equals() compares values for equality? For instance Integer int1 = new Integer(1); and Integer int2 = new Integer(1); then int1==int2 will yield false and int1.equals(int2) will yeild true, correct? This is the same with strings, but StringBuffers are not overriden and so they perform the same way as the object comparison operators, correct? Also, it is obvious that with a String or a wrapper class you can compare a value or a reference, but with objects, it does not seem that there is any value to compare, so does == and .equals() in object just compare reference (meaning they do the exact same thing)? And in StringBuffer, even though there is a value to compare, does it only check reference when using .equals() or ==?
Sorry for the long runon question. I am very appreciative to anyone who can take the time to answer it.
Thanks,
Matt Wheeler
18 years ago
I was reading over the explanation of this code and how it works, and I have a quick question. Why doesn't the line v = vh change the reference of v. v is an object, so it is passed by reference and if you change that reference in the method, its reference is also changed in the calling method isnt't it? If that is the case then when v.i is output in amethod, the result would be 10 or the same value that was in vh which v now references, or am I totally missing something? So with my logic which is appearantly wrong I would assume the final output to be 10010. So what am I missing here? I may need some serious explanation, because it appears that I am confused.
[This message has been edited by Matt Wheeler (edited November 20, 2001).]
18 years ago