Java uses only pass by value. In case of the String, the new Object is created inside the stringReplace but it doesn't affect the original String object in the calling method. In case of StringBuffer, the object state is modified and hence the change is reflected in the calling method.
Java uses pass by value. The value of the reference will be passed in the case of objects.
Regards,<br />Ram.<br />SCJP 1.4
Joined: Mar 19, 2006
Pass by reference means you should be able to change the value stored in the reference variable also. But in JAVA only the objects pointed by the reference variable is changed not the reference variable itself. So in JAVA there is ONLY PASS BY VALUE.