JAVA Programmers: Good questions to ask in an interview

I have to interview a potential Java candidate. I have general programming questions and general interview questions, but have not enough experience in Java to craft good Java questsions. Now, others on the panel will be skilled enough to do so, but I would like to ask a few questions myself.

What would you ask if you were doing the interviewing?

Unless you’re looking for a Java guru, I would avoid asking too many language-specific questions. Any idiot can look that stuff up in a book. I would be more concerned about their knowledge of software engineering: specification, testing, error handling, etc.

Honestly, if you don’t feel you know Java enough to ask these questions, it would be best to leave this area to others. If this guys knows his shit better than you, he’ll figure it real quick and take notes quietly – he’s not going to correct you during an job interview.

So you guys don’t know either? :stuck_out_tongue:

I appreciate the general advice. Let’s pretend that I have already thought that through and decided to post here anyway.

I don’t know shit about Java. I’ve interviewed for C++ positions before, though.

A guy asked me once in an interview, “what is an object?”

I know a guy who was asked once, “what’s the difference between a null pointer and a void pointer?” for a C job.

It’s not about the answers to those things specifically, but just to hear how comfortable the guy is with the concepts. You’d never really need to know the difference between a null pointer and a void pointer in practice.

Exactly. I know C++ and C# well enough that Java will be familiar and I want to see - as you said - how comfortable the guy is with the concepts.

  1. Why can an inner class not be static? Answer: because all inner classes contain an implicit reference to an instance of their enclosing class, which is meaningless in a static context.

More as I think of them.

The thing I’d ask about because so many of the “Java developers” (using the term loosely) I work with don’t get it: unit testing.

You wouldn’t? The difference between a null pointer and a void pointer while executing is a nice fat segfault.

Uh, what? Inner classes most certainly can be static. In fact, you can only use the static keyword on an inner class.

Aw crap, you’re right. What the hell was I thinking about?

If even people who know the language can screw up like that, what makes you think that you should be asking questions in an interview about a language that you don’t know?

Some questions on Java memory management:

“Explain the difference between managed code and unmanaged code.”

“Your Java application is not performing predictably. It’s stuttering and pausing, sometimes for a relatively long time. What might be the problem?”

A: the garbage collector might be working really hard.

Follow up: “What might you do to improve garbage collection performance?”

“Tell me why you might not want to use string concatenation inside loops in your Java Application.”

A: String concatenation creates copies of the string objects being concatenated, which must be garbage collected. This increases overhead. The alternative is to create a stringbuffer and append to it inside the loop, then when you are finished convert it back to a string.

Forgive me for being confusing. Pretend that I’ve asked for help on creating questions on Java and not advise on whether or not I should be asking them. Please: If you don’t wish to contribute a question, you need not - but I am not interested in hearing (again) that you don’t think I should ask Java questions.

You can’t have static instances of non-static inner classes, for the reason you have given.

Ask him what color the JVM is.

My point was: it’s hard to imagine a context where a programmer is trying to use a void pointer, and by “mistake” he uses a NULL pointer. The concepts might be tricky, but in practice, it’s not something you really need to guard against when writing code.

First of all, compared to most bugs one hunts, I’ll take a segfault any day.

It’s not like not knowing the difference between passing by value and passing by reference – pretty easy concepts and less fatal but

  1. easier to screw up when coding, AND

  2. harder to find when testing.

Ah, ok. I agree that it’s not something that you’re likely to mess up, nor would it likely be a hard bug to track down.

My interview question was to have someone create a recursive function. I’d tell them that they have the following API functions:

int get_subfolder_count(); // will return the number of subfolders in the current working directory
void enter_subfolder(int index); // will change the working directory to one of the subfolders of the current directory
void leave_folder(); // will change the working directory to the parent folder
bool contains_file(); // true if the search file is in the current working directory

And then they had to implement the following function:

bool file_exists(); // will scan all folders from the current workind directory and below to see if a file exists

You’d be amazed at how many professional programmers can’t do it. I always cared more whether someone could program than how well they knew a particular language.

Indeed, a null pointer isn’t a type, it’s a value. Mixing up types is something someone might do, but not handling a NULL case properly has no relation to what type of pointer you are using. The only relation between a “void pointer” and a “null pointer” is that they both have “pointer” in the name.