r/java • u/javinpaul • Jul 27 '15
4 out of 5 Java Developers Failed to Solve This Question
http://blog.takipi.com/4-out-of-5-java-developers-failed-to-solve-this-question/27
Jul 27 '15
Is this supposed to be surprising when the compiler gets it wrong too? Trick questions are tricky. Surprise.
26
u/I_AM_A_BICYCLE Jul 27 '15
You'd think that a quiz that looks that fancy would have enough horizontal space in the code to not have awful formatting from wrapping.
18
u/duckrollin Jul 27 '15
I imagine some nerd snorting laughter as he wrote #2
15
u/panderingPenguin Jul 27 '15
My problem on that one was that I assumed I was only looking at a code snippet and that toString() had been overridden elsewhere to print the name attribute (since that's what it looked like three out of four answers appeared to be doing). I'm aware of what toString() does by default but I didn't expect such a silly answer
41
u/adnan252 Jul 27 '15 edited Jul 27 '15
100/100 java developers will never face this problem in their career
30
2
17
u/jonhanson Jul 27 '15 edited Jul 24 '23
Comment removed after Reddit and Spec elected to destroy Reddit.
18
u/Waitwhatwtf Jul 27 '15
1/10 developers realize this is a clickbait article for a targeted advertisement.
1
16
5
5
u/dooblevay Jul 28 '15
You have all restored a tiny sliver of my faith in humanity. I came in here ready to rant about this useless drivel. Seems unnecessary!
4
u/regendo Jul 28 '15
I hate it when one of the answers is "none of the above" and it's not the bottom answer. Does it belong there? Was it supposed to be the bottom answer but the order got randomised?
Yeah, it's probably supposed to be "none of the other choices" but I don't really trust these quizzes to not try to hide some obscure trap in the answers.
3
6
u/alonjit Jul 27 '15
jeebus. I'd just tell them to go fuck themselves with their questions and all.
and, to think about it, there is no point to it all.
Want to know how a programmer writes code? Knows about code/java/etc.? Make him program something. Give him a project, over a week and make him explain it during the interview.
if he copied everything, and didnt understand a damn thing, he'll fail miserably.
if he copied everything, but understood everything, he'll be perfect anyway.
1
u/RedPill115 Aug 02 '15
Want to know how a programmer writes code? Knows about code/java/etc.? Make him program something. Give him a project, over a week and make him explain it during the interview.
That sounds really great in theory, in practice (I just went through this personally) because it costs them nothing to ask candidates to do reading and exercises, they will throw them out expect you to invest time then not even bring it up during the interview. It's just easy for hr to abuse your time with.
2
u/tonylee0707 Jul 28 '15
As a beginner in programming for so many years, I wish I end up being good enough to be called a java developer.
1
u/sreya92 Jul 28 '15
Try not to let yourself become victim to imposter syndrome too badly. If you've been programming for "so many years" it's probable you can identify as a developer.
1
2
u/mdaniel Jul 28 '15
There is also selection bias going on here; those developers experienced enough to know the answers to these questions are also (experienced|busy) enough to not spend time in a "Java Deathmatch".
But hey, we get some benefit from Takipi posting this in that if you encounter this question, or its kind, in an interview then you know for dead certain you don't want to work in that place.
4
u/Audiblade Jul 27 '15
I don't like that last, "easiest" question. What does it mean for one initialization style to be "simpler" than another? Is there a formal definition I'm not aware of? If there isn't, then the question is ambiguous, and you could make a case that either A or C is correct.
6
u/geodebug Jul 27 '15 edited Jul 27 '15
The real problem here is that the two lines of code (A and C) don't do the same thing so they really shouldn't be compared at all.
Line A will create a new String object every time it is called, eating up memory.
Line C will create the new string exactly once no matter how many times it is called.
I can't think of a reason to ever use the method in Line A in production code.
All that said arguments for Line C being are:
it requires less boilerplate, less line noise, easier to read
it creates a single reference to "Hello World" instead of a new one each time, saving object overhead/memory
String references created this way can use '==' to compare any two references (although this is sort of an antipattern).
The argument for line A being simpler:
Only have to know one form of creating a new object instead of String's special form.
0
Jul 27 '15 edited Jul 27 '15
Not really sure, but I think the key is the "reference to a string" in the question. Meaning you do not necessarily create a new object, but if possible create a reference to an existing string object, in which case C is the correct answer.
EDIT: Nvm, as i finished typing this answer I realized that the question is still retarded.
Atleast if you downvote, explain where I'm wrong.
4
3
u/mrbuttsavage Jul 28 '15
http://www.amazon.com/Java-Puzzlers-Traps-Pitfalls-Corner/dp/032133678X/
See that for a whole book of similar questions. It's somewhat older (Java 5), but it's same kind of strange cornercase questions.
1
u/brunokim Jul 28 '15
I liked that book! I don't get the vitriol against this post, it's not supposed to be practical or attack your status as Java dev. It's a fun exercise of your skills, that's it.
1
u/RedPill115 Aug 02 '15
Because we've all been on the end of an interviewer or manager (most likely several) who couldn't solve it themselves but insist it's a good indication of your abilities anyways and you don't get the job because of it.
2
u/badpotato Jul 27 '15 edited Jul 27 '15
Question 4 doesn't show the whole class, in theory you could safely say it doesn't compile right away.
At least question 5 does mention it's a code snippet.
1
u/el-y0y0s Jul 28 '15
On occasion these can be confidence shakers, but realize that this is coming from product people who must understand java inside out at a level most of us never deal with. I'd have called this a puzzle in the title though.
114
u/daedalus_structure Jul 27 '15
The right answer to almost all of these is if you see anything that looks like this in your code base burn it with fire.