<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VKpedia &#187; Java</title>
	<atom:link href="http://www.vkpedia.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vkpedia.com</link>
	<description>a repository of (mostly) useless information, since 2005</description>
	<lastBuildDate>Mon, 14 Nov 2011 02:53:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Copying Maps in Java</title>
		<link>http://www.vkpedia.com/2009/05/11/copying-maps-in-java/</link>
		<comments>http://www.vkpedia.com/2009/05/11/copying-maps-in-java/#comments</comments>
		<pubDate>Mon, 11 May 2009 23:57:25 +0000</pubDate>
		<dc:creator>Vijay Narayanan</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[object cloning]]></category>

		<guid isPermaLink="false">http://www.vkpedia.com/?p=1182</guid>
		<description><![CDATA[Consider this. You have a list* of maps. You want to replicate the list a specified number of times. For example, if the list has two maps, and you want to create from this list another list that contains six maps. The constraint is that you have to write your own method, and you must <a href='http://www.vkpedia.com/2009/05/11/copying-maps-in-java/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Consider this. You have a list<strong>*</strong> of maps. You want to replicate the list a specified number of times. For example, if the list has two maps, and you want to create from this list another list that contains six maps. The constraint is that you have to write your own method, and you must not use Java&#8217;s object cloning feature.</p>
<p>The first approach is simple. You take each map in the list and add it to the list a specified number of times (n-1 times, if n is multiplier). If this is methodized, the code would look something like this.</p>
<div id="attachment_1183" class="wp-caption aligncenter" style="width: 589px"><img class="size-full wp-image-1183  " title="firstcut" src="http://www.vkpedia.com/wp-content/uploads/2009/05/firstcut.jpg" alt="firstcut" width="579" height="252" /><p class="wp-caption-text">A first-cut, defective solution</p></div>
<p>Basically, we add every map from the input list into a temporary list, and then add back to the original list each map &#8220;n&#8221; (or, in this case, &#8220;size&#8221;) number of times. And all is well.</p>
<p>Well? Think again. The above method will fail&#8230; miserably. It will, of course, return a list of maps that is n times bigger. But its utility ends there. If you work with the list, you will find that it behaves strangely. Modifying some element in the list will also modify some other element. Why does this happen?</p>
<p>In our ingenious first-cut method, we have add the same map multiple times to the list. What happens internally is that the list contains multiple references to the same map (or set of maps). So any change to one map in the resultant list will also modify all its replicas, since each map reference points to the same map. In essence, we have performed a shallow copy.</p>
<p>The correct approach (and I do not claim that this is the best) is to modify the map-copy portion of the above method (the second for-loop) as follows. Iterate through the map entries and copy each entry, i.e. key-value pair, to a temporary map, and when done, add this map to the list. This way, you are not left with references to a single map. Each map in the list is its own object.</p>
<div id="attachment_1184" class="wp-caption aligncenter" style="width: 589px"><a href="http://www.vkpedia.com/wp-content/uploads/2009/05/second-cut.jpg"><img class="size-full wp-image-1184  " title="second-cut" src="http://www.vkpedia.com/wp-content/uploads/2009/05/second-cut.jpg" alt="second-cut" width="579" height="445" /></a><p class="wp-caption-text">A better, more correct solution</p></div>
<p style="text-align: center;"> </p>
<p><strong>Update</strong></p>
<p>The purpose of the above was specifically to illustrate the concept of object references. The point is, you cannot copy objects in Java the way you copy simple data types. The more straightforward solution to the above (<a href="http://www.vkpedia.com/2009/05/11/copying-maps-in-java/comment-page-1/#comment-254646">as Thejo points out</a>) is to use the constructor of the HashMap (or another map implementation) class. Under the hood, however, the constructor does the same thing as we have done &#8212; it iterates through the map entries and copies each key-value pair of the passed map object to a new map object.</p>
<p>Here is how the method will look when refactored.</p>
<div id="attachment_1189" class="wp-caption aligncenter" style="width: 591px"><a href="http://www.vkpedia.com/wp-content/uploads/2009/05/third-cut.jpg"><img class="size-full wp-image-1189" title="third-cut" src="http://www.vkpedia.com/wp-content/uploads/2009/05/third-cut.jpg" alt="third-cut" width="581" height="231" /></a><p class="wp-caption-text">An easier, more straight-forward approach</p></div>
<p>P.S.: Looking back, all this sounds very intuitive. Yet, intuition is not the first faculty that one can command when frantically debugging code on a Sunday evening. </p>
<p><strong>*</strong> I have used list and map instead of List and Map. This is just for explanatory purposes. If you are a purist, please accept my sincerest apologies.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=100558576708178&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.vkpedia.com/2009/05/11/copying-maps-in-java/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.vkpedia.com/2009/05/11/copying-maps-in-java/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>NetBeans turns 10!</title>
		<link>http://www.vkpedia.com/2008/10/20/netbeans-turns-10/</link>
		<comments>http://www.vkpedia.com/2008/10/20/netbeans-turns-10/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 18:19:27 +0000</pubDate>
		<dc:creator>Vijay Narayanan</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[Sun Microsystems]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.vkpedia.com/?p=801</guid>
		<description><![CDATA[If you are a Java developer looking for a powerful IDE that can get you started in no time, you should look no further than NetBeans. Why? NetBeans is free and open-source. A lot of people list preference with open-source software just because it is free. But beyond just the cost, there is a lot <a href='http://www.vkpedia.com/2008/10/20/netbeans-turns-10/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you are a Java developer looking for a powerful IDE that can get you started in no time, you should look no further than <a href="http://www.netbeans.org">NetBeans</a>.</p>
<p>Why?</p>
<ul>
<li><strong>NetBeans is free and open-source</strong>. A lot of people list preference with open-source software just because it is free. But beyond just the cost, there is a lot more to open-source software that is exciting and inviting. It means that a community of developers from across the world are pouring in their ideas with the sole intention of creating great software. Plus think of how much testing they can get done from folks who download their betas.</li>
<li><strong>NetBeans helps you hit the ground running</strong>. A month or so ago, I was giving an overview of Struts to my cousin. He wanted a short demo using Eclipse. However, we couldn&#8217;t configure Eclipse for Struts even after some concerted efforts at doing so. The plugins we found were found wanting. NetBeans made the task much easier, with its in-built support for Struts (and a host of other popular frameworks.) There is also support for GUI design, Java EE, PHP, Ruby, C++, the whole works; but yeah, you get the point.</li>
<li><strong>NetBeans comes as a full package</strong>. NetBeans comes pre-built with GlassFish and Apache Tomcat servers, and JavaDB. So, you don&#8217;t need to spend time trying to setup servers and databases just to get a simple Web application up and running. You can throw in MySQL into the mix as well.</li>
<li><strong>NetBeans is from Sun Microsystems</strong>. The Java guys. They are behind NetBeans. This is reassuring because whether you are a big business trying to adopt a new IDE for your development team or a developer who wants a full-featured IDE, you can trust a name like Sun to have a roadmap for the IDE. Plus they would be able to align IDE development to the developments in the language as well. One might have to mention MySQL again, as it is now a Sun product.</li>
<li><strong>NetBeans has a rich set of plugins</strong>. You betcha!</li>
</ul>
<p>So go ahead and give NetBeans, which turns 10 this week, a shot. You are sure to recommend it to all your friends!</p>
<p>P.S.: If you have been using NetBeans for a while, Sun Microsystems is offering a free beta of the Sun Certified Specialist NetBeans IDE exam. Here are the <a href="http://www.vkpedia.com/2008/10/01/free-sun-certification-exam/">SCSN exam details</a>.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=100558576708178&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.vkpedia.com/2008/10/20/netbeans-turns-10/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.vkpedia.com/2008/10/20/netbeans-turns-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Java down-unga!&#8221;</title>
		<link>http://www.vkpedia.com/2008/10/14/java-down-unga/</link>
		<comments>http://www.vkpedia.com/2008/10/14/java-down-unga/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 05:01:28 +0000</pubDate>
		<dc:creator>Vijay Narayanan</dc:creator>
				<category><![CDATA[Chennai]]></category>
		<category><![CDATA[Culture & Society]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[folk]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.vkpedia.com/?p=764</guid>
		<description><![CDATA[(Warning: Lotsa brackets, like this one.) Back in 2001-02 (ah, the good ol&#8217; days), when the stock markets recoiled after the dotcom bust and thousands of people found themselves out of a job in Silicon Valley, thousands of miles across the face of the earth, the impact was felt in Chennai. The great Indian IT <a href='http://www.vkpedia.com/2008/10/14/java-down-unga/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">(Warning: Lotsa brackets, like this one.)</span></p>
<p>Back in 2001-02 (ah, the good ol&#8217; days), when the stock markets recoiled after the dotcom bust and thousands of people found themselves out of a job in Silicon Valley, thousands of miles across the face of the earth, the impact was felt in Chennai. The great Indian IT boom 1.0 had ended, and this was the period before v2.0 commenced (the period when folks were recruited in hordes; the &#8220;Trespassers will be recruited&#8221; days).</p>
<p>At the turn of the <span style="text-decoration: line-through;">century</span> millennium, every Ram, Shyam and Hari was enrolled in a computer-training course. It didn&#8217;t matter what you did, what degree you were pursuing, what your life&#8217;s ambitions were etc. All that mattered was to enroll in the nearest NIIT or SSI centre (or something not that far off, if there were &#8220;incentives&#8221;).</p>
<p>These institutes were unbelievably good at marketing. They tapped into the general &#8220;Whatever you learn today is going to worthless tomorrow&#8221; belief. And added, &#8220;&#8230; but you must learn it from us nevertheless.&#8221; The ads in newspapers, and there were more ads than news content on most pages, teemed with TLAs and FLAs. TLA stands for Three Letter Acronym (which incidentally is a three letter abbreviation). So, if COM was the hot topic in 1999, it was DCOM in 2000, CORBA in 2001 and Coldfusion in 2002.</p>
<p>It didn&#8217;t matter what these meant; the rule was to be abstruse, condescending and inviting all at the same time.</p>
<p>But Java changed all that. Everyone&#8217;s son and daughter and neigbhor was learning Java. Soon, however, Java, as it was used in conversations, did not directly refer to the programming language that Sun Microsystems came out with. It morphed into more of a folk term.</p>
<p>People felt comfortable using the term Java. (Like you bring a girl home, and your mom frowns; but you tell her that her name is Gayatri, and frown turns to contented smile.) I guess the Tamil mind felt that C was too small a name for a serious programming language. C++ should have fit the bill, but for some reason, it escaped them. Maybe the additional &#8220;+&#8221; was off-putting. But somehow Java became the chosen term. It was what people on the street threw in the midst of a conversation to prove that they were also buzzword-compliant.</p>
<p>(Perhaps the crowing glory of the language came when the comedian Vivek included the language in his now-famous <em>ettu pulli kolam</em> dialogue &#8211; remember &#8220;atomic energy coupled with cosmic energy&#8221;?)</p>
<p>So, in 2002, I walk into the neighborhood saloon. (Didn&#8217;t I say, good ol&#8217; days?) It is Sunday morning, so there is a crowd, so I&#8217;m forced to wait in line and read <em>Dhina Thanthi</em>.</p>
<p>(Have you seen the folks reading <em>Dhina Thanthi</em> in a saloon? They are the unluckiest of the most unfortunate. They cannot get to lay their hands on the magazines; those are all taken; nobody is interested in the papers, and those with the papers are doing their best to peer into the magazine in the hands of the person sitting next to them, while actually giving an impression of reading the paper. They should be extra careful not to be caught in the act. <em>Yenda indha maanamketta pozhappu?</em>)</p>
<p>The person sitting next to me is an elderly gentleman. He also has a paper in hand, and is evidently not interested in it. So he turns to me and asks, &#8220;So what do you do?&#8221;</p>
<p>I tell him I study engineering. Like everyone else does, I don&#8217;t add.</p>
<p><strong>He:</strong> &#8220;Computer engineering?&#8221;</p>
<p><strong>I:</strong> &#8220;No, electronics.&#8221;</p>
<p><strong>He:</strong> &#8220;Nalladhu dhaan. Java down aayiduchunga!&#8221; (literally &#8220;That&#8217;s good. Java is down&#8221;; what he meant was &#8220;Java is out of demand.&#8221;)</p>
<p><strong>I:</strong> &#8220;Oh!&#8221; (I&#8217;m thinking if he understands fully what he is saying.)</p>
<p><strong>He:</strong> &#8220;Yes, my daughter studied Java. She is unable to find a job now.&#8221;</p>
<p><strong>I:</strong> &#8220;Sorry to hear that&#8221;, and the conversation peters out.</p>
<p>Friends, Chennai-<em>vasis</em>, now that we are in another downturn, do you hear stuff like this these days on the road, in the bus, in the saloon?</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=100558576708178&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.vkpedia.com/2008/10/14/java-down-unga/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.vkpedia.com/2008/10/14/java-down-unga/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Cafebabe</title>
		<link>http://www.vkpedia.com/2008/07/03/cafebabe/</link>
		<comments>http://www.vkpedia.com/2008/07/03/cafebabe/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 20:49:31 +0000</pubDate>
		<dc:creator>Vijay Narayanan</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[certification]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[SCJP]]></category>
		<category><![CDATA[Sun]]></category>

		<guid isPermaLink="false">http://www.vkpedia.com/?p=639</guid>
		<description><![CDATA[try { &#160;&#160;&#160;&#160;writeSunCertifiedJavaProgrammerExam(); } finally { &#160;&#160;&#160;clearExam(); } No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<p><code>try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;writeSunCertifiedJavaProgrammerExam();<br />
}<br />
finally {<br />
&nbsp;&nbsp;&nbsp;clearExam();<br />
}</code></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=100558576708178&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.vkpedia.com/2008/07/03/cafebabe/" layout="standard" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.vkpedia.com/2008/07/03/cafebabe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

