<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Raghavan&#039;s WikiSite - new forum threads</title>
		<link>http://raghavan.wikidot.com/forum/start</link>
		<description>Threads in forums of the site &quot;Raghavan&#039;s WikiSite&quot; - Sharing of thoughts...</description>
				<copyright></copyright>
		<lastBuildDate></lastBuildDate>
		
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-37967</guid>
				<title>how many strings are created?</title>
				<link>http://raghavan.wikidot.com/forum/t-37967/how-many-strings-are-created</link>
				<description>usual question present in scjp 1.4 exam when a set of string referencs are dealt with some objects..</description>
				<pubDate>Mon, 28 Jan 2008 18:31:41 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>Reference javaranch thread -&gt; <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=042205&amp;p=1">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=042205&amp;p=1</a></p> </div> <p>How many String Objects are created when executing the following code?</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-number">11</span><span class="hl-code">. </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">makinStrings</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-number">12</span><span class="hl-code">. </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">s</span><span class="hl-code"> = </span><span class="hl-quotes">"</span><span class="hl-string">Fred</span><span class="hl-quotes">"</span><span class="hl-code">; </span><span class="hl-comment">// this line creates one object</span><span class="hl-code"> </span><span class="hl-number">13</span><span class="hl-code">. </span><span class="hl-identifier">s</span><span class="hl-code"> = </span><span class="hl-identifier">s</span><span class="hl-code"> + </span><span class="hl-quotes">"</span><span class="hl-string">47</span><span class="hl-quotes">"</span><span class="hl-code">; </span><span class="hl-comment">// this line creates two objects</span><span class="hl-code"> </span><span class="hl-number">14</span><span class="hl-code">. </span><span class="hl-identifier">s</span><span class="hl-code"> = </span><span class="hl-identifier">s</span><span class="hl-code">.</span><span class="hl-identifier">substring</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// this line creates one object</span><span class="hl-code"> </span><span class="hl-number">15</span><span class="hl-code">. </span><span class="hl-identifier">s</span><span class="hl-code"> = </span><span class="hl-identifier">s</span><span class="hl-code">.</span><span class="hl-identifier">toUpperCase</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">// this line creates one object</span><span class="hl-code"> </span><span class="hl-number">16</span><span class="hl-code">. </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">s</span><span class="hl-code">.</span><span class="hl-identifier">toString</span><span class="hl-brackets">()</span><span class="hl-code"> ; </span><span class="hl-number">17</span><span class="hl-code">. </span><span class="hl-brackets">}</span> </pre></div> </div> <p>Though many ranchers answered already (a seems to be correct answer is 3), the perfect explanation<br /> given by <strong>Jim Yingst</strong> is here:</p> <p>Unfortunately this isn't a very good test question, and it's not representative of the questions you'll get on the real exam. The problem is that the compile-time constants "Fred" and "47" have special behavior that's more subtle then you need to know for the exam, and it's ambiguous to say that they were "created" in the code. What happens is, String objects for "Fred" and "47" are created when the class is loaded, not when the method is run. And if the method is run more than once, "Fred" and "47" aren't recreated - they just get re-used. So, if you run the method just once and exit, you get:</p> <p>"Fred", "47" created when class is loaded.<br /> "Fred47", "ed47", "ED47" created when the method is run.</p> <p>That's 5 strings total.</p> <p>If you run the method 5 times, you get</p> <p>"Fred", "47" created when class is loaded.<br /> "Fred47", "ed47", "ED47" created when the method is run the 1st time<br /> "Fred47", "ed47", "ED47" created when the method is run the 2nd time<br /> "Fred47", "ed47", "ED47" created when the method is run the 3rd time<br /> "Fred47", "ed47", "ED47" created when the method is run the 4th time<br /> "Fred47", "ed47", "ED47" created when the method is run the 5th time</p> <p>That's 17 strings over 5 method calls.</p> <p>Additionally, in the event that some other code has used the constants "Fred" or "47" before the method is called, those strings won't be recreated at all. So it's possible that the above code could create just 3 objects when run once, and 15 object when run 5 times.</p> <p>Based on all this, you can guarantee that at least three String objects are created when the method is run, and at most, five. I would say that three String objects are created in the method, and two may be caused to be created when the class is loaded.</p> <p>Ultimately I don't think there's any way to determine what the "best" answer is for this question because, the way it's phrased, it's ambiguous. I wouldn't worry too much about it. The real exam won't have a question like this anyway.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-37292</guid>
				<title>which one will it invoke? base or derived?</title>
				<link>http://raghavan.wikidot.com/forum/t-37292/which-one-will-it-invoke-base-or-derived</link>
				<description>will it invoke the method in base class or derived class? also the order/timings of initialization of members in each class..</description>
				<pubDate>Thu, 24 Jan 2008 18:43:58 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>JavaRanch Reference Thread -&gt; <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=025141&amp;p=1">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=025141&amp;p=1</a></p> </div> <p>Question by <strong>Jose Campana</strong>:<br /> Analyze this case and please tell me Why the method with the comment <strong>//This method</strong> is never reached.</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Base</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">value</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-identifier">Base</span><span class="hl-brackets">(){</span><span class="hl-code"> </span><span class="hl-identifier">addValue</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">addValue</span><span class="hl-brackets">(){</span><span class="hl-code"> </span><span class="hl-comment">//This method</span><span class="hl-code"> </span><span class="hl-identifier">value</span><span class="hl-code"> += </span><span class="hl-number">10</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">getValue</span><span class="hl-brackets">(){</span><span class="hl-code"> </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">value</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Derived</span><span class="hl-code"> </span><span class="hl-reserved">extends</span><span class="hl-code"> </span><span class="hl-identifier">Base</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-identifier">Derived</span><span class="hl-brackets">(){</span><span class="hl-code"> </span><span class="hl-identifier">addValue</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">addValue</span><span class="hl-brackets">(){</span><span class="hl-code"> </span><span class="hl-identifier">value</span><span class="hl-code"> += </span><span class="hl-number">20</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Test3</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">){</span><span class="hl-code"> </span><span class="hl-identifier">Base</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">Derived</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-identifier">b</span><span class="hl-code">.</span><span class="hl-identifier">getValue</span><span class="hl-brackets">())</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span> </pre></div> </div> <p>The preceding code prints out 40. And of course, that means that the method addValue() in class Base() never executes.</p> <p>When inside Base() constructor, it calls the addValue() method, and it uses the one defined in class Derived. but the Question is:</p> <p><strong>WHY ?</strong></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-37244</guid>
				<title>are constructors really constructing?</title>
				<link>http://raghavan.wikidot.com/forum/t-37244/are-constructors-really-constructing</link>
				<description>constructors are NOT just to construct. they infact MODIFY or UPDATE the instance values!!</description>
				<pubDate>Thu, 24 Jan 2008 13:53:18 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>JavaRanch Ref thread -&gt; <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=011778">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=011778</a></p> </div> <p>Reply from <strong>Mike Gershman</strong>:</p> <p>In my view, constructors are misnamed - they alter already initialized variables in already created objects, based on the arguments passed to the constructors in the <strong>new</strong> syntax and on other sources.</p> <p>Memory allocation for an object is done by the JVM based on information in the <strong>class</strong> object. The JVM also initializes the instance variables to their default values. Next, the variable initializers and the initialization blocks are executed together in the order they appear in the source code. They can alter the values of the variables. <em>Finally, the constructors get a chance to modify the variables once again</em>. At that point, the object is considered fully initialized and <strong>final</strong> variables can no longer be altered.</p> <p>I have not considered the implications of <strong>super()</strong> here.</p> <p>BTW, constructors are not methods. Unlike methods, constructors can alter <strong>final</strong> variables. There are constraints on constructors that don't apply to methods. And you can't call a constructor directly.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-36907</guid>
				<title>how many objects are created (wrt inheritance)</title>
				<link>http://raghavan.wikidot.com/forum/t-36907/how-many-objects-are-created-wrt-inheritance</link>
				<description>Generally when inheritance is in picture, how many objects are *acutally* getting created? Is it one or two? basically this qn comes when a subclass object has access to its superclass instance variables as well...</description>
				<pubDate>Wed, 23 Jan 2008 13:51:31 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>[[toc]]</p> <h1><span>Question1: Inheritance - how many objects created???</span></h1> <div class="wiki-note"> <p>Reference Thead from JavaRanch: <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=024491">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=024491</a></p> </div> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-reserved">extends</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Try</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">){</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">obj</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-brackets">()</span><span class="hl-code"> ; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span> </pre></div> </div> <p>Question from Original Poster <em>Imran Mehrenali</em>:</p> <p>1) In the above code, when i create an object of Class B, how many objects will get created? Only one object of class B that has 2 members (a and b) or two objects - one of class A that has one member (a), and another of class B that also has only member (b) but can directly acccess the member (a) beloning to object of class A.</p> <p>2) I was about to ask how many constructors will be called, but have tried this out myself in a java program and have found that 2 constructors (A() and B()) are called while creating an object of class B.<br /> Does this mean that 2 objects are created.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-36906</guid>
				<title>how many objects are created (wrt inheritance)</title>
				<link>http://raghavan.wikidot.com/forum/t-36906/how-many-objects-are-created-wrt-inheritance</link>
				<description>Generally when inheritance is in picture, how many objects are *acutally* getting created? Is it one or two? basically this qn comes when a subclass object has access to its superclass instance variables as well...</description>
				<pubDate>Wed, 23 Jan 2008 13:51:01 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>[[toc]]</p> <h1><span>Question1: Inheritance - how many objects created???</span></h1> <div class="wiki-note"> <p>Reference Thead from JavaRanch: <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=024491">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=024491</a></p> </div> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-reserved">extends</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Try</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">){</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">obj</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-brackets">()</span><span class="hl-code"> ; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span> </pre></div> </div> <p>Question from Original Poster <em>Imran Mehrenali</em>:</p> <p>1) In the above code, when i create an object of Class B, how many objects will get created? Only one object of class B that has 2 members (a and b) or two objects - one of class A that has one member (a), and another of class B that also has only member (b) but can directly acccess the member (a) beloning to object of class A.</p> <p>2) I was about to ask how many constructors will be called, but have tried this out myself in a java program and have found that 2 constructors (A() and B()) are called while creating an object of class B.<br /> Does this mean that 2 objects are created.</p> <p><em>Reply</em> from Ernest Friedman-Hill<strong>, <em>Sheriff and Author</em> in JavaRanch:<br /> The answer is **just one object</strong>.</p> <p>An instance of B includes an A "part". Imagine a piece of paper 1 inch square, call it A. Then think of a B object as a piece of paper 2 inches square, with a 1-inch square drawn onto it labeled "A". The A constructor is called to initialize the A part of the single B object.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-36279</guid>
				<title>doubt on notification of Threads</title>
				<link>http://raghavan.wikidot.com/forum/t-36279/doubt-on-notification-of-threads</link>
				<description>This is not a question of an official exam. It is a question extracted from the certification book named &quot;SCJP Sun Certified Programmer for Java 5 Study Guide&quot;, and it appears on the page 750. (from JavaRanch Post)</description>
				<pubDate>Sun, 20 Jan 2008 08:48:54 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>JavaRanch reference thread -&gt; <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=043103">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=043103</a></p> </div> <br /> I thought that when a thread calls wait() over an object, and then someother thread calls notify(), the first one leaved the "waiting" state, and goes to the "locked" state, waiting for the second one to leave the synchronized region, and finally goes to "runnable". <p>But just when i thought that it was fairly clear, I found a question like this one:</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-identifier">Assume</span><span class="hl-code"> </span><span class="hl-identifier">the</span><span class="hl-code"> </span><span class="hl-identifier">following</span><span class="hl-code"> </span><span class="hl-identifier">method</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">properly</span><span class="hl-code"> </span><span class="hl-reserved">synchronized</span><span class="hl-code"> </span><span class="hl-identifier">and</span><span class="hl-code"> </span><span class="hl-identifier">called</span><span class="hl-code"> </span><span class="hl-identifier">from</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-identifier">thread</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-code"> </span><span class="hl-identifier">on</span><span class="hl-code"> </span><span class="hl-identifier">an</span><span class="hl-code"> </span><span class="hl-identifier">object</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code">: </span><span class="hl-identifier">wait</span><span class="hl-brackets">(</span><span class="hl-number">2000</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">After</span><span class="hl-code"> </span><span class="hl-identifier">calling</span><span class="hl-code"> </span><span class="hl-reserved">this</span><span class="hl-code"> </span><span class="hl-identifier">method</span><span class="hl-code">, </span><span class="hl-identifier">when</span><span class="hl-code"> </span><span class="hl-identifier">will</span><span class="hl-code"> </span><span class="hl-identifier">the</span><span class="hl-code"> </span><span class="hl-identifier">thread</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-code"> </span><span class="hl-identifier">become</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-identifier">candidate</span><span class="hl-code"> </span><span class="hl-identifier">to</span><span class="hl-code"> </span><span class="hl-identifier">get</span><span class="hl-code"> </span><span class="hl-identifier">another</span><span class="hl-code"> </span><span class="hl-identifier">turn</span><span class="hl-code"> </span><span class="hl-identifier">at</span><span class="hl-code"> </span><span class="hl-identifier">the</span><span class="hl-code"> </span><span class="hl-identifier">CPU</span><span class="hl-code">? </span><span class="hl-identifier">A</span><span class="hl-code">. </span><span class="hl-identifier">After</span><span class="hl-code"> </span><span class="hl-identifier">object</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">notified</span><span class="hl-code">, </span><span class="hl-identifier">or</span><span class="hl-code"> </span><span class="hl-identifier">after</span><span class="hl-code"> </span><span class="hl-identifier">two</span><span class="hl-code"> </span><span class="hl-identifier">seconds</span><span class="hl-code">. </span><span class="hl-identifier">B</span><span class="hl-code">. </span><span class="hl-identifier">After</span><span class="hl-code"> </span><span class="hl-identifier">the</span><span class="hl-code"> </span><span class="hl-identifier">lock</span><span class="hl-code"> </span><span class="hl-identifier">on</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">released</span><span class="hl-code">, </span><span class="hl-identifier">or</span><span class="hl-code"> </span><span class="hl-identifier">after</span><span class="hl-code"> </span><span class="hl-identifier">two</span><span class="hl-code"> </span><span class="hl-identifier">seconds</span><span class="hl-code">. </span><span class="hl-identifier">C</span><span class="hl-code">. </span><span class="hl-identifier">Two</span><span class="hl-code"> </span><span class="hl-identifier">seconds</span><span class="hl-code"> </span><span class="hl-identifier">after</span><span class="hl-code"> </span><span class="hl-identifier">object</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">notified</span><span class="hl-code">. </span><span class="hl-identifier">D</span><span class="hl-code">. </span><span class="hl-identifier">Two</span><span class="hl-code"> </span><span class="hl-identifier">seconds</span><span class="hl-code"> </span><span class="hl-identifier">after</span><span class="hl-code"> </span><span class="hl-identifier">lock</span><span class="hl-code"> </span><span class="hl-identifier">B</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">released</span><span class="hl-code">. </span><span class="hl-identifier">Which</span><span class="hl-code"> </span><span class="hl-identifier">one</span><span class="hl-code"> </span><span class="hl-identifier">is</span><span class="hl-code"> </span><span class="hl-identifier">the</span><span class="hl-code"> </span><span class="hl-identifier">correct</span><span class="hl-code">?</span> </pre></div> </div> <p>The books says that A, but I simply don't get it, to me, there are no correct question.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-14914</guid>
				<title>how many public classes in a .java file allowed?</title>
				<link>http://raghavan.wikidot.com/forum/t-14914/how-many-public-classes-in-a-java-file-allowed</link>
				<description></description>
				<pubDate>Thu, 26 Jul 2007 15:58:15 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>In a java file how many public classes can be present?</p> <p>The answer is ONLY ONE. But most refined answer is <strong>Only one Public Class</strong>, since there may be public nested class inside the same .java file which is legally allowed.</p> <p>source : A Javaranch thread -&gt; <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=023337">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=33&amp;t=023337</a></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-13396</guid>
				<title>what is the output? (wrt to post increment operator)</title>
				<link>http://raghavan.wikidot.com/forum/t-13396/what-is-the-output-wrt-to-post-increment-operator</link>
				<description>post increment operator in method return value</description>
				<pubDate>Tue, 10 Jul 2007 07:45:22 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>Reference from the JavaRanch thread -&gt;</p> <p><a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=039606">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=039606</a></p> </div> <p>What is the output of the below program?</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Increment</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">getNum</span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">x</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">x</span><span class="hl-code">++; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-identifier">getNum</span><span class="hl-brackets">(</span><span class="hl-number">44</span><span class="hl-brackets">))</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span> </pre></div> </div> <p>The options for the answers are :</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-number">44</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-number">45</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">c</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-number">46</span> </pre></div> </div> <p><strong>Output:</strong></p> <p>The answer is :</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-number">44</span> </pre></div> </div> <p><strong>Reason with Explanation by Henry:</strong><br /> When the getNum() method calculates to value to be returned, it will use the value of x before it gets incremented (post increment means the value of x will be incremented after it has been used).</p> <p>Sure, the value of x will be incremented, but the value to be returned has already been calculated by then.</p> <p><strong>Reason with Explanation by me:</strong><br /> Its more or less the same of assignment.</p> <p>When you have</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">x</span><span class="hl-code"> = </span><span class="hl-number">2</span><span class="hl-code">; </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">y</span><span class="hl-code"> = </span><span class="hl-identifier">x</span><span class="hl-code">++; </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">x = </span><span class="hl-quotes">"</span><span class="hl-code">+</span><span class="hl-identifier">x</span><span class="hl-code">+</span><span class="hl-quotes">"</span><span class="hl-string">, y = </span><span class="hl-quotes">"</span><span class="hl-code">+</span><span class="hl-identifier">y</span><span class="hl-brackets">)</span><span class="hl-code">;</span> </pre></div> </div> <p>The above SOP will print the value as:</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-identifier">x</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">, </span><span class="hl-identifier">y</span><span class="hl-code"> = </span><span class="hl-number">2</span> </pre></div> </div> <p>Why? and How? The value of x is being used in the operation first (ie., assignment). After the appropriate operation (here assignment) is done, the value of x is incremented! Right?</p> <p>The same holds good in terms of your method as well. <strong>The value of x is being used for its operation (here, return value) first and then its incremented</strong>. But that does NOT mean that the updated value of x (incremented here) will be reflected back because the updation happens only after the value of x is being used (returned).</p> <p>Hope this helps!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-12372</guid>
				<title>how many objects (wrt Strings)</title>
				<link>http://raghavan.wikidot.com/forum/t-12372/how-many-objects-wrt-strings</link>
				<description>how many objects are created when this SOP is executed</description>
				<pubDate>Tue, 26 Jun 2007 07:19:22 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="wiki-note"> <p>famous question on how many objects are created with respect to Strings (and literals).<br /> Reference from javaranch: <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=039347">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=24&amp;t=039347</a><br /> (though there were similar threads for the same post, this one is recent)</p> </div> <div class="code"> <div class="hl-main"> <pre> <span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">s1</span><span class="hl-code"> = </span><span class="hl-quotes">"</span><span class="hl-string">spring </span><span class="hl-quotes">"</span><span class="hl-code">; </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">s2</span><span class="hl-code"> = </span><span class="hl-identifier">s1</span><span class="hl-code"> + </span><span class="hl-quotes">"</span><span class="hl-string">summer </span><span class="hl-quotes">"</span><span class="hl-code">; </span><span class="hl-identifier">s1</span><span class="hl-code">.</span><span class="hl-identifier">concat</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">fall </span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">s2</span><span class="hl-code">.</span><span class="hl-identifier">concat</span><span class="hl-brackets">(</span><span class="hl-identifier">s1</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">s1</span><span class="hl-code"> += </span><span class="hl-quotes">"</span><span class="hl-string">winter </span><span class="hl-quotes">"</span><span class="hl-code">; </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-identifier">s1</span><span class="hl-code"> + </span><span class="hl-quotes">"</span><span class="hl-string"> </span><span class="hl-quotes">"</span><span class="hl-code"> + </span><span class="hl-identifier">s2</span><span class="hl-brackets">)</span><span class="hl-code">;</span> </pre></div> </div> <p><strong>Answer:</strong></p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-identifier">a</span><span class="hl-code">. </span><span class="hl-number">8</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code">. </span><span class="hl-number">6</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code">. </span><span class="hl-number">10</span><span class="hl-code"> </span><span class="hl-identifier">d</span><span class="hl-code">. </span><span class="hl-number">4</span> </pre></div> </div> <p>Answer is <strong>c. 10</strong></p> <p><strong>Explanation</strong><br /> 1 object ("spring") created in line 1<br /> 2 objects ("springsummer" and "summer") in line 2<br /> 2 objects ("springfall" and "fall") in line 3<br /> 1 object ("springsummerspring") in line 4<br /> 2 objects ("springwinter" and "winter") in line 5<br /> 2 objects ("spring "(with space at end) and "spring springsummer") in line 6</p> <p>So in total there are <strong>ten</strong> objects</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://raghavan.wikidot.com/forum/t-11999</guid>
				<title>how many objects are created (wrt arrays)</title>
				<link>http://raghavan.wikidot.com/forum/t-11999/how-many-objects-are-created-wrt-arrays</link>
				<description></description>
				<pubDate>Thu, 21 Jun 2007 10:23:19 +0000</pubDate>
				<wikidot:authorName>itsraghz</wikidot:authorName>				<wikidot:authorUserId>20174</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>How many objects are created after executing the statements individually.</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-types">int</span><span class="hl-brackets">[][]</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-identifier">dArray</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">][]</span><span class="hl-code">;</span> </pre></div> </div> <div class="code"> <div class="hl-main"> <pre> <span class="hl-types">int</span><span class="hl-brackets">[][]</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-identifier">dArray</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-brackets">[</span><span class="hl-number">3</span><span class="hl-brackets">][</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code">;</span> </pre></div> </div> <p><strong>Pick the correct answer from the options given below:</strong></p> <ol> <li>(1,1)</li> <li>(2,2)</li> <li>(1,4)</li> <li>(2,4)</li> <li>(2,3)</li> </ol> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>