<?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; opinion</title>
	<atom:link href="http://www.certpal.com/blogs/tag/opinion/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>
		<item>
		<title>Response: Are Naming Conventions Still Needed For Abstract Classes?</title>
		<link>http://www.certpal.com/blogs/2009/09/java-abstract-class-prefix/</link>
		<comments>http://www.certpal.com/blogs/2009/09/java-abstract-class-prefix/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 13:42:38 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=304</guid>
		<description><![CDATA[Abstract java classes are usually prefixed with the word Abstract. Do we really need this standard ?]]></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-abstract-class-prefix%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-abstract-class-prefix%2F&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I came across <a href="http://www.adam-bien.com/roller/abien/entry/are_naming_conventions_still_needed" target="_blank">a post on the Adam Bien blog</a> recently about using the prefix &#8216;<strong>Abstract</strong>&#8216; to define Abstract classes. The argument was that using the &#8216;<strong>Abstract</strong>&#8216; prefix is superfluous. I do not fully agree with the post. As I read the points he had mentioned on the post, here are some that came to mind</p>
<blockquote><p><span style="color: #000080;">Abstract classes are already distinguishable by the keyword abstract. There is no need to further emphasize it.</span></p>
<p><span style="color: #000080;">A prefix &#8220;Abstract&#8221; doesn&#8217;t provide any additional value to the user &#8211; in contrary it blurs the actual intention</span></p></blockquote>
<p>The Abstract in the class name helps a developer know that a class is Abstract even before they open it. Of course if some one bucks the convention and names a Concrete class abstract, it creates confusion but that scenario is rare.</p>
<blockquote><p><span style="color: #000080;">Modern IDEs don&#8217;t let you instantiate an abstract class, even before saving / compiling.</span></p></blockquote>
<p>The IDE would not let you instantiate the class whether or not the Abstract prefix is placed on the class name. If Abstract is used as a prefix, a developer would know before hand that the class is abstract.</p>
<blockquote><p><span style="color: #000080;">If you really have to, it is easy to find / distinguish an abstract class with modern IDEs.</span></p></blockquote>
<p>An IDE should be able to give you such a filter, but I wonder if it is a common feature across IDEs. I am not aware of a shortcut in eclipse that can do this (it might exist, I am just not aware of one). When I want to open an Abstract class, I type ctrl+shift+R and type &#8216;abstract&#8217;. That usually yields good results.</p>
<blockquote><p><span style="color: #000080;">Even in UML class diagrams abstract classes are easy to distinguish &#8211; their name is italicized.</span></p></blockquote>
<p>This is true. If you name your class AbstractSomething just because you want to distinguish them in UML diagrams, it is not justifiable.</p>
<p>So what good does an Abstract prefix do for a class ? Here is my opinion</p>
<ol>
<li> Developers know a class is Abstract without opening it.</li>
<li>The name helps the developer realize that the class is meant to be inherited by a subclass, which will provide methods that the boiler plate does not.</li>
<li>Provides a developer one more way to search for Abstract classes.</li>
</ol>
<p>In summary I would say that whether or not you want to use the Abstract prefix depends. Most boiler plate classes that you encounter (non abstract) use the word Default as a prefix. Example &#8211; <strong>DefaultContentHandler</strong>. Boiler plate code with some abstract methods use the word &#8216;Abstract&#8217; as a prefix. Example &#8211; <strong>AbstractList</strong>. There are classes that do not follow the convention, but I would still vote for the word Abstract as a prefix because of the advantages that it presents.<br />
<script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2009/09/java-abstract-class-prefix/';</script><br />
<script type="text/javascript">var dzone_title = 'Response: Are Naming Conventions Still Needed For Abstract Classes?';</script><br />
<script type="text/javascript">var dzone_blurb = 'Abstract java classes are usually prefixed with the word Abstract. Do we really need this standard ?';</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-abstract-class-prefix%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Fjava-abstract-class-prefix%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-abstract-class-prefix/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

