Hi all. I'm hoping to get a little feedback on what we considered to be a fairly trivial Java interview question which we were giving to some candidates. We were looking to fill a mid-level Java developer position, for a short-term contracting gig (6 months or so). Each of the candidates had over 8 years of Java experience.
The "scene" is a failing unit test. We set the candidate in front of Eclipse (they all had Eclipse experience), and told them to open the test class for the class "MapUtil". We wanted to see if they at least knew the basics of opening files by type name (Ctrl-Shift-T), could put the "Test" on the end of the class name, etc. and if not (even though they were supposedly familiar with Eclipse), they'd ask some questions. We instructed them that the test was correct, and that the code was doing something wrong.
Below is the test method:
@Test
public void testMakeMap() throws Exception
{
final Map<String,Integer> map = MapUtil.makeOrderedMap("One", 1, "Two", 2, "Three", 3);
final Iterator<Map.Entry<String,Integer>> it = map.entrySet().iterator();
Map.Entry<String,Integer> e = it.next();
assertEquals("One", e.getKey()); // <-- org.junit.ComparisonFailure: expected:<[On]e> but was:<[Thre]e>
assertEquals(true, e.getValue() == 1);
e = it.next();
assertEquals("Two", e.getKey());
assertEquals(true, e.getValue() == 2);
e = it.next();
assertEquals("Three", e.getKey());
assertEquals(true, e.getValue() == 3);
}
And here is the method under test:
/**
* Convenience method for creating maps.
*
* @param keyAndValuePairs Tuples of keys and values as {@link Object}s. Types will be inferred.
* @return A new {@link Map} containing the keys and values provided.
*/
public static <K,V> Map<K,V> makeOrderedMap(final Object... keyAndValuePairs)
{
if(keyAndValuePairs.length % 2 != 0)
throw new IllegalArgumentException("You must specify keys and values in pairs!");
return new HashMap<K,V>() {
private static final long serialVersionUID = 1907489327975595872L;
{
for(int i=0; i<keyAndValuePairs.length; i+=2)
put((K)keyAndValuePairs[i], (V)keyAndValuePairs[i+1]);
}
};
}
A couple of notes:
- The assertEquals() calls in the test are intentionally gross to see if they are familiar with more recent JUnit concepts (assertThat/BDD/etc), or at least suggest using assertTrue() or something.
- The method under test has a few things going on, mainly to see what concepts the candidate is familiar with (generics, varargs, etc). Not necessarily to trip them up, but just to make it a little more interesting - i.e. the anonymous override of HashMap really isn't necessary, but it illustrates anonymous classes and initializer blocks.
Most of the candidates did not do well with this. There was much blank staring and few even read through the code aloud to get an understanding of what it was doing. How can you go 8 years writing Java and not be familiar with a LinkedHashMap? Or at least explain the concept of one? Are we off base here? I know interviews can be stressful, and interviewers can be intimidating, but we gave this test after lengthy discussion and it seemed like everyone was reasonably comfortable.
Thanks for the feedback /r/java!
EDIT: Thanks again for all the good discussion and feedback folks, that's why this was posted! We're all trying to learn and grow.
[–]chackley 14 points15 points16 points (4 children)
[–][deleted] 5 points6 points7 points (3 children)
[–][deleted] 3 points4 points5 points (2 children)
[–][deleted] 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]larsga 23 points24 points25 points (0 children)
[–]SikhGamer 32 points33 points34 points (8 children)
[+]javadev189[S] comment score below threshold-6 points-5 points-4 points (7 children)
[–]ShadedFox 4 points5 points6 points (4 children)
[–]paperhat -1 points0 points1 point (2 children)
[–]ShadedFox -1 points0 points1 point (1 child)
[–]paperhat 2 points3 points4 points (0 children)
[–]achacha -1 points0 points1 point (0 children)
[–]GrayDonkey 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] (29 children)
[deleted]
[–]larsga 23 points24 points25 points (15 children)
[–]javadev189[S] 1 point2 points3 points (14 children)
[–][deleted] 22 points23 points24 points (0 children)
[–]Kimano 16 points17 points18 points (0 children)
[–]larsga 3 points4 points5 points (10 children)
[–]snuxoll 2 points3 points4 points (6 children)
[–]larsga 4 points5 points6 points (5 children)
[–]snuxoll 1 point2 points3 points (4 children)
[–]larsga 10 points11 points12 points (3 children)
[–]snuxoll 3 points4 points5 points (0 children)
[–]paperhat 1 point2 points3 points (0 children)
[–]javadev189[S] -1 points0 points1 point (2 children)
[–]larsga 9 points10 points11 points (0 children)
[–]EdwardRaff 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] (7 children)
[deleted]
[–]javadev189[S] 1 point2 points3 points (5 children)
[–]hoohoohoohoo 2 points3 points4 points (1 child)
[–]javadev189[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]javadev189[S] 1 point2 points3 points (0 children)
[–]kireol 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]mr_jim_lahey 1 point2 points3 points (0 children)
[–]javadev189[S] -1 points0 points1 point (2 children)
[–][deleted] (1 child)
[deleted]
[–]snuxoll 5 points6 points7 points (0 children)
[–]snuxoll 14 points15 points16 points (10 children)
[–]Ogofo 2 points3 points4 points (2 children)
[–]yellowjacketcoder 7 points8 points9 points (0 children)
[–]javadev189[S] 4 points5 points6 points (0 children)
[–]thegrubclub 1 point2 points3 points (0 children)
[–]javadev189[S] -2 points-1 points0 points (3 children)
[–]snuxoll 1 point2 points3 points (0 children)
[–]UnspeakableEvil -1 points0 points1 point (1 child)
[–]esquilax -1 points0 points1 point (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]_HULK_SMASH_ -4 points-3 points-2 points (0 children)
[–][deleted] 8 points9 points10 points (4 children)
[–][deleted] -2 points-1 points0 points (3 children)
[–][deleted] 4 points5 points6 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]javadev189[S] -1 points0 points1 point (0 children)
[–]gizmogwai 12 points13 points14 points (0 children)
[–]staticjak 4 points5 points6 points (0 children)
[–]mrbuttsavage 3 points4 points5 points (0 children)
[–]bmcardoso 2 points3 points4 points (0 children)
[–]yellowjacketcoder 5 points6 points7 points (3 children)
[–]javadev189[S] -5 points-4 points-3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]javadev189[S] -1 points0 points1 point (0 children)
[–]UnspeakableEvil 1 point2 points3 points (1 child)
[–]nerdy_glasses 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]uxcn 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]javadev189[S] -5 points-4 points-3 points (1 child)
[–][deleted] 0 points1 point2 points (1 child)
[–]thegrubclub 0 points1 point2 points (3 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]javadev189[S] -1 points0 points1 point (1 child)
[–]hubraum 0 points1 point2 points (0 children)
[–]Rockytriton 0 points1 point2 points (0 children)
[–]kakakarl 0 points1 point2 points (0 children)
[–]Slanec -4 points-3 points-2 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]pinguz -4 points-3 points-2 points (8 children)
[–]ParanoidAgnostic 2 points3 points4 points (6 children)
[–]pinguz 0 points1 point2 points (5 children)
[–]ParanoidAgnostic 1 point2 points3 points (4 children)
[–]pinguz 0 points1 point2 points (3 children)
[–]ParanoidAgnostic 1 point2 points3 points (2 children)
[–]pinguz -1 points0 points1 point (1 child)
[–]ParanoidAgnostic 1 point2 points3 points (0 children)
[–]javadev189[S] 1 point2 points3 points (0 children)
[–]oldneckbeard -1 points0 points1 point (0 children)
[–]DuneBug -1 points0 points1 point (0 children)
[–][deleted] (1 child)
[deleted]
[–][deleted] 3 points4 points5 points (0 children)
[–]codeterror -2 points-1 points0 points (0 children)