File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String and String Buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String and String Buffer" Watch "String and String Buffer" New topic
Author

String and String Buffer

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100


Ans is :s=aaa sb=bbbaaabbb

The value of String object is understandable because strings are immutable so any changes made in the mehod will not effect the original String.
But why does setting the StringBuffer to null does not effect its value.
After all StringBuffr is not immutable and any changes made to it in the method should have an effect in the original StringBuffer object.
i know i am not getting it right.
please help
Geoffrey Vlassaks
Greenhorn

Joined: May 12, 2004
Posts: 24
Hi,



After the append, the object where "sb" references to has a value of "bbbaaabbb". "sb = null;" removes the reference to that object, but the original "sb" (that one in the main method) still refers to that object. The whole clue is, that when you pass an object as an argument to a method, you pass a copy of the reference to that object. So by setting the copy reference to null, doesn't mean that the original will be set to null..

Greetz,
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
first of al have a look at this example on a different topic.

parameter passing

Its a pretty neat illustration.
Jerry Bustamente
Ranch Hand

Joined: May 24, 2004
Posts: 90
I am overwhelmed by the postitive spirt of this forum and by the usefulness of JavaRanch.

I am new to Java and just wanted to thank Swamy for his excellent Flash application that demonstrates how variables are passed in Java.

http://www.geocities.com/mcglonec1978/javacert/paramPassing.html

I hope I can contribute to others benefit in the future once I am more skillful.

Jerry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String and String Buffer