Thanks for the answer sir!
I am not afraid to say that I am a programmer, with 3 years of industrial experience, I might not be a good programmer, but I have worked on many projects, my code runs on on a few major government server as well. I just suprised that how far I have went without event understand such simple concept.
I blame it on myself lack of C or C++ experience, never worked with pointers, spent too much time reading APIs rather then trying to understand some fundamental concepts, I am a good sample of how programmer can get spoiled by Java and modern IDEs.
anyway let's work on the question
Because Java is pass by value, if you change the value of a method argument inside the method, the caller does not see the change; i.e., x remains null in your program even after calling the method.
I have changed the code again, and the value changed this time, I still don`t get it why.Are you saying, EVERY method call resulting the JVM make a fresh copy of the original memory location (pointer) inside the method scope, change the formal parameter, only resulting the newly created pointer pointing to another chunk of memory, the original pointer still pointing to "string";
however, before the " y = "hi";" statement, pointer Y and X was pointing to the same memory location which hold the value "string".
Any change on the reference y would also changes x isn't ? You might say that even the X and Y point to the same chunk of memory, but
change to one doesn't reflect on another one. therfor I added another method
giveMeAObj(ObjectRef objY); as you can see, as objX and ObjY point to the same object, change on objY at method level, reflected on the actual object.
Does that mean, primitives type is pass by value, object pass by reference?
You can't write a method to swap the values of two variables passed as arguments.
if I can't swap two arguments, is there anything I can swap?
[ November 10, 2008: Message edited by: Ernest Friedman-Hill ]
[ November 10, 2008: Message edited by: junchen liu ]
[ November 10, 2008: Message edited by: junchen liu ]