<?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>techtamasha.com &#187; Java</title>
	<atom:link href="http://www.techtamasha.com/category/java/feed" rel="self" type="application/rss+xml" />
	<link>http://www.techtamasha.com</link>
	<description>a new play everyday</description>
	<lastBuildDate>Fri, 13 Jan 2012 09:21:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Reducing the size of List in Java</title>
		<link>http://www.techtamasha.com/reducing-the-size-of-list-in-java/218</link>
		<comments>http://www.techtamasha.com/reducing-the-size-of-list-in-java/218#comments</comments>
		<pubDate>Sun, 26 Jun 2011 16:16:03 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[arraylist reduce size]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[list size reduce]]></category>
		<category><![CDATA[sublist]]></category>

		<guid isPermaLink="false">http://www.techtamasha.com/?p=218</guid>
		<description><![CDATA[I had a List that had around 70000 objects in it and I needed only the first 15000. I was about to create a new empty array list and iterate 15000 times over the current one in order to get a smaller list. That would have been a mess. I searched a bit and realized [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Freducing-the-size-of-list-in-java%2F218&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Reducing the size of List in Java" data-url="http://www.techtamasha.com/reducing-the-size-of-list-in-java/218" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I had a List that had around 70000 objects in it and I needed only the first 15000. I was about to create a new empty array list and iterate 15000 times over the current one in order to get a smaller list. That would have been a mess.</p>
<p>I searched a bit and realized there was an easier (and I&#8217;m hoping it&#8217;s more efficient) way to reduce the size of a list.</p>
<blockquote><p>//templist has 70000 objects in it</p>
<p>tempList.subList(15000 &#8211; 1, tempList.size()-1).clear();</p>
<p>//templist now has the first 15000 objects in it</p>
<p>//15000 &#8211; 1 because the positions start from 0</p>
<p>&nbsp;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/reducing-the-size-of-list-in-java/218/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fetch Multiple Objects by key in JDO using getObjectsById</title>
		<link>http://www.techtamasha.com/fetch-multiple-objects-by-key-in-jdo/209</link>
		<comments>http://www.techtamasha.com/fetch-multiple-objects-by-key-in-jdo/209#comments</comments>
		<pubDate>Wed, 22 Jun 2011 04:18:52 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Google Appengine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDO]]></category>
		<category><![CDATA[appengine getObjectsById error]]></category>
		<category><![CDATA[getObjectsById]]></category>
		<category><![CDATA[getObjectsById error]]></category>
		<category><![CDATA[google appengine]]></category>
		<category><![CDATA[jdo getObjectsById]]></category>

		<guid isPermaLink="false">http://www.techtamasha.com/?p=209</guid>
		<description><![CDATA[On Google Appengine I needed to fetch multiple objects, the key to which is present with me. I tried using PersistenceManager#getObjectsById(Collection) method and passed a list of keys to it. But that threw an exception. On further probing I realized this is not how #getObjectsById works. There might be other ways of doing it but [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Ffetch-multiple-objects-by-key-in-jdo%2F209&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Fetch Multiple Objects by key in JDO using getObjectsById" data-url="http://www.techtamasha.com/fetch-multiple-objects-by-key-in-jdo/209" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>On Google Appengine I needed to fetch multiple objects, the key to which is present with me. I tried using <strong>PersistenceManager#getObjectsById(Collection)</strong> method and passed a list of keys to it. But that threw an exception. On further probing I realized this is not how <strong>#getObjectsById</strong> works.</p>
<p>There might be other ways of doing it but this is how I&#8217;ve done it :</p>
<blockquote><p>List list = new ArrayList();</p>
<p>for(Key key : &lt;iterate-over-list-of-keys&gt;){</p>
<p>list.add(persistenceManager.newObjectIdInstance(&lt;class-name-here&gt;, key));</p>
<p>}</p>
<p>Collection objects = persistenceManager.getObjectsById(list);</p>
<p>Hopefully this helps you use the <strong>getObjectsById</strong> method in JDO on google appengine.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/fetch-multiple-objects-by-key-in-jdo/209/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert json string to Map in Java using Gson</title>
		<link>http://www.techtamasha.com/convert-json-to-map-in-java/168</link>
		<comments>http://www.techtamasha.com/convert-json-to-map-in-java/168#comments</comments>
		<pubDate>Sun, 03 Apr 2011 09:53:19 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[gson]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json map java]]></category>

		<guid isPermaLink="false">http://www.techtamasha.com/?p=168</guid>
		<description><![CDATA[I&#8217;ve been using Gson from quite some time now. It&#8217;s a Java library developed by Google that is used to convert JSON to Java objects and vice versa. You can read more about Gson here. I came across this json string which I had to convert into a Map. Here&#8217;s how you do it: Type [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fconvert-json-to-map-in-java%2F168&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Convert json string to Map in Java using Gson" data-url="http://www.techtamasha.com/convert-json-to-map-in-java/168" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I&#8217;ve been using Gson from quite some time now. It&#8217;s a Java library developed by Google that is used to convert JSON to Java objects and vice versa. You can <a href="http://sites.google.com/site/gson/Home">read more about Gson here</a>.</p>
<p>I came across this json string which I had to convert into a Map. Here&#8217;s how you do it:</p>
<pre>Type type =</pre>
<pre> new TypeToken&lt;Map&lt;String, String&gt;&gt;(){}.getType();</pre>
<pre>Map&lt;String, String&gt; map =</pre>
<pre> gson.fromJson("{'key1':'123','key2':'456'}", type);</pre>
<p>Hope that helps you convert a json string into a java Map.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/convert-json-to-map-in-java/168/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to get cookie value in Java</title>
		<link>http://www.techtamasha.com/how-to-get-cookie-value-in-java/161</link>
		<comments>http://www.techtamasha.com/how-to-get-cookie-value-in-java/161#comments</comments>
		<pubDate>Sat, 26 Mar 2011 07:05:20 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[servlet cookie]]></category>

		<guid isPermaLink="false">http://www.techtamasha.com/?p=161</guid>
		<description><![CDATA[Cookies come as part of the HttpServletRequest object.  The below code should help you retrieve cookie values that you have set on a client&#8217;s browser. &#160; Cookie[] cookies = servletRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals("cookieName")) { //do something //value can be retrieved using #cookie.getValue() } } }]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fhow-to-get-cookie-value-in-java%2F161&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="How to get cookie value in Java" data-url="http://www.techtamasha.com/how-to-get-cookie-value-in-java/161" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Cookies come as part of the HttpServletRequest object.  The below code should help you retrieve cookie values that you have set on a client&#8217;s browser.</p>
<p>&nbsp;</p>
<pre>Cookie[] cookies = servletRequest.getCookies();

if (cookies != null) {
 for (Cookie cookie : cookies) {
   if (cookie.getName().equals("cookieName")) {
     //do something</pre>
<pre>     //value can be retrieved using #cookie.getValue()</pre>
<pre>    }</pre>
<pre>  }</pre>
<pre>}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/how-to-get-cookie-value-in-java/161/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javac bug &#8211; no unique maximal instance</title>
		<link>http://www.techtamasha.com/javac-bug-no-unique-maximal-instance/97</link>
		<comments>http://www.techtamasha.com/javac-bug-no-unique-maximal-instance/97#comments</comments>
		<pubDate>Tue, 28 Apr 2009 12:08:13 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javac bug]]></category>
		<category><![CDATA[no unique maximal instance]]></category>

		<guid isPermaLink="false">http://www.techtamasha.com/?p=97</guid>
		<description><![CDATA[While trying to compile my java class files with the 1.6 java compiler, I came across an error message that read : &#8220;no unique maximal instance exists for type variable U with upper bounds U&#8221; The weird thing was that the file compiled just fine in eclipse! On further probing I realized it&#8217;s a javac [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fjavac-bug-no-unique-maximal-instance%2F97&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="javac bug &#8211; no unique maximal instance" data-url="http://www.techtamasha.com/javac-bug-no-unique-maximal-instance/97" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>While trying to compile my java class files with the 1.6 java compiler, I came across an error message that read :</p>
<p>&#8220;<strong>no unique maximal instance exists for type variable U with upper bounds U</strong>&#8221;</p>
<p>The weird thing was that the file compiled just fine in eclipse!</p>
<p>On further probing I realized it&#8217;s a javac bug (<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954">check the bug here</a>)</p>
<p>Here&#8217;s the workaround -</p>
<p><span style="text-decoration: underline;">Bug Scenario</span> :</p>
<p>public class SomeObject {</p>
<p>&lt;U extends SomeObject&gt; U foo1() throws Exception {</p>
<p>SomeObject obj = new SomeObject();<br />
return obj.foo1();<br />
}</p>
<p>}</p>
<p><span style="text-decoration: underline;">Solve this way </span>:</p>
<p>public class SomeObject {</p>
<p>&lt;U extends SomeObject&gt; U foo1() throws Exception {</p>
<p>SomeObject obj = new SomeObject();<br />
return obj.<strong>&lt;U&gt;</strong>foo1();<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/javac-bug-no-unique-maximal-instance/97/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Method overriding and overloading in Java</title>
		<link>http://www.techtamasha.com/method-overriding-and-overloading-in-java/66</link>
		<comments>http://www.techtamasha.com/method-overriding-and-overloading-in-java/66#comments</comments>
		<pubDate>Fri, 04 Jul 2008 18:38:22 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[method overloading]]></category>
		<category><![CDATA[overriding]]></category>

		<guid isPermaLink="false">http://techtamasha.com/?p=66</guid>
		<description><![CDATA[I know this may be trivial for many people but then it can be pretty confusing for new bees (pssst.. in the beginning me too used to be confused between overloading and overriding) OVERRIDING &#8211; when you extend a class and write a method in the derived class which is exactly similar to the one [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fmethod-overriding-and-overloading-in-java%2F66&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Method overriding and overloading in Java" data-url="http://www.techtamasha.com/method-overriding-and-overloading-in-java/66" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I know this may be trivial for many people but then it can be pretty confusing for new bees (pssst.. in the beginning me too used to be confused between overloading and overriding)</p>
<p><strong>OVERRIDING &#8211; when you extend a class and write a method in the derived class which is exactly similar to the one present in the base class, it is termed as overriding.</strong></p>
<blockquote><p><span style="color: #800000;">Example:</span></p>
<p><span style="color: #800000;">public class BaseClass{</span></p>
<p><span style="color: #800000;">public void methodToOverride()</span></p>
<p><span style="color: #800000;">{</span></p>
<p><span style="color: #800000;">//Some code here</span></p>
<p><span style="color: #800000;">}</span></p>
<p><span style="color: #800000;">}</span></p>
<p><span style="color: #800000;">public class DerivedClass extends BaseClass{</span></p>
<p><span style="color: #800000;">public void methodToOverride()</span></p>
<p><span style="color: #800000;">{</span></p>
<p><span style="color: #800000;">//Some new code here</span></p>
<p><span style="color: #800000;">}</span></p>
<p><span style="color: #800000;">}</span></p></blockquote>
<p>As you can see, in the class DerivedClass, we have overridden the method present in the BaseClass with a completely new piece of code in the DerivedClass.</p>
<p>What that effectively means is that if you create an object of DerivedClass and call the methodToOverride() method, the code in the derivedClass will be executed. If you hadn&#8217;t overridden the method in the DerivedClass then the method in the BaseClass would have been called.</p>
<p><strong>OVERLOADING -  when you have more than one method with the same name but different arguments, the methods are said to be overloaded.</strong></p>
<blockquote><p><span style="color: #800000;">Example:</span></p>
<p><span style="color: #800000;">public class OverLoadingExample{</span></p>
<p><span style="color: #800000;">public void add(int i, int j)</span></p>
<p><span style="color: #800000;">{</span></p>
<p><span style="color: #800000;">int k = i + j;</span></p>
<p><span style="color: #800000;">}</span></p>
<p><span style="color: #800000;">public void add(String s, String t)</span></p>
<p><span style="color: #800000;">{</span></p>
<p><span style="color: #800000;">int k = Integer.parseInt(s) + Integer.parseInt(t);</span></p>
<p><span style="color: #800000;">}</span></p>
<p><span style="color: #800000;">}</span></p></blockquote>
<p>As you can see in the example above, we have the same method add() taking two parameters but with different data types. Due to overloading we can now call the add method by either passing it a String or int <img src='http://www.techtamasha.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/method-overriding-and-overloading-in-java/66/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>The &#8216;final&#8217; keyword in Java</title>
		<link>http://www.techtamasha.com/the-final-keyword-in-java/36</link>
		<comments>http://www.techtamasha.com/the-final-keyword-in-java/36#comments</comments>
		<pubDate>Mon, 03 Mar 2008 14:13:46 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[constant value for variable]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[final class]]></category>
		<category><![CDATA[final java]]></category>
		<category><![CDATA[final method]]></category>
		<category><![CDATA[final variable]]></category>
		<category><![CDATA[java final]]></category>
		<category><![CDATA[what is final in Java?]]></category>

		<guid isPermaLink="false">http://techtamasha.com/?p=36</guid>
		<description><![CDATA[Time to explore the &#8216;final&#8216; keyword. When you use the keyword &#8216;final&#8217; with a variable declaration, the value stored inside that variable cannot be changed come what may!! So suppose you do this : final int i =10; After this, nowhere in your code can you change the value of &#8216;i&#8217; i.e. &#8216;i&#8217; will always [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fthe-final-keyword-in-java%2F36&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="The &#8216;final&#8217; keyword in Java" data-url="http://www.techtamasha.com/the-final-keyword-in-java/36" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Time to explore the &#8216;<strong>final</strong>&#8216; keyword.</p>
<p>When you use the keyword &#8216;final&#8217; with a variable declaration, the value stored inside that variable cannot be changed come what may!!</p>
<p>So suppose you do this :</p>
<p>final int i =10;</p>
<p>After this, nowhere in your code can you change the value of &#8216;i&#8217; i.e. &#8216;i&#8217; will always have a value &#8217;10&#8242; .</p>
<p>So i = 11;  //will give you a compile time error.</p>
<p>Now, suppose you did not initialize the final integer &#8216;i&#8217; while declaring it.</p>
<p>final int i;</p>
<p>Can you assign any value to this variable now?</p>
<p>Yes, you definitely can. But only once!</p>
<p>So,</p>
<p>final int i;</p>
<p>i = 10; //This is fine</p>
<p>i = 11; //Compiler error</p>
<p>Now that was the core stuff about &#8216;final&#8217; . Let&#8217;s learn a bit more in detail about it.</p>
<p>The &#8216;final&#8217; keyword can be used for a class declaration or method declaration.</p>
<p><strong>What happens when you use &#8216;final&#8217; for a class declaration?</strong></p>
<p><strong>A</strong>: You cannot have a sub class of a class declared final i.e. No other class can extend this class.</p>
<p><strong>What happens when you declare a method as final?</strong></p>
<p><strong>A</strong>: Simply put, the method cannot be overridden.</p>
<p><strong>Can you override a method(Not declared as &#8216;final&#8217;) present inside a final class?</strong></p>
<p><strong>A</strong>: Obviously Not.  Since there&#8217;s no way to extend a class declared final there&#8217;s no way of overriding its methods!</p>
<p><strong>What happens when I declare a method inside a class as both &#8216;private&#8217; and &#8216;final&#8217; ?</strong></p>
<p><strong>A</strong>: Making a class both &#8216;private&#8217; and &#8216;final&#8217; makes the &#8216;final&#8217; keyword redundant as a private method cannot be accessed in its sub class. But hey, you&#8217;ll be able to declare a method of the same name as in the base class if the method has been made private in the base class. But then that doesn&#8217;t mean you&#8217;re overriding the method. You&#8217;re simply declaring a new method in the sub class.</p>
<p><strong>Note:</strong> You cannot make an &#8216;abstract&#8217; class or method as &#8216;final&#8217; because an &#8216;abstract&#8217; class needs to be extended which will not be possible if you mark it as &#8216;final&#8217;!</p>
<p>I found this article on &#8216;final&#8217; worth reading:</p>
<p><a href="http://www.ibm.com/developerworks/java/library/j-jtp1029.html" title="http://www.ibm.com/developerworks/java/library/j-jtp1029.html" target="_blank">http://www.ibm.com/developerworks/java/library/j-jtp1029.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/the-final-keyword-in-java/36/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>New jdk 1.5 &#8216;for&#8217; loop ( Enhanced for loop-&#8217;for each&#8217;)</title>
		<link>http://www.techtamasha.com/new-jdk-15-for-loop-enhanced-for-loop-for-each/35</link>
		<comments>http://www.techtamasha.com/new-jdk-15-for-loop-enhanced-for-loop-for-each/35#comments</comments>
		<pubDate>Fri, 29 Feb 2008 13:16:05 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[1.5 for loop]]></category>
		<category><![CDATA[foreach loop]]></category>
		<category><![CDATA[java for each]]></category>
		<category><![CDATA[jdk 1.5 for loop]]></category>
		<category><![CDATA[new for loop]]></category>

		<guid isPermaLink="false">http://techtamasha.com/?p=35</guid>
		<description><![CDATA[int a[] = {1,2,3,4,5}; for(int i =0;i&#60;a.length;i++) { System.out.println(&#8220;Value: &#8220;+a[i]); } This is so 1.4!!! Here&#8217;s how you do it with the new and enhanced for loop : for(int b: a) { System.out.println(&#8220;Value :&#8221;+b); } To make it easy for you to understand how to interpret the above condition, read it as follows: &#8221; for [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fnew-jdk-15-for-loop-enhanced-for-loop-for-each%2F35&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="New jdk 1.5 &#8216;for&#8217; loop ( Enhanced for loop-&#8217;for each&#8217;)" data-url="http://www.techtamasha.com/new-jdk-15-for-loop-enhanced-for-loop-for-each/35" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>int a[] = {1,2,3,4,5};</p>
<p>for(int i =0;i&lt;a.length;i++)</p>
<p>{</p>
<p>System.out.println(&#8220;Value: &#8220;+a[i]);</p>
<p>}</p>
<p>This is so 1.4!!!</p>
<p>Here&#8217;s how you do it with the new and enhanced for loop :</p>
<p>for(int b: a)</p>
<p>{</p>
<p>System.out.println(&#8220;Value :&#8221;+b);</p>
<p>}</p>
<p>To make it easy for you to understand how to interpret the above condition, read it as follows:</p>
<p>&#8221; for each int b in a&#8230;..iterate&#8221;</p>
<p><strong>Basically what you have to do is &#8211; To the left of the colon in the for loop declare the datatype that is present inside the array and to the right of the colon write the name of the array.</strong></p>
<p>The above &#8216;for&#8217; loop will iterate as many times as there are elements in the array &#8216;a&#8217;. At every iteration int b will have the value of the next element.</p>
<p>In simple terms its like this:</p>
<p>for(int b: a) will internally expand like this : for(int i=0;i&lt;a.length;i++){int b=a[i];}</p>
<p>You can use this for loop for iterating over type collections too.</p>
<p>Example :</p>
<p>List&lt;MyObject&gt; al = new ArrayList();</p>
<p>//Create an Object of some class you want to put into the arraylist.</p>
<p>MyObject myObject = new MyObject();</p>
<p>MyObject myObject1 = new MyObject();</p>
<p>al.add(myObject);</p>
<p>al.add(myObject1);</p>
<p>for(MyObject o : al)</p>
<p>{</p>
<p>System.out.println(&#8220;Object hashcode is &#8220;+o.hashCode());</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/new-jdk-15-for-loop-enhanced-for-loop-for-each/35/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple example to demonstrate that String object is immutable</title>
		<link>http://www.techtamasha.com/simple-example-to-demonstrate-that-string-object-is-immutable/31</link>
		<comments>http://www.techtamasha.com/simple-example-to-demonstrate-that-string-object-is-immutable/31#comments</comments>
		<pubDate>Tue, 19 Feb 2008 14:29:55 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techtamasha.com/?p=31</guid>
		<description><![CDATA[In my post &#8216;Difference between String and StringBuffer/StringBuilder&#8217; I told you stuff like String object is immutable( meaning the value stored in the object cannot be changed) and that when you perform operations such as concat or replace, internally a new object is created to hold the result. Below is a simple example that will [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fsimple-example-to-demonstrate-that-string-object-is-immutable%2F31&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Simple example to demonstrate that String object is immutable" data-url="http://www.techtamasha.com/simple-example-to-demonstrate-that-string-object-is-immutable/31" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>In my post <a href="http://techtamasha.com/?p=28" target="_blank">&#8216;Difference between String and StringBuffer/StringBuilder&#8217;</a> I told you stuff like String object is immutable( meaning the value stored in the object cannot be changed) and that when you perform operations such as concat or replace, internally a new object is created to hold the result.</p>
<p>Below is a simple example that will make you believe that what I said about String object is indeed true!</p>
<p>String s = &#8220;Let&#8217;s test&#8221;;</p>
<p>s.concat(&#8221; if the String object is IMMUTABLE&#8221;);</p>
<p>System.out.println(s);</p>
<p>s = s.concat(&#8221; if the String object is IMMUTABLE&#8221;);</p>
<p>System.out.println(s);</p>
<p>The output of the above code will be:</p>
<p>Let&#8217;s test</p>
<p>Let&#8217;s test  if the String object is IMMUTABLE</p>
<p>That&#8217;s all people! The above piece of code proves that String is immutable and hence the results of operations like concat etc. should be stored into a new object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/simple-example-to-demonstrate-that-string-object-is-immutable/31/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Here&#8217;s how you use StringBuilder</title>
		<link>http://www.techtamasha.com/heres-how-you-use-stringbuilder/30</link>
		<comments>http://www.techtamasha.com/heres-how-you-use-stringbuilder/30#comments</comments>
		<pubDate>Tue, 19 Feb 2008 09:46:21 +0000</pubDate>
		<dc:creator>Nischal Shetty</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techtamasha.com/?p=30</guid>
		<description><![CDATA[Now get out of that bad habit of using String objects to perform operations on strings. With StringBuilder(introduced in J2Se 5.0), you can perform those very append and other such operations more efficiently. Scene 1: typical coder&#8230;. using the same old String object to perform append operations. String s = &#8220;Hello&#8221;; s = s + [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:100px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.techtamasha.com%2Fheres-how-you-use-stringbuilder%2F30&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:110px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Here&#8217;s how you use StringBuilder" data-url="http://www.techtamasha.com/heres-how-you-use-stringbuilder/30" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Now get out of that bad habit of using String objects to perform operations on strings. With StringBuilder(introduced in J2Se 5.0), you can perform those very append and other such operations more efficiently.</p>
<p>Scene 1: typical coder&#8230;. using the same old String object to perform append operations.</p>
<p>String s = &#8220;Hello&#8221;;</p>
<p>s = s + &#8221; World&#8221;;</p>
<p>system.out.println(s);</p>
<p>I agree it&#8217;ll give you &#8220;Hello World&#8221;, but fella&#8230;. let&#8217;s be different from the rest and think about making the code more efficient.</p>
<p>Enter Scene 2.</p>
<p>StringBuilder sb = new StringBuilder(&#8220;Hello&#8221;);</p>
<p>sb.append(&#8221; World&#8221;);</p>
<p>system.out.println(sb);</p>
<p>well&#8230; thats it!! You&#8217;ll get your &#8220;Hello World&#8221; but in a more efficient way <img src='http://www.techtamasha.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.techtamasha.com/heres-how-you-use-stringbuilder/30/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

