<?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>CertPal &#187; interview</title>
	<atom:link href="http://www.certpal.com/blogs/tag/interview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Mon, 18 Jul 2011 06:48:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Java Interviews and trick questions</title>
		<link>http://www.certpal.com/blogs/2009/09/java-interviews-and-trick-questions/</link>
		<comments>http://www.certpal.com/blogs/2009/09/java-interviews-and-trick-questions/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 18:26:13 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=331</guid>
		<description><![CDATA[Interviews, be it for the java language or not, do not deserve to be sprinkled with trick questions. Here are some thoughts that back up this claim.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-interviews-and-trick-questions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-interviews-and-trick-questions%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="alignright size-medium wp-image-333" title="java_interview" src="http://www.certpal.com/blogs/wp-content/uploads/java_interview-300x193.jpg" alt="java_interview" width="180" height="116" />I have taken many java interviews over the last few years. As time passed by, I learned from mistakes I have made. One of them being to ask candidates trick questions or questions that do not necessarily have an obvious answer.</p>
<p>I read a <a href="http://whyjava.wordpress.com/2009/09/24/java-puzzlers-are-asked-in-interviews/" target="_blank">blog post recently</a> that detailed such a question. I will highlight the question here along with the answer</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JavaPuzzler<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        HashSet<span style="color: #339933;">&lt;</span>Short<span style="color: #339933;">&gt;</span> s <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>Short<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//1</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">short</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//2</span>
            s.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//3</span>
            s.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//4</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//5</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Can you guess the answer to this question ? Simply drag and select the text near the spoiler to see the answer.</p>
<p><strong>Spoiler: </strong><span style="color: #ffffff;">The answer to the question is 100. The gotcha is that the statement s.remove(i-1); at //4 will autobox to an Integer and not a Short. Equals comparison between an Integer and Short fails. </span></p>
<p>This is a nice gotcha. One more to add to the collection of <a href="http://www.certpal.com/blogs/2009/08/autoboxing-unboxing-gotchas/" target="_blank">autobox/unbox gotchas</a> . But by no means is this a fair interview question. The candidate may not know java 5 and this reduces the scope of the question. Debugging this problem is also quite difficult. Finding the bug is even more difficult without a debugger. Asking a programmer for the answer by giving him/her this question on a piece of paper is unfair.</p>
<p>I sometimes do ask questions that absolutely do not make sense. These are asked so that the candidate will (hopefully) call out my bull poop. For example I say something ridiculous like &#8216;But if the client can request for the JSP page, all he/she has to do is right click -&gt; View source and they can see the JSP code&#8230;.&#8217;. Most candidates stop me and say &#8216;huh ? are you kidding me ?&#8217;. Some go the distance and give me a stare. Others respond and say &#8216;Yeah. Perhaps we need to use SSL&#8217;. This question does help an interviewer know if the candidate knows what he/she is talking about or simply nods and tries to answer every question.</p>
<p>This question is however not intended for everyone. I ask this question to about 5% of the sample space, as a litmus test, only if I suspect that I am dealing with a bad apple. Asking the question to everyone would do some damage, since a good candidate may wonder &#8216;mmm&#8230; do I really want to work at a place where some one thinks this is possible ?&#8217; and misintepret the question&#8217;s real intention.</p>
<p>When you interview some one for a DEV position, it is imperative that they write code and display problem solving skills. It is however not beneficial to the process if we add trick questions to the lot. It does not say anything about the candidate, whether or not they get the question right. </p>
<p><strong>PS:</strong> The author of the blog that posted this question also agrees that it is not fair to ask it. I do hope we see less of it in interviews <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2009/09/java-interviews-and-trick-questions/';</script><br />
<script type="text/javascript">var dzone_title = 'Java Interviews and trick questions';</script><br />
<script type="text/javascript">var dzone_blurb = 'Interviews, be it for the java language or not, do not deserve to be sprinkled with trick questions.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-interviews-and-trick-questions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-interviews-and-trick-questions%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/09/java-interviews-and-trick-questions/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

