<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: String constant pool</title>
	<atom:link href="http://technote.wsjoung.com/2006/11/26/string-constant-pool/feed/" rel="self" type="application/rss+xml" />
	<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/</link>
	<description>simple note</description>
	<lastBuildDate>Fri, 09 Dec 2011 14:46:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: jack</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-212</link>
		<dc:creator>jack</dc:creator>
		<pubDate>Mon, 16 May 2011 04:41:35 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-212</guid>
		<description>&lt;a href=&quot;#comment-32&quot; rel=&quot;nofollow&quot;&gt;@Munish Gogna &lt;/a&gt; 
u have wrote the  same println message for both if block and else block</description>
		<content:encoded><![CDATA[<p><a href="#comment-32" rel="nofollow">@Munish Gogna </a><br />
u have wrote the  same println message for both if block and else block</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nrg</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-182</link>
		<dc:creator>nrg</dc:creator>
		<pubDate>Sat, 20 Nov 2010 04:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-182</guid>
		<description>shouldnt it means:

In this case, a regular object will be created by new keyword on heap area and it will NOT be placed in the String constant pool. Finally it will be assigned to the reference variable, var3.


???</description>
		<content:encoded><![CDATA[<p>shouldnt it means:</p>
<p>In this case, a regular object will be created by new keyword on heap area and it will NOT be placed in the String constant pool. Finally it will be assigned to the reference variable, var3.</p>
<p>???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ariel Diaz Molina</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-148</link>
		<dc:creator>Ariel Diaz Molina</dc:creator>
		<pubDate>Fri, 16 Apr 2010 13:32:38 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-148</guid>
		<description>hey guys why did u call Sring litral to a &quot;thing&quot; that is not an &quot;String literal&quot;!! this post is pretty good!</description>
		<content:encoded><![CDATA[<p>hey guys why did u call Sring litral to a &#8220;thing&#8221; that is not an &#8220;String literal&#8221;!! this post is pretty good!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Quiring</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-138</link>
		<dc:creator>Sam Quiring</dc:creator>
		<pubDate>Fri, 12 Mar 2010 15:43:02 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-138</guid>
		<description>String.hashCode() returns a value computed from the characters in the string, not the address of the object.</description>
		<content:encoded><![CDATA[<p>String.hashCode() returns a value computed from the characters in the string, not the address of the object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Satya Pavan Kumar</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-137</link>
		<dc:creator>Satya Pavan Kumar</dc:creator>
		<pubDate>Fri, 05 Mar 2010 17:11:37 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-137</guid>
		<description>thank u for providing this concept. i have doubt in this concept . i am writing two program differently 
program 1
class Test{
public static void main(String args[])
{
 int i;
String s1=&quot;Hello&quot;;
String s2=&quot;Hello&quot;;
String s3=new String(&quot;Hello&quot;);
String s4=new String(&quot;Hello&quot;);
i=s1.hashCode();
System.out.println(&quot;String s1-&gt;&quot;+i);  //365478
i=s2.hashCode();
System.out.println(&quot;String s2-&gt;&quot;+i); //365478
i=s3.hashCode();
System.out.println(&quot;String s3-&gt;&quot;+i); //365478
i=s4.hashCode();
System.out.println(&quot;String s4-&gt;&quot;+i); //365478
}
}

That comment is output. that means all hashcode are same .that mean entire content with respect heap and string constant pool are maintain single hashcode. If similar content is available w.r.t to heap as well as string constant pool it is pointed to single hashcode.

ok
 
observe this program

class Test{
public static void main(String args[])
{
String s1=&quot;hello&quot;;
String s2=&quot;hello&quot;;
String s3=new String(&quot;hello&quot;);
String s4=new String(&quot;hello&quot;);
System.out.println(&quot;w.r.t to heap &amp; string constant pool&quot;);
if(s1==s3)
System.out.println(&quot;String s1 is equal to s&quot;);
else
System.out.println(&quot;String s1 is not equals to s&quot;);  // this line executes 
System.out.println(&quot;w.r.t  string constant pool&quot;);
if(s2==s1)
System.out.println(&quot;String s1 is equal to s&quot;);  // this line executes 
else
System.out.println(&quot;String s1 is not equals to s&quot;);
System.out.println(&quot;w.r.t to heap &quot;);
if(s3==s4)
System.out.println(&quot;String s1 is equal to s&quot;);
else
System.out.println(&quot;String s1 is not equals to s&quot;);   // this line executes 
}
}

Observing this two program i got confused . plz clarify this doubt</description>
		<content:encoded><![CDATA[<p>thank u for providing this concept. i have doubt in this concept . i am writing two program differently<br />
program 1<br />
class Test{<br />
public static void main(String args[])<br />
{<br />
 int i;<br />
String s1=&#8221;Hello&#8221;;<br />
String s2=&#8221;Hello&#8221;;<br />
String s3=new String(&#8220;Hello&#8221;);<br />
String s4=new String(&#8220;Hello&#8221;);<br />
i=s1.hashCode();<br />
System.out.println(&#8220;String s1-&gt;&#8221;+i);  //365478<br />
i=s2.hashCode();<br />
System.out.println(&#8220;String s2-&gt;&#8221;+i); //365478<br />
i=s3.hashCode();<br />
System.out.println(&#8220;String s3-&gt;&#8221;+i); //365478<br />
i=s4.hashCode();<br />
System.out.println(&#8220;String s4-&gt;&#8221;+i); //365478<br />
}<br />
}</p>
<p>That comment is output. that means all hashcode are same .that mean entire content with respect heap and string constant pool are maintain single hashcode. If similar content is available w.r.t to heap as well as string constant pool it is pointed to single hashcode.</p>
<p>ok</p>
<p>observe this program</p>
<p>class Test{<br />
public static void main(String args[])<br />
{<br />
String s1=&#8221;hello&#8221;;<br />
String s2=&#8221;hello&#8221;;<br />
String s3=new String(&#8220;hello&#8221;);<br />
String s4=new String(&#8220;hello&#8221;);<br />
System.out.println(&#8220;w.r.t to heap &amp; string constant pool&#8221;);<br />
if(s1==s3)<br />
System.out.println(&#8220;String s1 is equal to s&#8221;);<br />
else<br />
System.out.println(&#8220;String s1 is not equals to s&#8221;);  // this line executes<br />
System.out.println(&#8220;w.r.t  string constant pool&#8221;);<br />
if(s2==s1)<br />
System.out.println(&#8220;String s1 is equal to s&#8221;);  // this line executes<br />
else<br />
System.out.println(&#8220;String s1 is not equals to s&#8221;);<br />
System.out.println(&#8220;w.r.t to heap &#8220;);<br />
if(s3==s4)<br />
System.out.println(&#8220;String s1 is equal to s&#8221;);<br />
else<br />
System.out.println(&#8220;String s1 is not equals to s&#8221;);   // this line executes<br />
}<br />
}</p>
<p>Observing this two program i got confused . plz clarify this doubt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naresh Hode</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-131</link>
		<dc:creator>Naresh Hode</dc:creator>
		<pubDate>Fri, 29 Jan 2010 11:24:07 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-131</guid>
		<description>in this case also it is giving true</description>
		<content:encoded><![CDATA[<p>in this case also it is giving true</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vawani sankar pati</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-43</link>
		<dc:creator>Vawani sankar pati</dc:creator>
		<pubDate>Tue, 11 Aug 2009 10:52:41 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-43</guid>
		<description>hai  guy

look at  this  code some body  asked  abt  it

String s1 = “abc”;
String s2 = “ab”;
s2 = s2 + “c”;
if (s1 == s2)
System.out.println(”Equal”);
else
System.out.println(”false”);


ok  this  will show  false
because when u  are  trying to add  to  string  a  new  object  will  be  created so  the principle given on  the  top  will  work now, as it  will  create  a  object  in the heap and  the  heap  object  refrence  will be  given  back  so  the s1  and  s2  will  not  at  the  same  address,so  it will show  u  false  but  if  u  want  to  refer  to  the  &quot;abc&quot; in the  string  constant pool  then  you  can  use  the  &quot;intern()&quot; method  as  follows  so  both  will  refer  to  same  address
String s1=&quot;abc&quot;;
String s2=&quot;ab&quot;;
s2=s2+&quot;c&quot;;
s2=s2.intern();
if(s1==s2)
{
	System.out.println(&quot;true&quot;);
}
else
{
	System.out.println(&quot;false&quot;);

}


regards
vawani S  pati</description>
		<content:encoded><![CDATA[<p>hai  guy</p>
<p>look at  this  code some body  asked  abt  it</p>
<p>String s1 = “abc”;<br />
String s2 = “ab”;<br />
s2 = s2 + “c”;<br />
if (s1 == s2)<br />
System.out.println(”Equal”);<br />
else<br />
System.out.println(”false”);</p>
<p>ok  this  will show  false<br />
because when u  are  trying to add  to  string  a  new  object  will  be  created so  the principle given on  the  top  will  work now, as it  will  create  a  object  in the heap and  the  heap  object  refrence  will be  given  back  so  the s1  and  s2  will  not  at  the  same  address,so  it will show  u  false  but  if  u  want  to  refer  to  the  &#8220;abc&#8221; in the  string  constant pool  then  you  can  use  the  &#8220;intern()&#8221; method  as  follows  so  both  will  refer  to  same  address<br />
String s1=&#8221;abc&#8221;;<br />
String s2=&#8221;ab&#8221;;<br />
s2=s2+&#8221;c&#8221;;<br />
s2=s2.intern();<br />
if(s1==s2)<br />
{<br />
	System.out.println(&#8220;true&#8221;);<br />
}<br />
else<br />
{<br />
	System.out.println(&#8220;false&#8221;);</p>
<p>}</p>
<p>regards<br />
vawani S  pati</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abhiroop</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-42</link>
		<dc:creator>abhiroop</dc:creator>
		<pubDate>Wed, 04 Feb 2009 17:26:19 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-42</guid>
		<description>sorry
in the above  post read nikhil as  Niks..</description>
		<content:encoded><![CDATA[<p>sorry<br />
in the above  post read nikhil as  Niks..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abhiroop</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-41</link>
		<dc:creator>abhiroop</dc:creator>
		<pubDate>Wed, 04 Feb 2009 17:24:32 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-41</guid>
		<description>@------Niks Says:
---------May 2, 2008 at 12:44 am
hi nikhil
String s2 = s2;
this line wont compiled
make it String s2 = s1;then evrything will work nd giv result
true
true</description>
		<content:encoded><![CDATA[<p>@&#8212;&#8212;Niks Says:<br />
&#8212;&#8212;&#8212;May 2, 2008 at 12:44 am<br />
hi nikhil<br />
String s2 = s2;<br />
this line wont compiled<br />
make it String s2 = s1;then evrything will work nd giv result<br />
true<br />
true</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abhiroop</title>
		<link>http://technote.wsjoung.com/2006/11/26/string-constant-pool/comment-page-1/#comment-40</link>
		<dc:creator>abhiroop</dc:creator>
		<pubDate>Wed, 04 Feb 2009 17:17:54 +0000</pubDate>
		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/26/string-constant-pool/#comment-40</guid>
		<description>@  Munish Gogna Says:
     August 28, 2007 at 6:20 am
  hi manish.as u r taking strings inside double quotes so they become constants ..so s2 = s2 + “c”  this wont wrk..
or change the class .. make it StringBuilder there u can make modification in the string itself</description>
		<content:encoded><![CDATA[<p>@  Munish Gogna Says:<br />
     August 28, 2007 at 6:20 am<br />
  hi manish.as u r taking strings inside double quotes so they become constants ..so s2 = s2 + “c”  this wont wrk..<br />
or change the class .. make it StringBuilder there u can make modification in the string itself</p>
]]></content:encoded>
	</item>
</channel>
</rss>

