<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic StringBuffer in java in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1248297#M79904</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;Consider the following example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;public class Test
{
static void operate (StringBuffer x, StringBuffer y)
{
x.append(y);
y = x;
}

public static void main (String [] args)
{
StringBuffer a = new StringBuffer ("A");
StringBuffer b = new StringBuffer ("B");
operate (a,b);
System.out.println(a + "," +b);
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is: AB,B&lt;/P&gt;&lt;P&gt;I thought arguments were always supplied "by value" in Java. Meaning that copies of objects "a" and "b" would be provided to the method "operate".&lt;/P&gt;&lt;P&gt;However, in the above example, while object "b" behaves as anticipated (since it did not change after being sent to "operation"), object "a" has changed, which perplexes me. As if "a" was passed by reference and "b" was passed by value. Is there something I'm missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jan 2023 00:55:39 GMT</pubDate>
    <dc:creator>hectorsalamanca</dc:creator>
    <dc:date>2023-01-14T00:55:39Z</dc:date>
    <item>
      <title>StringBuffer in java</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1248297#M79904</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;Consider the following example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;public class Test
{
static void operate (StringBuffer x, StringBuffer y)
{
x.append(y);
y = x;
}

public static void main (String [] args)
{
StringBuffer a = new StringBuffer ("A");
StringBuffer b = new StringBuffer ("B");
operate (a,b);
System.out.println(a + "," +b);
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is: AB,B&lt;/P&gt;&lt;P&gt;I thought arguments were always supplied "by value" in Java. Meaning that copies of objects "a" and "b" would be provided to the method "operate".&lt;/P&gt;&lt;P&gt;However, in the above example, while object "b" behaves as anticipated (since it did not change after being sent to "operation"), object "a" has changed, which perplexes me. As if "a" was passed by reference and "b" was passed by value. Is there something I'm missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 00:55:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1248297#M79904</guid>
      <dc:creator>hectorsalamanca</dc:creator>
      <dc:date>2023-01-14T00:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: StringBuffer in java</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1248613#M79925</link>
      <description>&lt;P&gt;Yes, you're passing values.&lt;/P&gt;&lt;P&gt;BUT: Your values are objects with attributes and methods. In your operate function, you're using these methods to change the internal attributes of your values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what's happening:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;static void operate (StringBuffer x, StringBuffer y)
{
  // x and y are passed by value. but they have internal values themselves.
  // here, you're changing x's internal value. You're not changing x itself, only its internal value!
  x.append(y);

  // here, you're creating a new variable in the local scope of this function.
  // this does not change the variable you passed into this function, because
  // it is outside of this function's scope.
  // IF you would be passing by reference (which you are not!), this would
  // change the outer y
  y = x;
}


public static void main (String [] args)
{
  StringBuffer a = new StringBuffer ("A");
  // a = "A"
  StringBuffer b = new StringBuffer ("B");
  // b = "B"
  operate (a,b);
  // a = "AB", because you changed a's internal value
  // b = "B", because you didn't change its internal value
  // y_inside_the_function = "AB", but y only exists inside the function's scope
  System.out.println(a + "," +b);
  // "AB,B"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are some good explanations in this StackOverflow post:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value" target="_blank"&gt;methods - Is Java "pass-by-reference" or "pass-by-value"? - Stack Overflow&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 10:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1248613#M79925</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-17T10:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: StringBuffer in java</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1252110#M80068</link>
      <description>&lt;P&gt;hey thank you for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2023 21:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/stringbuffer-in-java/m-p/1252110#M80068</guid>
      <dc:creator>hectorsalamanca</dc:creator>
      <dc:date>2023-01-26T21:28:20Z</dc:date>
    </item>
  </channel>
</rss>

