<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Myblog&#039;s Blog</title>
	<atom:link href="http://interviewboard.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://interviewboard.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 19 Feb 2010 22:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='interviewboard.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Myblog&#039;s Blog</title>
		<link>http://interviewboard.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://interviewboard.wordpress.com/osd.xml" title="Myblog&#039;s Blog" />
	<atom:link rel='hub' href='http://interviewboard.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Garbage Collection</title>
		<link>http://interviewboard.wordpress.com/2010/02/19/garbage-collection/</link>
		<comments>http://interviewboard.wordpress.com/2010/02/19/garbage-collection/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 22:14:11 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Garbage Collection]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=71</guid>
		<description><![CDATA[What is difference between C++ Destructor and Java Finalize method ?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=71&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What is difference between C++ Destructor and Java Finalize method ?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=71&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/02/19/garbage-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>http://ostermiller.org/articles.html</title>
		<link>http://interviewboard.wordpress.com/2010/02/08/httpostermiller-orgarticles-html/</link>
		<comments>http://interviewboard.wordpress.com/2010/02/08/httpostermiller-orgarticles-html/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 19:32:25 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/2010/02/08/httpostermiller-orgarticles-html/</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=70&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=70&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/02/08/httpostermiller-orgarticles-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>M Random Numbers Which Sum To N</title>
		<link>http://interviewboard.wordpress.com/2010/02/08/m-random-numbers-which-sum-to-n/</link>
		<comments>http://interviewboard.wordpress.com/2010/02/08/m-random-numbers-which-sum-to-n/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 19:21:02 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/2010/02/08/m-random-numbers-which-sum-to-n/</guid>
		<description><![CDATA[http://www.siafoo.net/algorithm/8<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=68&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>http://www.siafoo.net/algorithm/8</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=68&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/02/08/m-random-numbers-which-sum-to-n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>Detecting A cycle in Singly linked List</title>
		<link>http://interviewboard.wordpress.com/2010/02/08/detecting-a-cycle-in-singly-linked-list/</link>
		<comments>http://interviewboard.wordpress.com/2010/02/08/detecting-a-cycle-in-singly-linked-list/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 19:18:56 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=66</guid>
		<description><![CDATA[http://www.siafoo.net/algorithm/10 http://www.siafoo.net/algorithm/11 How do you determine if your singly-linked list has a cycle? In the late 1960s, Robert W. Floyd invented an algorithm that worked in linear (O(N)) time. It is also called Floyd&#8217;s cycle detection algorithm. The easiest solution to the cycle detection problem is to run through the list, keeping track of which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=66&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>http://www.siafoo.net/algorithm/10</p>
<p>http://www.siafoo.net/algorithm/11</p>
<p>How do you determine if your singly-linked list has a cycle? In the late 1960s, Robert W. Floyd invented an algorithm that worked in linear (O(N)) time. It is also called Floyd&#8217;s cycle detection algorithm.</p>
<p>The easiest solution to the cycle detection problem is to run through the list, keeping track of which nodes you visit, and on each node check to see if it is the same as any of the previous nodes. It&#8217;s pretty obvious that this runs in quadratic (O(N^2)) time&#8230; not very efficient, and actually more complicated than this one.</p>
<p>The Tortoise and the Hare is possibly the most famous cycle detection algorithm, and is surprisingly straightforward. The Tortoise and the Hare are both pointers, and both start at the top of the list. For each iteration, the Tortoise takes one step and the Hare takes two. If there is a loop, the hare will go around that loop (possibly more than once) and eventually meet up with the turtle when the turtle gets into the loop. If there is no loop, the hare will get to the end of the list without meeting up with the turtle.</p>
<p>Why can&#8217;t you just let the hare go by itself? If there was a loop, it would just go forever; the turtle ensues you will only take n steps at most.</p>
<p>For a somewhat more efficient algorithm, check out Brent&#8217;s Cycle Detection Algorithm (The Teleporting Turtle).</p>
<p>How do you determine if your singly-linked list has a cycle? In 1980, Brent invented an algorithm that not only worked in linear time, but required less stepping than Floyd&#8217;s Tortoise and the Hare algorithm (however it is slightly more complex). Although stepping through a &#8216;regular&#8217; linked list is computationally easy, these algorithms are also used for factorization and pseudorandom number generators, linked lists are implicit and finding the next member is computationally difficult.</p>
<p>Brent&#8217;s algorithm features a moving rabbit and a stationary, then teleporting, turtle. Both turtle and rabbit start at the top of the list. The rabbit takes one step per iteration. If it is then at the same position as the stationary turtle, there is obviously a loop. If it reaches the end of the list, there is no loop.</p>
<p>Of course, this by itself will take infinite time if there is a loop. So every once in a while, we teleport the turtle to the rabbit&#8217;s position, and let the rabbit continue moving. We start out waiting just 2 steps before teleportation, and we double that each time we move the turtle.</p>
<p>Why move the turtle at all? Well, the loop might not include the entire list; if a rabbit gets stuck in a loop further down, without the turtle, it will go forever. Why take twice as long each time? Eventually, the length of time between teleportations will become longer than the size of the loop, and the turtle will be there waiting for the rabbit when it gets back.</p>
<p>Note that like Floyd&#8217;s Tortoise and Hare algorithm, this one runs in O(N). However you&#8217;re doing less stepping than with Floyd&#8217;s (in fact the upper bound for steps is the number you would do with Floyd&#8217;s algorithm). According to Brent&#8217;s research, his algorithm is 24-36% faster on average for implicit linked list algorithms.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=66&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/02/08/detecting-a-cycle-in-singly-linked-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>Algorithm for converting a string to an integer value.</title>
		<link>http://interviewboard.wordpress.com/2010/02/08/algorithm-for-converting-a-string-to-an-integer-value/</link>
		<comments>http://interviewboard.wordpress.com/2010/02/08/algorithm-for-converting-a-string-to-an-integer-value/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:59:24 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=63</guid>
		<description><![CDATA[Hints: 1. Check that each character is a numeric character. Take into consideration the base in which the conversion is sought. 2. Identify the character in ASCII and convert it to numeral &#8217;1&#8242; -&#62; 1 3. Iterate over string and Multiply by the appropriate base and add it to temp to find the value of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=63&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hints:<br />
1. Check that each character is a numeric character. Take into consideration the base in which the conversion is sought.</p>
<p>2. Identify the character in ASCII and convert it to numeral &#8217;1&#8242; -&gt; 1<br />
3. Iterate over string and Multiply by the appropriate base and add it to temp to find the value of the number.<br />
Also take care that number is -ve</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=63&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/02/08/algorithm-for-converting-a-string-to-an-integer-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>Amazon-1-Advantages and disadvantages of recursions</title>
		<link>http://interviewboard.wordpress.com/2010/01/26/amazon-1-advantages-and-disadvantages-of-recursions/</link>
		<comments>http://interviewboard.wordpress.com/2010/01/26/amazon-1-advantages-and-disadvantages-of-recursions/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 12:00:34 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Amazon]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[Recusions]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=60</guid>
		<description><![CDATA[1. Advantages and disadvantages of recursion Show Answer advantages 1. Small Manageable Code 2. Sometimes Recursion is only option 3. Code Reuse Disadvantages: 1. Is mostly depth first- You may run out of memory 2. Is memory intensive 3. Stack Space is used prominently<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=60&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>1. Advantages and disadvantages of recursion</p>
<p>Show Answer</p>
<p>advantages</p>
<p>1. Small Manageable Code</p>
<p>2. Sometimes Recursion is only option</p>
<p>3. Code Reuse</p>
<p>Disadvantages:</p>
<p>1. Is mostly depth first- You may run out of memory</p>
<p>2. Is memory intensive</p>
<p>3. Stack Space is used prominently</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=60&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2010/01/26/amazon-1-advantages-and-disadvantages-of-recursions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title></title>
		<link>http://interviewboard.wordpress.com/2009/11/17/58/</link>
		<comments>http://interviewboard.wordpress.com/2009/11/17/58/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:58:38 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Inner Classes]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/2009/11/17/58/</guid>
		<description><![CDATA[Q1) What is an inner class? Ans) Inner class is a class defined inside other class and act like a member of the enclosing class. Q2) What are the different types of inner classes? Ans) There are two main types of inner classes – Static member class Inner class Member class Anonymous class Local class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=58&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="15">
<tbody>
<tr>
<td><a name="Q1" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q1"> <strong>Q1)  What is an inner class?</p>
<p></strong></a></p>
<div id="divQ1">Ans) Inner class is a class defined inside other class and act like a  member of the enclosing class.</div>
</td>
</tr>
<tr>
<td><a name="Q2" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q2"><strong>Q2)  What are the different types of inner classes?</strong></p>
<p></a></p>
<div id="divQ2">Ans) There are two main types of inner classes –</p>
<ul>
<li>Static member class</li>
<li>Inner class
<ul>
<li>Member class</li>
<li>Anonymous class</li>
<li>Local class</li>
</ul>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td><a name="Q3" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q3"><strong>Q3) What is static member class?</strong></p>
<p></a></p>
<div id="divQ3">Ans) A static member class behaves much like an ordinary top-level class, except that it can access the static members of the class that contains it. The static nested class can be accessed as the other static members of the enclosing class without having an instance of the outer class. The static class can contain non-static and static members and methods.public class InnerClass {</p>
<p>static class StaticInner {</p>
<p>static int <em>i</em> = 9;<br />
int no = 6;</p>
<p>private void method() {}</p>
<p>public void method1() {}</p>
<p>static void method2() {}</p>
<p>final void method3() {}</p>
<p>}<br />
}</p>
<p>The  static inner class can be accessed from Outer Class in the following manner:<br />
InnerClass.StaticInner staticObj= new InnerClass. StaticInner ();</p>
<p>No outer class instance is required to instantiate the nested static class because the static class is a static member of the enclosing class.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q4" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q4"><strong>Q4) What are non  static inner classes?</strong></p>
<p></a></p>
<div id="divQ4">Ans)<br />
Non &#8211; static inner  classes – classes associated with the object of the enclosing class.<br />
<strong>Member class</strong> &#8211;  Classes declared outside a function (hence a &#8220;member&#8221;) and not  declared &#8220;static&#8221;.<br />
The member class can be declared as public, private,  protected, final and abstract. E.g.public class InnerClass {</p>
<blockquote><p>class MemberClass {</p></blockquote>
<blockquote><p>public void  method1() { }</p></blockquote>
<blockquote><p>}<br />
}</p></blockquote>
<p><strong>Method local class</strong> – The inner class declared inside the method is called method local inner class. Method local inner class can only be declared as final or abstract. Method local class can only access global variables or method local variables if declared as final</p>
<p>public class InnerClass {</p>
<p>int i = 9;</p>
<p>public void method1() {</p>
<p>final int k = 6;<br />
class MethodLocal {<br />
MethodLocal() {<br />
System.out.println(k  + i);<br />
}<br />
}<br />
}<br />
}<strong>Anonymous inner  class</strong> &#8211; These are local classes which are automatically declared and instantiated in the middle of an expression.  Also, like local classes, anonymous classes cannot be public, private, protected, or static. They can specify arguments to the constructor of the superclass, but cannot otherwise have a constructor. They can implement only one interface or extend a class.<br />
Anonymous class cannot define any static fields, methods,  or classes, except for static final constants.<br />
Also, like local classes, anonymous classes cannot be  public, private, protected, or static</p>
<p>Some examples:<br />
public class MyFrame extends JFrame {</p>
<p>JButton btn = new JButton();<br />
MyFrame() {<br />
btn.addActionListener(new  ActionListener() {<br />
public void  actionPerformed(ActionEvent e) {<br />
}<br />
});<br />
}<br />
}</p>
<p>Anonymous class  used with comparator</p>
<p>List&lt;Parent&gt; l = new ArrayList&lt;Parent&gt;();<br />
l.add(new Parent(2));<br />
l.add(new Parent(3));<br />
Collections.sort(l, new Comparator() {<br />
public int compare(Object o1,  Object o2) {<br />
Parent prt1 = (Parent) o1;<br />
Parent prt2 = (Parent) o2;</p>
<blockquote><p>if (prt1.getAge() &gt;  prt2.getAge()) {</p>
<blockquote><p>return -1;<br />
}else if(prt1.getAge()&lt;prt2.getAge())  {</p>
<blockquote><p>return 1;<br />
} else {</p>
<blockquote><p>return 0;<br />
}<br />
}<br />
});
<p>&nbsp;</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</div>
</td>
</tr>
<tr>
<td><a name="Q5" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q5"> <strong>Q5) 							Does a static nested class have access to the enclosing class&#8217; 							non-static methods or instance variables? </strong></a></p>
<div id="divQ5">
Ans) No .</div>
</td>
</tr>
<tr>
<td><a name="Q6" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q6"> Q6) 						<strong> What are the advantages of Inner classes?</strong></a></p>
<div id="divQ6">
<p>Ans) The embedding of inner class into the outer class in the 								case when the inner class is to be used only by one class i.e. 								the outer class makes the package more streamlined. Nesting the 								inner class code where it is used (inside the outer class) makes 								the code more readable and maintainable.</p>
<p>The inner class shares a special relationship with the outer 								class i.e. the inner class has access to all members of the outer 								class and still have its own type is the main advantages of Inner 								class. Advantage of inner class is that they can be hidden from 								the other classes in the same package and still have the access 								to all the members (private also) of the enclosing class. So the 								outer class members which are going to be used by the inner class 								can be made private and the inner class members can be hidden 								from the classes in the same package. This increases the level of 								encapsulation.</p>
<p>If a class A is written requires another class B for its own use, 								there are two ways to do this. One way is to write a separate 								class B or to write an inner class B inside class A. Advantage of 								writing the inner class B in the class A is you can avoid having 								a separate class. Inner classes are best used in the event 								handling mechanism and to implement the helper classes. The 								advantage of using inner class for event handling mechanism is 								that the use of if/else to select the component to be handled can 								be avoided. If inner classes are used each component gets its own 								event handler and each event handler implicitly knows the 								component it is working for. e.g.</p>
<p>Button btn1 = new Button(&#8220;Submit&#8221;);<br />
Btn.addActionListener(new ActionListener(){/br&gt;</p>
<blockquote><p>Public void actionPerformed(ActionEvent ae){ submitClicked(); }</p></blockquote>
<p>} );<br />
The advantage of using static nested class is that to instantiate 							a static nested class you need not create an instance of the 							enclosing class which reduces the number of objects the 							application creates at runtime.</p></div>
</td>
</tr>
<tr>
<td><a name="Q7" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q7"> <strong>Q7)What 							are disadvantages of using inner classes?</strong></a></p>
<div id="divQ7">Ans)<br />
1. Using inner class increases the total number of classes being 							used by the application. For all the classes created by JVM and 							loaded in the memory, jvm has to perform some tasks like creating 							the object of type class. Jvm may have to perform some routine 							tasks for these extra classes created which may result slower 							performance if the application is using more number of inner 							classes.<br />
2. Inner classes get limited support of ide/tools as compared to 							the top level classes, so working with the inner classes is 							sometimes annoying for the developer.</div>
</td>
</tr>
<tr>
<td><a name="Q8" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q8"> <strong> Q8) What are different types of anonymous classes?</strong></a></p>
<div id="divQ8">
Ans 1) 						<strong>Plain old anonymous class type one</strong>–<br />
e.g.<br />
class superClass{<br />
void doSomething() 						{<br />
System.out.println(“Doing something in the Super 						class”);<br />
}<br />
}</p>
<p>class hasAnonymous{<br />
superClass anon = new superClass(){<br />
void doSomething() {<br />
System.out.println(“Doing something in the Anonymous 						class”);<br />
}<br />
};<br />
Here anon is the reference which is of type superClass which is the 						class extended by the anonymous class i.e. superclass of the 						anonymous class. The method doSomething() is the super class method 						overridden by the anonymous class.<br />
2) 						<strong>Plain old anonymous class type two</strong> –</p>
<p>interface Eatable{<br />
public void prepareSweets();<br />
}<br />
class serveMeal{<br />
Eatable food = new Eatable(){<br />
public void 						prepareSweets(){ //come implementation code goes here }<br />
};<br />
}<br />
food is reference variable of type Eatable interface which 						refers to the anonymous class which is the implementer of the 						interface Eatable. The anonymous implementer class of the interface 						Eatable implements its method prepareSweets() inside it.<br />
3) 						<strong>Argument defined anonymous class</strong> – e.g.</p>
<p>interface Vehicle {<br />
void getNoOfWheels();<br />
}<br />
class Car {<br />
void getType(Vehical v) { }<br />
}<br />
class BeautifulCars {<br />
void 						getTheBeautifilCar() {<br />
Car c = new Car ();<br />
c.getType (new Vehicle () {<br />
public void getNoOfWheels () {<br />
System.out.println(&#8220;It has four wheels&#8221;);<br />
}<br />
});<br />
}<br />
}<br />
Anonymous class is defined as the argument of the method 						getTheBeautifilCar(), this anonymous class is the implementer of 						the interface Vehicle. The method of class Car getTheBeautifilCar() 						expects the argument as an object of type Vehicle. So first we 						create an object of Car referenced by the variable ‘c’. 						On this object of Car we call the method getTheBeautifilCar() and 						in the argument we create an anonymous class in place which is the 						implementer of interface Vehicle hence of type Vehicle.</p></div>
</td>
</tr>
<tr>
<td><a name="Q9" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q9"><strong>Q9) If 							you compile a file containing inner class how many .class files 							are created and what are all of them accessible in usual way?</strong></a></p>
<div id="divQ9">
Ans) If a inner class enclosed with an outer class is compiled 							then one .class file for each inner class an a .class file for the 							outer class is created. e.g.<br />
class 							<strong>EnclosingOuter </strong>{<br />
class Inner{ }<br />
}<br />
If you compile the above code with command<br />
% javac EnclosingOuter.java<br />
Two files<br />
<em><strong>EnclosingOuter.class<br />
EnclosingOuter$Inner.class </strong> </em><br />
will be created. Though a separate inner class file is generated, 							the inner class file is not accessible in the usual way like,<br />
% java EnclosingOuter$Inner</div>
</td>
</tr>
<tr>
<td><a name="Q10" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q10"> <strong>Q10) How to access the inner class from code within the outer class?</strong></a></p>
<div id="divQ10">
Ans) The inner class is instantiated only through the outer class 						instance.<br />
class EnclosingOuter {<br />
private int noInnerClass = 1;<br />
public void getNoOfInnerClasses(){<br />
Inner 						in = new Inner();<br />
System.out.println(“No Of Inner classes is : “+ 						<strong>in.getNoOfClassesFromOuter()</strong>);<br />
}<br />
class Inner{</p>
<p>public int getNoOfClassesFromOuter(){ return noInnerClass; }</p>
<p>}<br />
Here the method getNoOfInnerClasses() is called on the outer 						class’s instance through this outer class instance the inner 						class instance in is created.</p></div>
</td>
</tr>
<tr>
<td valign="top"><a name="Q11" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q11"> <strong> Q11) How to create an inner class instance from outside the outer 						class instance code?</strong></a></p>
<div id="divQ11">
Ans) 						 						<strong>To create an instance of the inner class you must 							have the instance of its enclosing class</strong>.<br />
e.g. class EnclosingOuter {<br />
class Inner{ }<br />
}<br />
<strong> To create the instance of inner class from 							class other than the enclosing class.</strong><br />
1) class OtherThanOuter{<br />
EnclosingOuter out = new EnclosingOuter();<br />
EnclosingOuter.Inner in = out.new Inner();<br />
}</p>
<p>2) class OtherThanOuter{<br />
EnclosingOuter.Inner out = new EnclosingOuter.Inner (); }</p></div>
</td>
</tr>
<tr>
<td><a name="Q12" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q12"> <strong>Q12) How to refer to the outer this i.e. outer class’s current 						instance from inside the inner class?</strong> </a></p>
<div id="divQ12">
Ans) The outer this reference i.e. the outer class’ current 						instance’ reference can be 						<strong>refered using ‘OuterClassName.this’.</strong> E.g<br />
class EnclosingOuter {<br />
class 						Inner{<br />
System.out.println(“Inner class reference is “ + this); 						// inner class instance</p>
<blockquote><p>System.out.println(“Outer class reference is “ + 							EnclosingOuter.this); //outer class instance<br />
}<br />
}</p>
<p><strong>To reference the inner class reference from 								within the inner class use this.</strong></p></blockquote>
</div>
</td>
</tr>
<tr>
<td><a name="Q13" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q13"> <strong> Q13) Which modifiers can be applied to the inner class?</strong></a></p>
<div id="divQ13">
Ans) Following are modifiers that can be applied to the inner:<br />
public<br />
private<br />
abstract<br />
final<br />
protected<br />
strictfp<br />
static – turns the inner class into 						static nested class.</div>
</td>
</tr>
<tr>
<td><a name="Q14" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q14"> <strong>Q14) Can the method local inner class object access method’s 						local variables?</strong> </a></p>
<div id="divQ14">
Ans) No, a method local inner class object can not access the 						method local variable.<br />
<strong>Reason</strong>: The local variables are not guaranteed to 						live as long as the local inner class object. The method local 						variable live on stack and exist only till the method lives, their 						scope is limited only code inside the method they are declared in. 						But the local inner class object created within the method lives on 						heap and it may exist even after the method ends if in case the 						reference of this local inner class is passed into some other code 						and is stored in an instance variable. So we can not be sure that 						the local variables will live till the method local inner class 						object lives, therefore the method local inner class object can not 						access the method local variable. To access the method local 						variables, the variable has to be declared as final.</div>
</td>
</tr>
<tr>
<td><a name="Q15" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q15"> <strong> Q15) Can a method local inner class access the local final 			variables?Why?</strong></a></p>
<div id="divQ15">
Ans) Yes. Because the final variables are stored on heap and 						they live as long as the method local inner class object may live.</div>
</td>
</tr>
<tr>
<td><a name="Q16" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q16"> <strong>Q16) Which modifiers can be applied to the method local inner class?</strong></a></p>
<div id="divQ16">
Ans) Only abstract or final keyword isallowed.</div>
</td>
</tr>
<tr>
<td><a name="Q17" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q17"> <strong>Q17) Can a local class declared inside a static method have access 						to the instance members of the outer class?</strong></a></p>
<div id="divQ17">
Ans) No. There is no this reference available in the static method .The static method 						class can not have access to any members of the outer class other 						than static members.</div>
</td>
</tr>
<tr>
<td><a name="Q18" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q18"> <strong> Q18) Can a method which is not in the definition of the superclass of an anonymous class be invoked on that anonymous class reference?</strong> </a></p>
<div id="divQ18">
Ans) No. Compilation will fail.As the reference variable type of 						the anonymous class will be of superclass which will not know of 						any method defined inside the anonymous class the compilation will 						fail.<br />
e.g. class SuperClass{<br />
void doSomething() {<br />
System.out.println(&#8220;In the Super class&#8221;);<br />
}<br />
}<br />
class hasAnonymous{<br />
SuperClass anon = new SuperClass(){<br />
void 						doSomething() {<br />
System.out.println(&#8220;In the Anonymous class&#8221;);<br />
}<br />
void doStuff() {<br />
System.out.println(&#8220;An Anonymous class method not present in 						superClass&#8221;);<br />
}<br />
};</p>
<p>public void doIt(){<br />
anon.doSomething(); // legal 						superClass has this method<br />
anon.doStuff(); // Not legal }<br />
}<br />
The above code does not compile as the superClass does not 						know about the anonymous class method doStuff().</p></div>
</td>
</tr>
<tr>
<td><a name="Q19" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q19"> <strong> Q19) Can an anonymous class define method of its own? </strong></a></p>
<div id="divQ19">
Ans) Yes. But there will be no way by which the methods defined in 						the anonymous class which are not present in its superclass be 						invoked. As only those methods which are defined in the suprclass 						which the anonymous class extends be invoked defining the methods 						in the anonymous class will be of no use</div>
</td>
</tr>
<tr>
<td><a name="Q20" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q20"> <strong>Q20) Can an anonymous class implement multiple interfaces directly?</strong></a></p>
<div id="divQ20">
Ans) No. An anonymous class can implement only one interface. If 						the anonymous class is extending a class then it becomes the 						implementer of all the interfaces implemented by its superclass 						automatically.</div>
</td>
</tr>
<tr>
<td><a name="Q21" href="http://www.java-questions.com/InnerClass_interview_questions.html#Q21"> <strong>Q21) Can an anonymous class implement an interface and also extend a 						class at the same time?</strong></a></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=58&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2009/11/17/58/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>Exceptions</title>
		<link>http://interviewboard.wordpress.com/2009/11/17/exceptions/</link>
		<comments>http://interviewboard.wordpress.com/2009/11/17/exceptions/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:53:44 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=55</guid>
		<description><![CDATA[Q1) What is an Exception? Ans) The exception is said to be thrown whenever an exceptional event occurs in java which signals that something is not correct with the code written and may give unexpected result. An exceptional event is a occurrence of condition which alters the normal program flow. Exceptional handler is the code [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=55&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="15">
<tbody>
<tr>
<td><a name="Q1" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q1"><strong>Q1) What is an Exception?</strong></p>
<p></a></p>
<div id="divQ1">
<p>Ans) The exception is said to be thrown whenever an exceptional event occurs in java which signals that something is not correct with the code written and may give unexpected result. An exceptional event is a occurrence of condition which alters the normal program flow. Exceptional handler is the code that does something about the exception.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q2" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q2"><strong>Q2) Exceptions are defined in which java package?</strong></p>
<p></a></p>
<div id="divQ2">
<p>Ans)All the exceptions are subclasses of java.lang.Exception</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q3" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q3"><strong>Q3) How are the exceptions handled in java?</strong></a></p>
<div id="divQ3">
<p>Ans)When an exception occurs the execution of the program is transferred to an appropriate exception handler.The try-catch-finally block is used to handle the exception.<br />
The code in which the  exception may occur is enclosed in a try block, also called as a guarded region.<br />
The catch clause matches a  specific exception to a block of code which handles that exception.<br />
And the clean up code which  needs to be executed no matter the exception occurs or not is put inside the finally block</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q4" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q4"><strong>Q4) Explain the exception hierarchy in java.</strong></p>
<p></a></p>
<div id="divQ4">
<p>Ans) The hierarchy is as follows:</p>
<p><img src="http://www.java-questions.com/%5Cimg%5CExceptionClasses.png" alt="Exception" /></p>
<p>Throwable is a parent class off all Exception classes. They are two types of Exceptions: Checked exceptions and UncheckedExceptions. Both type of exceptions extends Exception class.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q5" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q5"><strong>Q5) What is Runtime Exception or unchecked exception?</strong></p>
<p></a></p>
<div id="divQ5">
<p>Ans) Runtime exceptions represent problems that are the result of a programming problem. Such problems include arithmetic exceptions, such as dividing by zero; pointer exceptions, such as trying to access an object through a null reference; and indexing exceptions, such as attempting to access an array element through an index that is too large or too small. Runtime exceptions need not be explicitly caught in try catch block as it can occur anywhere in a program, and in a typical one they can be very numerous. Having to add runtime exceptions in every method declaration would reduce a program&#8217;s clarity. Thus, the compiler does not require that you catch or specify runtime exceptions (although you can). The solution to rectify is to correct the programming logic where the exception has occurred or provide a check.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q6" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q6"><strong> Q6) What is checked exception? </strong></p>
<p></a></p>
<div id="divQ6">
<p>Ans) Checked exception are the exceptions which forces the programmer to catch them explicitly in try-catch block. It is a subClass of Exception. Example: IOException.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q7" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q7"><strong> Q7) What is difference between Error and Exception? </strong></p>
<p></a></p>
<div id="divQ7">
<p>Ans) An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime.Though error can be caught in catch block but the execution of application will come to a halt and is not recoverable.</p>
<p>While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.)</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q8" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q8"><strong>Q8) What is difference between ClassNotFoundException and NoClassDefFoundError?</strong></p>
<p></a></p>
<div id="divQ8">
<p>Ans) A ClassNotFoundException is thrown when the reported class is not found by the ClassLoader in the CLASSPATH. It could also mean that the class in question is trying to be loaded from another class which was loaded in a parent classloader and hence the class from the child classloader is not visible.</p>
<p>Consider if NoClassDefFoundError occurs which is something like</p>
<p>java.lang.NoClassDefFoundError</p>
<p>src/com/TestClass</p>
<p>does not mean that the TestClass class is not in the CLASSPATH. It means that the class TestClass was found by the ClassLoader however when trying to load the class, it ran into an error reading the class definition. This typically happens when the class in question has static blocks or members which use a Class that&#8217;s not found by the ClassLoader. So to find the culprit, view the source of the class in question (TestClass in this case) and look for code using static blocks or static members.</p>
</div>
</td>
</tr>
<tr>
<td><a name="throw_keyword" href="http://www.java-questions.com/Exceptions_interview_questions.html#throw_keyword"><strong>Q9) What is throw keyword?</strong></p>
<p></a></p>
<div id="divQ28">
Ans) Throw keyword is used to throw the exception manually. It is mainly used when the program fails to satisfy the given condition and it wants to warn the application.The exception thrown should be subclass of Throwable.</p>
<div>public void parent(){<br />
try{<br />
child();<br />
}catch(MyCustomException e){	}<br />
}</p>
<p>public void child{<br />
String iAmMandatory=null;<br />
if(iAmMandatory == null){<br />
throw (new MyCustomException(&#8220;Throwing exception using throw keyword&#8221;);<br />
}<br />
}</p></div>
</div>
</td>
</tr>
<tr>
<td><a name="throws_keyword" href="http://www.java-questions.com/Exceptions_interview_questions.html#throws_keyword"><strong>Q10) What is use of throws keyword?</strong></p>
<p></a></p>
<div id="divQ29">
Ans) If the function is not capable of handling the exception then it can ask the calling method to handle it by simply putting the <strong>throws clause</strong> at the function declaration.</p>
<div>public void parent(){<br />
try{<br />
child();<br />
}catch(MyCustomException e){	}<br />
}</p>
<p>public void child throws MyCustomException{<br />
//put some logic so that the exception occurs.<br />
}</p></div>
</div>
</td>
</tr>
<tr>
<td><a name="Q9" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q9"><strong>Q11) What are the possible combination to write try, catch  finally block?</strong></p>
<p></a></p>
<div id="divQ9">
<p>Ans)</p>
<blockquote><p>&nbsp;</p>
<div>1)  try{</p>
<blockquote><p>//lines of code that may throw an exception</p></blockquote>
<p>}catch(Exception e){</p>
<blockquote><p>//lines of code to handle the exception thrown in try block</p></blockquote>
<p>}finally{</p>
<blockquote><p>//the clean code which is executed always no matter the exception occurs or not.</p></blockquote>
<p>}</p>
</div>
<div>
<p>2 try{</p>
<p>}finally{}</p>
<p>3 try{</p>
<p>}catch(Exception e){</p>
<p>//lines of code to handle the exception thrown in try block</p>
<p>}</p>
</div>
</blockquote>
<p>The catch blocks must always follow the try block. If there are more than one catch blocks they all must follow each other without any block in between. The finally block must follow the catch block if one is present or if the catch block is absent the finally block must follow the try block.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q10" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q10"><strong> Q12) How to create custom Exception?</strong> </a></p>
<div id="divQ10">
<p>Ans) To create you own exception extend the Exception class or any of its subclasses.</p>
<p>e.g.</p>
<p>1 class New1Exception extends Exception { } // this will create Checked Exception</p>
<p>2 class NewException extends IOExcpetion { } // this will create Checked exception</p>
<p>3 class NewException extends NullPonterExcpetion { } // this will create UnChecked exception</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q11" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q11"><strong>Q13) When to make a custom checked Exception or custom unchecked Exception?</p>
<p></strong></a></p>
<div id="divQ11">
<p>Ans) If an application can reasonably be expected to recover from an exception, make it a checked exception. If an application cannot do anything to recover from the exception, make it an unchecked exception.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q12" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q12"><strong>Q14)What is StackOverflowError?</strong></p>
<p></a></p>
<div id="divQ12">
<p>Ans) The StackOverFlowError is an Error Object thorwn by the Runtime System when it Encounters that your application/code has ran out of the memory. It may occur in case of recursive methods or a large amount of data is fetched from the server and stored in some object. This error is generated by JVM.</p>
<p>e.g. 				void swap(){</p>
<blockquote>
<blockquote><p>swap();</p></blockquote>
<p>}</p></blockquote>
</div>
</td>
</tr>
<tr>
<td><a name="Q13" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q13"><strong>Q15) Why did the designers decide to force a method to specify all uncaught checked exceptions that can be thrown within its scope?</strong></p>
<p></a></p>
<div id="divQ13">
<p>Ans) Any Exception that can be thrown by a method is part of the method&#8217;s public programming interface. Those who call a method must know about the exceptions that a method can throw so that they can decide what to do about them. These exceptions are as much a part of that method&#8217;s programming interface as its parameters and return value.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q14" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q14"><strong>Q16) Once the control switches to the catch block does it return back to the try block to execute the balance code?</strong></p>
<p></a></p>
<div id="divQ141">
<p>Ans) No. Once the control jumps to the catch block it never returns to the try block but it goes  to finally block(if present).</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q15" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q15"><strong>Q17) Where is the clean up code like release of resources is put in try-catch-finally block and why?</strong></p>
<p></a></p>
<div id="divQ15">
<p>Ans) The code is put in a finally block because irrespective of try or catch block execution the control will flow to finally block. Typically finally block contains release of connections, closing of result set etc.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q16" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q16"><strong>Q18) Is it valid to have a try block without catch or finally?</strong></a></p>
<div id="divQ16">
<p>Ans) NO. This will result in a compilation error. 			The try block must be followed by a catch or a finally block. 			It is legal to omit the either catch or the finally block but not both.</p>
<p>e.g.  The following code is illegal.</p>
<blockquote><p>try{<br />
int i =0;<br />
}<br />
int a = 2;<br />
System.out.println(“a =  “+a);</p></blockquote>
</div>
</td>
</tr>
<tr>
<td><a name="Q17" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q17"><strong> Q19) Is it valid to place some code in between try the catch/finally block that follows it?</strong></a></p>
<div id="divQ17">
<p>Ans) No. There should not be any line of code present between the try and the catch/finally block.</p>
<p>e.g.  The following code is wrong.</p>
<div>
<blockquote><p>try{}<br />
String str = “ABC”;<br />
System.out.println(“str  = “+str);<br />
catch(Exception e){}</p></blockquote>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q18" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q18"> <strong>Q20) What happens if the exception is never caught and throws down the method stack?</p>
<p></strong></a></p>
<div id="divQ18">
<p>Ans) If the exception is not caught by any of the method in the method’s stack till you get to the main() method, the main method throws that exception and the JVM halts its execution.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q19" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q19"> <strong>Q21) How do you get the descriptive information about the Exception occurred during the program execution?</p>
<p></strong></a></p>
<div id="divQ19">
<p>Ans) All the exceptions inherit a method printStackTrace() from the Throwable class. This method prints the stack trace from where the exception occurred. It prints the most recently entered method first and continues down, printing the name of each method as it works its way down the call stack from the top.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q20" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q20"><strong>Q22) Can you catch more than one exceptions in a single catch block?</strong></p>
<p></a></p>
<div id="divQ20">
<p>Ans)Yes. If the exception class specified in the catch clause has subclasses, any exception object that is a subclass of the specified Exception class will be caught by that single catch block.</p>
<p>E.g..</p>
<div>
<blockquote><p>try {</p>
<p>// Some code here that can throw an IOException</p>
<p>}</p>
<p>catch (IOException e) {</p>
<blockquote><p>e.printStackTrace();</p></blockquote>
<p>}</p></blockquote>
</div>
<p>The catch block above will catch IOException and all its subclasses e.g. FileNotFoundException etc.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q21" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q21"><strong>Q23)Why is not considered as a good practice to write a single catchall handler to catch all the exceptions?</strong></p>
<p></a></p>
<div id="divQ21">
<p>Ans) You can write a single catch block to handle all the exceptions thrown during the program execution as follows :</p>
<div>
<blockquote><p>try {</p>
<blockquote><p>// code that can throw exception of any possible type</p></blockquote>
<p>}catch (Exception e) {</p>
<blockquote><p>e.printStackTrace();</p></blockquote>
<p>}</p></blockquote>
</div>
<p>If you use the Superclass Exception in the catch block then you will not get the valuable information about each of the exception thrown during the execution, though you can find out the class of the exception occurred. Also it will reduce the readability of the code as the programmer will not understand what is the exact reason for putting the try-catch block.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q22" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q22"> <strong>Q24) What is exception matching?</strong></a></p>
<div id="divQ22">
<p>Ans) Exception matching is the process by which the the jvm finds out the matching catch block for the exception thrown from the list of catch blocks. When an exception is thrown, Java will try to find by looking at the available catch clauses in the top down manner. If it doesn&#8217;t find one, it will search for a handler for a supertype of the exception. If it does not find a catch clause that matches a supertype for the exception, then the exception is propagated down the call stack. This process is called exception matching.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q23" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q23"> <strong>Q25) What happens if the handlers for the most specific exceptions is placed above the more general exceptions handler?</strong> </a></p>
<div id="divQ23">
<p>Ans) Compilation fails. 					The catch block for handling the most specific exceptions 					must always be placed above the catch block written to handle the more general exceptions.</p>
<p>e.g. The code below will not compile.</p>
<div>
<blockquote><p>1 try {</p>
<p>// code that can throw IOException or its subtypes</p>
<p>} catch (IOException e) {</p>
<p>// handles IOExceptions and its subtypes</p>
<p>} catch (FileNotFoundException ex) {</p>
<p>// handle FileNotFoundException only</p>
<p>}</p></blockquote>
</div>
<p>The code below will compile successfully :-</p>
<div>
<blockquote><p>try {<br />
// code that can throw IOException or its subtypes<br />
} catch (FileNotFoundException ex)  {<br />
// handles IOExceptions and its subtypes<br />
} catch (IOException e){<br />
// handle FileNotFoundException only<br />
}</p></blockquote>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q24" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q24"> <strong> Q26) Does the order of the catch blocks matter if the Exceptions caught by them are not subtype or supertype of each other</strong></a></p>
<div id="divQ24">
<p>Ans) No. If the exceptions are siblings in the Exception class’s hierarchy i.e. If one Exception class is not a subtype or supertype of the other, then the order in which their handlers(catch clauses) are placed does not matter.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q25" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q25"><strong>Q27) What happens if a method does not throw an checked Exception directly but calls a method that does? What does &#8216;Ducking&#8217; the exception mean?</strong></p>
<p></a></p>
<div id="divQ25">
<p>Ans) If a method does not throw an checked Exception directly but calls a method that throws an exception then the calling method must handle the throw exception or declare the exception in its throws clause. If the calling method does not handle and declares the exception, the exceptions is passed to the next method in the method stack. This is called as ducking the exception down the method stack.</p>
<p>e.g. The code below will not compile as the getCar() method has not declared the CarNotFoundException which is thrown by the getColor () method.</p>
<div>
<blockquote><p>void getCar() {</p>
<blockquote><p>getColor();</p></blockquote>
<p>}</p>
<p>void getColor () {</p>
<blockquote><p>throw new CarNotFoundException();</p></blockquote>
<p>}</p></blockquote>
</div>
<p>Fix for the above code is</p>
<div>
<blockquote><p>void getCar() throws CarNotFoundException {</p>
<blockquote><p>getColor();</p></blockquote>
<p>}</p>
<p>void getColor () {</p>
<blockquote><p>throw new CarNotFoundException();</p></blockquote>
<p>}</p></blockquote>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q26" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q26"> <strong>Q28) Is an empty catch block legal?</p>
<p></strong></a></p>
<div id="divQ26">
<p>Ans) Yes you can leave the catch block without writing any actual code to handle the exception caught.</p>
<p>e.g. The code below is legal but not appropriate, as in this case you will nt get any information about the exception thrown.</p>
<blockquote><p>try{</p>
<p>//code that may throw the FileNotFoundException</p>
<p>}catch(FileNotFound eFnf){</p>
<p>//no code to handle the FileNotFound exception</p>
<p>}</p>
<p>&nbsp;</p>
</blockquote>
</div>
</td>
</tr>
<tr>
<td><a name="Q27" href="http://www.java-questions.com/Exceptions_interview_questions.html#Q27"><strong>Q29)Can a catch block throw the exception caught by itself?</strong></p>
<p></a></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=55&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2009/11/17/exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>

		<media:content url="http://www.java-questions.com/%5Cimg%5CExceptionClasses.png" medium="image">
			<media:title type="html">Exception</media:title>
		</media:content>
	</item>
		<item>
		<title>KeyWords</title>
		<link>http://interviewboard.wordpress.com/2009/11/17/keywords/</link>
		<comments>http://interviewboard.wordpress.com/2009/11/17/keywords/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:51:48 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[Basic]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/?p=53</guid>
		<description><![CDATA[Q1) What are different types of access modifiers in Java? Ans) There are four different types of modifiers: Modifer Accessible in the same package Accessible in different package Private No No Protected Yes Yes, only if the class extends the main class Default Yes No Public Yes Yes Q2) What is the use of final [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=53&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="15">
<tbody>
<tr>
<td><a name="Q1" href="http://www.java-questions.com/keywords_interview_questions.html#Q1"><strong>Q1) What are different  types of access modifiers in Java?</strong></a></p>
<div id="divQ1">
<p>Ans) There are  four different types of modifiers:</p>
<div>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="197" valign="top">Modifer</td>
<td width="197" valign="top">Accessible in the    same package</td>
<td width="197" valign="top">Accessible in    different package</td>
</tr>
<tr>
<td width="197" valign="top">Private</td>
<td width="197" valign="top">No</td>
<td width="197" valign="top">No</td>
</tr>
<tr>
<td width="197" valign="top">Protected</td>
<td width="197" valign="top">Yes</td>
<td width="197" valign="top">Yes, only if the    class extends the main class</td>
</tr>
<tr>
<td width="197" valign="top">Default</td>
<td width="197" valign="top">Yes</td>
<td width="197" valign="top">No</td>
</tr>
<tr>
<td width="197" valign="top">Public</td>
<td width="197" valign="top">Yes</td>
<td width="197" valign="top">Yes</td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q2" href="http://www.java-questions.com/keywords_interview_questions.html#Q2"> <strong>Q2) What is the use of final keyword?</strong></a></p>
<div id="divQ2">
<p>Ans) The final keyword can be assigned to</p>
<ol>
<li>Class level variable</li>
<li>method</li>
<li>class</li>
<li>Objects</li>
</ol>
<p>If a final is assigned to a variable, the variable behaves as a constant. It means that the value of variable once set cannot be changed.</p>
<blockquote><p>final int i=1;<br />
i =5; // error</p></blockquote>
<p>If a  final is assigned to a method then it cannot be  overridden in its child class.</p>
<div>
<p>class Parent {</p>
<blockquote><p>public final void  print(){System.out.println(“Inside”);</p>
<p>}</p></blockquote>
<p>}</p>
<p>class Child extends Parent{</p>
<blockquote><p>public final void  print(){             // error cannot  override final method</p>
<p>System.out.println(“Inside”);<br />
}</p></blockquote>
<p>}</p></div>
<p>If a  class is made as final, then no other class can  extend it and make it as parent class. E.g. String Class.</p>
<p>Final  objects are instantiated only once. i.e</p>
<p>final Map map = new HashMap();</p>
<p>map.put(“key”,”value”);</p>
<p>map = new HashMap();  // error</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q3" href="http://www.java-questions.com/keywords_interview_questions.html#Q3"><strong>Q3) What is use of synchronized keyword?</strong> </a></p>
<div id="divQ3">
<p>Ans) This keyword is used to prevent concurrency. Synchronized keyword can be applied to static/non-static methods or a block of code. Only one thread at a time can access synchronized methods and if there are multiple threads trying to access the same method then other threads have to wait for the execution of method by one thread. Synchronized keyword provides a lock on the object and thus prevents race condition. E.g.</p>
<div>
<p>public void synchronized method(){}<br />
public void synchronized staticmethod(){}<br />
public void myMethod(){</p>
<p>synchronized (this){             // synchronized keyword on block  of  code<br />
}</p>
<p>}</p>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q4" href="http://www.java-questions.com/keywords_interview_questions.html#Q4"><strong>Q4) What is volatile keyword?</strong> </a></p>
<div id="divQ4">
<p>Ans) In general each thread has its own copy of variable, such that one thread is not concerned with the value of same variable in the other thread. But sometime this may not be the case. Consider a scenario in which the count variable is holding the number of times a method is called for a given class irrespective of any thread calling, in this case irrespective of thread access the count has to be increased. In this case the count variable is declared as volatile. The copy of volatile variable is stored in the main memory, so every time a thread access the variable even for reading purpose the local copy is updated each time from the main memory. The volatile variable also have performance issues.</p>
</div>
</td>
</tr>
<tr>
<td><a name="What is a transient variable" href="http://www.java-questions.com/keywords_interview_questions.html#What%20is%20a%20transient%20variable"><strong>Q5) What is a transient variable?</strong></a></p>
<div id="divQ5">
<p>Ans) If some of the properties of a class are not required to be serialized then the varaibles are marked as transient. When an object is deserialized the transient variables retains the default value depending on the type of variable declared and hence lost its original value.</p>
</div>
</td>
</tr>
<tr>
<td><a name="what is strictfp modifier" href="http://www.java-questions.com/keywords_interview_questions.html#what%20is%20strictfp%20modifier"><strong>Q6) What is a strictfp modifier?</strong></a></p>
<div id="divQ6">
<p>Ans) Strictfp is used with variable only . It is used to restrict floating point calculations ( fp ) to ensure portability ( platform Independent ). When this modifier is specified, the JVM adheres to the Java specifications ( IEEE-754 floating-point specification ) and returns the consistent value independent of the platform. That is, if you want the answers from your code (which uses floating point values) to be consistent in all platforms, then you need to specify the strictfp modifier.</p>
</div>
</td>
</tr>
<tr>
<td><a name="what_is_static_variable" href="http://www.java-questions.com/keywords_interview_questions.html#what_is_static_variable"><strong>Q7) What is a static variable?</strong></a></p>
<div id="divQ7">
Ans) Static keyword can be used with the variables and methods but not with the class but there are static class. Anything declared as static is related to class and not objects.</p>
<p><strong>Static variable</strong> : Multiples objects of a class shares the same instance of a static variable.Consider the example:</p>
<div>
<p>public class Counter{</p>
<p>private static int count=0;</p>
<p>private int nonStaticcount=0;</p>
<p>public void incrementCounter(){</p>
<p>count++;</p>
<p>nonStaticcount++;</p>
<p>}</p>
<p>public int getCount(){</p>
<p>return count;</p>
<p>}</p>
<p>public int getNonStaticcount(){</p>
<p>return nonStaticcount;</p>
<p>}</p>
<p>&nbsp;</p>
<p>public static void main(String args[]){</p>
<p>Counter countObj1 = new Counter();</p>
<p>Counter countObj2 = new Counter();</p>
<p>countObj1.incrementCounter();</p>
<p>countObj1.incrementCounter();</p>
<p>System.out.println(&#8220;Static count for Obj1: &#8220;+countObj1.getCount());</p>
<p>System.out.println(&#8220;NonStatic count for Obj1: &#8220;+countObj1.getNonStaticcount());</p>
<p>System.out.println(&#8220;Static count for Obj2: &#8220;+countObj2.getCount())</p>
<p>System.out.println(&#8220;NonStatic count for Obj2: &#8220;+countObj2.getNonStaticcount())</p>
<p>}</p>
</div>
<div>
<p>Output</p>
<p>Static count for Obj1: 2</p>
<p>NonStatic count for Obj1: 2</p>
<p>Static count for Obj2: 2</p>
<p>NonStatic count for Obj2: 0</p>
</div>
<p>In the above program obj1 and obj2 share the same instance of static variable count hence if the value is incremented by one object , the incremented value will be reflected across the other objects</p></div>
</td>
</tr>
<tr>
<td><a name="what_is_static_method" href="http://www.java-questions.com/keywords_interview_questions.html#what_is_static_method"><strong>Q8) What is a static method?</strong></a></p>
<div id="divQ8">
Ans)A method defined as static is called static method. A static method can be accessed without creating the objects. Just by using the Class name the method can be accessed.</p>
<p>Static method can only access static variables and not local or global non-static variables. For eg:</p>
<div>public class Test{<br />
public static void printMe(){<br />
System.out.println(&#8220;Hello World&#8221;);<br />
}<br />
}<br />
public class MainClass{<br />
public static void main(String args[]){<br />
Test.printMe()</p>
<p>}<br />
}<br />
OutPut:<br />
Hello World</p></div>
<p>Also static method can call only static methods and not non static methods. But non-static methods can call static mehtods.</p></div>
</td>
</tr>
<tr>
<td><a name="Q9" href="http://www.java-questions.com/keywords_interview_questions.html#Q9"><strong>Q9) Why static methods cannot access non static variables or methods?</strong></a></p>
<div id="divQ9">
Ans) A static method cannot access non static variables or methods because static methods doesnt need the object to be  accessed. So if a static method has non static variables or non static methods which has instantiated variables they will no be intialized since the object is not created and this could result in an error.</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q10" href="http://www.java-questions.com/keywords_interview_questions.html#Q10"><strong>Q10) What is static class</strong>?</a></p>
<div id="divQ10">
Ans) A class cannot be declared static. But a class can be said a static class if all the variables and methods of the class are static and the constructor is private. Making the constructor private will prevent the class to be instantiated. So the only possibility to access is using Class name only</p>
</div>
</td>
</tr>
<tr>
<td><a name="throw_keyword" href="http://www.java-questions.com/keywords_interview_questions.html#throw_keyword"><strong>Q9) What is throw keyword?</strong></a></p>
<div id="divQ11">
Ans) Throw keyword is used to throw the exception manually. It is mainly used when the program fails to satisfy the given condition and it wants to warn the application.The exception thrown should be subclass of Throwable.</p>
<div>public void parent(){<br />
try{<br />
child();<br />
}catch(MyCustomException e){	}<br />
}</p>
<p>public void child{<br />
String iAmMandatory=null;<br />
if(iAmMandatory == null){<br />
throw (new MyCustomException(&#8220;Throwing exception using throw keyword&#8221;);<br />
}<br />
}</p></div>
</div>
</td>
</tr>
<tr>
<td><a name="throws_keyword" href="http://www.java-questions.com/keywords_interview_questions.html#throws_keyword"><strong>Q10) What is use of throws keyword?</strong></a></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=53&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2009/11/17/keywords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
		<item>
		<title>OOPS</title>
		<link>http://interviewboard.wordpress.com/2009/11/17/serialization/</link>
		<comments>http://interviewboard.wordpress.com/2009/11/17/serialization/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:48:11 +0000</pubDate>
		<dc:creator>technospider</dc:creator>
				<category><![CDATA[OOPS]]></category>

		<guid isPermaLink="false">http://interviewboard.wordpress.com/2009/11/17/serialization/</guid>
		<description><![CDATA[Q1) What is polymorphism? Ans) Polymorphism gives us the ultimate flexibility in extensibility. The abiltiy to define more than pne function with the same name is called Polymorphism. In java,c++ there are two type of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding). When you override methods, JVM determines the proper methods to call [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=50&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table cellspacing="15">
<tbody>
<tr>
<td><a name="Q1" href="http://www.java-questions.com/oops_interview_questions.html#Q1"><strong>Q1) What is   polymorphism? </strong></a></p>
<div id="divQ1">
<p>Ans) 		    <strong>Polymorphism</strong> gives us the ultimate flexibility in extensibility. The abiltiy to define more than pne function with the same name is called Polymorphism. In java,c++ there are two type of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding).</p>
<p>When you override methods, JVM determines the proper methods to call at the program’s run time, not at the compile time. Overriding occurs when a class method has the same name and signature as a method in parent class.</p>
<p>Overloading  occurs when several methods have same names with</p>
<ul>
<li>Overloading  is determined at the compile time.</li>
<li>Different  method signature and different number or type of parameters.</li>
<li>Same  method signature but different number of parameters.</li>
<li>Same  method signature and same number of parameters but of different type</li>
</ul>
<div>
int add(int a,int b)<br />
float add(float a,int b)<br />
float add(int a ,float b)<br />
void add(float a)<br />
int add(int a)<br />
void add(int a)                 //error conflict with the  method int add(int a)</p>
</div>
<ul>
Example: Overloading</ul>
<div>
Class BookDetails{<br />
String title;<br />
String publisher;<br />
float price;</p>
<blockquote><p>setBook(String title){<br />
}<br />
setBook(String title, String publisher){<br />
}<br />
setBook(String title, String publisher,float price){<br />
}</p></blockquote>
<p>}</p>
</div>
<p>Example: Overriding</p>
<div>
<p>class BookDetails{<br />
String title;</p>
<blockquote><p>setBook(String title){ 			        }</p>
<p>}</p></blockquote>
<p>class ScienceBook{</p>
<p>setBook(String title){}                                             //overriding</p>
<blockquote><p>setBook(String title, String publisher,float price){ 			    }  //overloading</p></blockquote>
<p>}</p>
</div>
</div>
</td>
</tr>
<tr>
<td><a name="Q2" href="http://www.java-questions.com/oops_interview_questions.html#Q2"><strong>Q2) What is  inheritance?</strong></a></p>
<div id="divQ2">
Ans) Inheritance is the property which allows a Child class to inherit some properties from its parent class. In Java this is achieved by using extends keyword. Only properties with access modifier public and protected can be accessed in child class.</p>
<div>
<p>public class Parent{</p>
<p>public String parentName;<br />
public int parentage;<br />
public String familyName;<br />
}</p>
<p>public class Child extends Parent{</p>
<p>public String childName;<br />
public int childAge;</p>
<p>public void printMyName(){<br />
System.out.println(“ My name is “+ chidName+” “ +familyName)<br />
}</p>
<p>}</p>
</div>
<p>In above example the child has inherit its family name from the parent class just by inheriting the class.</p></div>
</td>
</tr>
<tr>
<td><a name="Q3" href="http://www.java-questions.com/oops_interview_questions.html#Q3"><strong>Q3) What is multiple  inheritance and does java support?</strong></a></p>
<div id="divQ3">
Ans) If a child  class inherits the property from multiple classes is known as multiple  inheritance.<br />
Java does not allow to extend multiple classes but to  overcome this problem it allows to implement multiple Interfaces.</div>
</td>
</tr>
<tr>
<td><a name="Q4" href="http://www.java-questions.com/oops_interview_questions.html#Q4"><strong>Q4) What is  abstraction?</strong></a></p>
<div id="divQ4">
Ans) Abstraction is way of converting real world objects in terms of class. For example creating a class Vehicle and injecting properties into it. E.gpublic class Vehicle {</p>
<p>public String colour;<br />
public String model;<br />
}</p>
</div>
</td>
</tr>
<tr>
<td><a name="Q5" href="http://www.java-questions.com/oops_interview_questions.html#Q5"><strong>Q5) What is data  hiding?</strong></a></p>
<div id="divQ5">
Ans) The way of providing restriction to the access of property of a class is called data hiding. In java this is achieved by using access modifiers: &#8211; public, private, protected and default.</div>
</td>
</tr>
<tr>
<td><a name="Q6" href="http://www.java-questions.com/oops_interview_questions.html#Q6"><strong>Q6) What is  encapsulation?</strong></a></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/interviewboard.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/interviewboard.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/interviewboard.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=interviewboard.wordpress.com&amp;blog=10112560&amp;post=50&amp;subd=interviewboard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://interviewboard.wordpress.com/2009/11/17/serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c9a8b6935af2a6cea279dc43632c4552?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">technospider</media:title>
		</media:content>
	</item>
	</channel>
</rss>
