Writing an interview test for java expert
<p>I'm currently writing an interview question for a <em>java expert profile</em>. Here it is:</p>

<hr>

<p>Considering this code :</p>

<p><strong>listing 1</strong></p>

<pre><code>package com.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Searching {
    public static void main(String[] args) {
        int input = Integer.valueOf(args[0]);
        String[] strings = {"1", "2", "4", "8", "16", "32", "64", "128"};
        List&lt;Integer&gt; integers = new ArrayList&lt;Integer&gt;();
        for (String s : strings) {
            integers.add(Integer.valueOf(s));
        }
        System.out.println("index of "+input+" is:"+Collections.binarySearch(integers, input, cmp));
    }

    static Comparator&lt;Integer&gt; cmp = new Comparator&lt;Integer&gt;() {
        public int compare(Integer i, Integer j) {
            return i &lt; j ? -1 : (i == j ? 0 : 1);
        }
    };
}
</code></pre>

<p>This code is then compiled with this cmd line</p>

<p><strong>listing 2</strong></p>

<pre><code>javac com/example/Searching.java
</code></pre>

<p>and run with this command line</p>

<p><strong>listing 3</strong></p>

<pre><code>java com/example/Searching 128
</code></pre>

<p><strong>QUESTION A:</strong></p>

<p>Executing listing 3 produce:</p>

<pre><code>index of 128 is:-8
</code></pre>

<p>Can you explain this output ?</p>

<p><strong>QUESTION B:</strong></p>

<p>Considering this</p>

<pre><code> java com/example/Searching 32
</code></pre>

<p>output is</p>

<pre><code>index of 32 is:5
</code></pre>

<p>Can you explain this output ?</p>

<p><strong>QUESTION C:</strong></p>

<p>Assuming you have a JRE 1.6, a shell, and a text editor. What would you change to listing 1 and/or listing 2 and/or listing 3 to produce this output:</p>

<pre><code>index of 128 is:7
</code></pre>

<p><em>remark:</em> the less you change, the better it is.</p>

<hr>

<p>My questions are :</p>

<ul>
<li>what would be your answer to those questions ?</li>
<li>how to improve it ?</li>
</ul>
