What are some good interview questions for Java developers?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
Status
Not open for further replies.

Cogman

Lifer
Sep 19, 2000
10,286
145
106
The point was to catch people who couldn't code at all. And, as I recall, Java's file I/O is pretty terrible, so I'd be tempted to go with iteration first and work upward from there. All the same, pseudocode would work as well, even if you can't remember all the BufferedReader garbage off the top of your head.

I might add that a good interviewee would say something like "I don't remember/know the syntax for doing file IO. However, it generally follows these steps.." and go from there. A company that won't hire you because you don't know a specific syntactical nicety is probably not the company which you want to work for.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
I understand the rationale. I just don't agree with the implementation. There are times, for example, when I may want to catch an exception one level up from the actual caller of the method that threw it. It shouldn't be a compiler error not to handle an exception. A warning, sure, but it shouldn't prevent building and running.

I guess as mod I shouldn't be facilitating this threadjack, should I? :)

:p You started it :D. BTW, IMO the compiler should do as much as possible to compile code. It should be general enough that an error is pretty dang hard to create. That being said, it should throw warning for every possible problem that ever could exist (and provide the switches to enforce those warning or ignore them all together.) Forced exceptions creates more problems than solutions and ultimately leads to pointless code bloat.
 

Monster_Munch

Senior member
Oct 19, 2010
873
1
0
I would stick to more general questions, like why would you use a while loop instead of a for loop? or what do the keywords "volatile", "synchronized" and "instanceof" mean?
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
I would stick to more general questions, like why would you use a while loop instead of a for loop? or what do the keywords "volatile", "synchronized" and "instanceof" mean?

Those really don't pick out the crappy programmers, however. If all your questions are on the exact same level, then you never really find out what the programmer is capable of.

This is my recommendation. Start off easy, If they do well, increase difficulty. If they do poorly, they are not the one. You should try and push them in the interview. Find out what the extent of their knowledge really is. This has the added bonus of showing what they do when they don't know something (a valuable skill in programming).

Asking specific syntax questions is a good way to filter out good programmers. It is more important, IMO, to find someone that knows how to program in general than it is to find someone that knows how to program Java.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
I understand the rationale. I just don't agree with the implementation. There are times, for example, when I may want to catch an exception one level up from the actual caller of the method that threw it. It shouldn't be a compiler error not to handle an exception. A warning, sure, but it shouldn't prevent building and running.

I guess as mod I shouldn't be facilitating this threadjack, should I? :)

Don't forget that fact that if you change code and in the future and you must throw new exceptions, then you break/change your interfaces.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
Don't forget that fact that if you change code and in the future and you must throw new exceptions, then you break/change your interfaces.

This is really the problem with any error checking or interface. A change down low has a good chance of breaking things up above.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
This is my recommendation. Start off easy, If they do well, increase difficulty. If they do poorly, they are not the one. You should try and push them in the interview. Find out what the extent of their knowledge really is. This has the added bonus of showing what they do when they don't know something (a valuable skill in programming).

I would agree with this. After going through some tough interviews in the past, if an interviewer leads with a really difficult question you don't have time to get "comfortable" in the interview setting.

Asking specific syntax questions is a good way to filter out good programmers. It is more important, IMO, to find someone that knows how to program in general than it is to find someone that knows how to program Java.

A good programmer will be able to pick up a new language easily, so I wouldn't dwell much on syntax.
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
1) What is your name?
2) What is your favorite color?
3) What is your quest?
4) What is the air-speed velocity of an unladen swallow?

:awe:
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Ok, now we're definitely not helping the OP, and I am at least half responsible :). Let's haul back on track and give the guy some interview questions, or start another thread where we can talk about funny faux interview questions for Java candidates, such as Q. Why don't you learn C#?
 

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
Some questions that I would ask, were I ever in a position to ask them:

General work attitude and approach

1. Describe a project where the code you developed was of a poor quality.
2. A co-worker maintains an important library to which your code interfaces. It is full of bugs, and he is reluctant to fix them, or even acknowledge them. He is difficult to contact, and unreliable when asked for help. How do you deal with this?
3. How did you use your initiative while working on your most recent project?

Technical (after weeding out the morons).

1. What are the problems with recursion? How might you avoid them?
2. What makes code 'thread-safe'?
3. Are you aware of any problems where there are multiple algorithms with different computational complexities? Would you ever use an algorithm even if a more efficient one is available?

Off the wall
1. If you had the opportunity to do your school time again, but could not do it at the same place, where would you go?
2. Tell me something interesting about yourself that you haven't mentioned in your resume.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
Ok, now we're definitely not helping the OP, and I am at least half responsible :). Let's haul back on track and give the guy some interview questions, or start another thread where we can talk about funny faux interview questions for Java candidates, such as Q. Why don't you learn C#?

Well, this was a necrobump.. I don't know that the OP is really all that interested any more.

Here are a few I might ask.

Why is Python better than C++? Why is C++ better than python? etc. My reasoning with this one is that I don't want rabid fanboys that can't recognize that pretty much all languages have their failing and niceties. It also shows that they really are interested in this sort of stuff.

The next question I might as (in a similar vein) is something like "I want to make a dynamic webpage, what should my backend language be?" and "I want to make a high speed video encoder, what should my language be?" I would be worried if they didn't ask questions to qualify how those applications would be used, and wouldn't consider them if they recommended the same language for both.

