3 ms·
I'm not saying it's a good task, I'm saying that people failed it despite we were thinking the task is trivial. But still, I'd expect Java developer to know th
by orless 10y ago
I'm not saying it's a good task, I'm saying that people failed it despite we were thinking the task is trivial.
But still, I'd expect Java developer to know that Java strings are immutable and that you can't treat them as character arrays. It's totally OK to not know how toArray method is called (toCharArray). Assuming there's a kind of "reverse" method is a bad idea - even if there would have been one, it would clearly be not what we ask. Same for "I'd use StringUtils.reverse(...)" from whatever package. I won't mind if you write a.length() for array or a.length for String, this does not matter much. Knowing a difference between a byte and a char is, however, quite important in my book.
The "usual" solution is to str.toCharArray() and then iterate this array to the middle, swapping i-th and (length - i - 1)-th characters, then new String(array) with the result.
For this solution you only need to know fundamentals of the language and vaguely recall that there was some method to convert string to a character array.
Bonus points (figuratively speaking, there were no actual points) were for: writing test cases, checking the argument for not being null or showing how to swap two characters without using an additional variable.
Do you think IDE would help much? I don't think so. IDE would have helped you with the unimportant part (how was that toArray() method called exactly). But you'd need to know how to use a cycle to reverse an array. You need to know what the difference between a byte and a char is (in order not to choose the getBytes() method instead toCharArray()).
- ashark 10y ago> Do you think IDE would help much? I don't think so. It'd help quite a bit with the parts that make writing this in Java different from talking through a pseudocode implementation, yeah. Or just let them write pseudocode instead, since you've written you don't care much about the details (aside from knowing you need to take care when manipulating strings that you're operating on the correct unit in order not to turn it into gibberish, which is a universal detail, not specific to Java). Bonus to that approach: you haven't just made your candidate incredibly self conscious over and distracted by things you apparently didn't care about to begin with, and there's also a lower chance they'll try to correctly use the language in ways you don't like and expected them to guess you don't like (e.g. using a single utility method that solves the problem immediately).
- orless 10y agoWe've tried it with pseudocode. People wrote Java.
- watwut 10y agoThe IDE would make huge difference for me and this question. It would allow me to instantly know string api which I normally don't need. Also, it would add confidence that what I am doing is actually java. I don't mind whiteboard in general, however expecting me to solve language specific question like this is weird - especially in language like java that is never written without IDE.
- orless 10y agoWell, yes, in an interview for a Java dev position I'd expect the candidate to be able to write code (whiteboard/paper) which at least remotely resembles Java syntax, is logically correct and does not break universal things like byte vs. char.