Other questions might involve stuff like.
"Would you ever use an n^3 algorithm over an n^2 algorithm?" and "can an n^3 algorithm be faster than an n^2 algorithm."

Other things I might do. I might just chat with them about a current tech event. Be it programming or hardware "So did you hear about intels new CPU?" or "What do you think about the lawsuit over Google's Go language". This would have two purposes, the first is to make sure that they are excited about technology (if they knew about all the news stuff, that in itself would be impressive.) but it would also show whether they are capable of discussing tech. I might also ask them "What tech news have you read abou lately?" to see if they are actually reading about anything tech related in their spare time. A good conversation can often show who knows their stuff and who doesn't.

I might ask them "What question would you love me to ask for this interview?" and "What would be the answer?" Bonus points if they say "When can you start?" or some other quip that make me see them as more than a sheet of paper. Though, I would persist until they come up with a tech question as it really shows what level the are comfortable working at.

I would ask for coding sample or give them assignments to complete. Then I would remove comments from the code they submit, introduce a few bugs, and change the requirements ever so slightly to see if they can actually read code fix things. This, of course, would be done outside of an in person interview. Coding complex stuff on the spot is just cruel.

I might present them with some code from thedailywtf and ask them "What's wrong with this?" Bonus points if they recognize its origin.


Essentially, very few of my questions would actually be language specific. I would be trying to find people that enjoy coding and have a nack for it, not people that have been working with java for x amount of years.
 

veri745

Golden Member
Oct 11, 2007
1,163
4
81
2. A co-worker maintains an important library to which your code interfaces. It is full of bugs, and he is reluctant to fix them, or even acknowledge them. He is difficult to contact, and unreliable when asked for help. How do you deal with this?

LOL because this is currently what my full-time job actually deals with on a weekly basis.

Except it's not just one coworker, it's an entire sub-organization of the company...
 

johanelmander45

Junior Member
Mar 21, 2011
2
0
0
Hi

I read some opinions in this topic. I do not agree above ideal. We can find out some articles at about.com by using Google search.

If you want to get more materials that related to this topic, you can visit: Typical interview questions

Best regards.
 
Last edited:
Sep 29, 2004
18,656
68
91
I'd takea 10 year C++ guy that know prope OO over an OK Java person that is a hacker.

Just saying.

I think everyone should have a mastery of model-view-controller after 10 years. The thing is, if they don't it might be hte case of working under dumber people which we have all seen.

I'd think a really good developer would know that a red-black tree is how a TreeSet works.

The thing is, I could go after example after example. It really comes down to 3 things.
1) What the person has actually experienced in those 2-5 years.
2) What you need an employee to know
3) If the person in question has the skill set or infers confidence i nthe fact that he/she can quickly gain it.
 
Sep 29, 2004
18,656
68
91
With interviews, you want to start by limiting the chance you hire a total moron. Ask them how to do file I/O, or how exceptions are handled by a try/catch duet... something crazy simple-- maybe how to iterate over a fixed-length array. Ratchet the difficulty up until the programmer can't answer your question... the hire the one that impresses you most.

How excceptions are handled by try/catch? I have 10 years experience mostly in Java and I wouldn't even know what to say in response to that. That's like asking why 1+1=2. It would just make my head explode.
 
Sep 29, 2004
18,656
68
91
I'll help...

1) Why are checked exceptions stupid?

That's an awesome question. Because if the interviewee actually tries to say they are stupid, they arn't worth hiring. They should give some benefits.

Of course, everyone know that checked exceptions are there so the program can handle them and exit gracefully if needed.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
That's an awesome question. Because if the interviewee actually tries to say they are stupid, they arn't worth hiring. They should give some benefits.

Of course, everyone know that checked exceptions are there so the program can handle them and exit gracefully if needed.

Forced exception checking (which java does) is a bad thing. It forces every level of your code to check the exceptions of the layer beneath. Sometimes, you don't want to handle errors at that level, sometimes, errors at that level should stop the whole program etc.

What this effectively creates is blocks that look like this
Code:
try
{
codeblock();
}
catch (exception e)
{
   throw e;
}
throughout a lot of code.
 

BigDH01

Golden Member
Jul 8, 2005
1,631
88
91
Forced exception checking (which java does) is a bad thing. It forces every level of your code to check the exceptions of the layer beneath. Sometimes, you don't want to handle errors at that level, sometimes, errors at that level should stop the whole program etc.

What this effectively creates is blocks that look like this
Code:
try
{
codeblock();
}
catch (exception e)
{
   throw e;
}
throughout a lot of code.

It's not that bad, especially if your function uses a lot of classes that implement IDisposable (in C# at least). I prefer the readability of..

Code:
try
{
//statements
}catch
{
throw;
}finally
{
//objects.dispose();
}

to

Code:
using (new object)
{
  using (new object)
  {
    using (new object)
    {
       //do stuff
    }
  }
}

In my opinion, the best part of try/catch is finally.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Having not done much in Java, I'm curious. With this checked exception thing, does that mean if you update code, and need to throw a new type of exception, does that mean you need to update the existing code in every level of calling between the added exception and the level at which you actually want to handle it?

IE, I've got code A, code A calls B calls C calls D calls E. E gets a new exception, which is properly handled in A. Instead of just updating A and E, I have to update B, C, and D?
 
Status
Not open for further replies.