views:

1712

answers:

8

When interviewing college coops/interns or recent graduates it helps to have a Java programming question that they can do on a white board in 15 minutes. Does anyone have examples of good questions like this? A C++ question I was once asked in an interview was to write a string to integer function which is along the lines of the level of question I am looking for examples of.

+4  A: 
  1. Write a function to swap variable values using pointers (Really poor ones will fall for this)
  2. Write a program to find the distance between two points in the XY plane. Make use of a class to store the points.
  3. Demonstrate the use of polymorphism in java using as simple program.
  4. Write a program to print the first n prime numbers.
  5. Write a program to replace a string in a file with another.
Niyaz
1 is a bit hard as Java doesn't have pointers (or is it a trick question?)
Thorbjørn Ravn Andersen
+8  A: 

Is there any reason why it has to be on a whiteboard? Personally, I'd rather sit them in front of a keyboard and have them write some code. Our test used to be a simple 100 (IIRC) line Swing text editor. We then broke it a few simple ways, some making the code not compile and some a little more subtle, and gave the candidates half and hour and a list of problems to fix.

Even if you can't have them do anything hands on make sure that you do give them some explicitly technical questions. In another round of interviews there were a surprising number of recent graduates who were just buzzword-spouting IDE-jockeys, so they could look OKish waving their hands around in front of a whiteboard talking about Enterprise-this and SOA-that, but when given a simple Java fundamentals multiple choice exam asking things about what final and protected meant did horrifyingly badly.

Dave Webb
Although that text editor test isn't 15 minutes, it sounds like an excellent test. It's more like what you would do in real life compared to writing algorithms: maintain code that someone else might have made.
palto
+6  A: 

Some stuff that has showed up on SO:

  • IsPalindrome(string s)
  • ReverseWordsInString(string s): "I know java" --> "java know I"

Other stuff that springs to mind:

  • multiply a Vector with a Matrix (can this be done OO-Style?)
  • echo (yes, a simple clone of the unix tool)
  • cat (15 min should be enough, should weed out the clueless)
  • a simple container for ints. Like ArrayList. Bonus question: Generic?
Daren Thomas
+6  A: 

I've always thought that algorithmic questions should be language agnostic. If you want to test the java level of a student, focus on the language: its keywords (from common one like static to more exotic one, like volatile), generics, overloading, boxing/unboxing of variable, standard libraries.

Nicolas
A: 

I agree with Nicolas in regards to separating the algorithmic questions from the actual language questions.

One thing that you might want to consider is giving them a couple simple algorithm questions that they can write up the pseudo code for on the white board (ex. "Explain to me the Bubble sort and show me the pseudo code for it."

Then once they have demonstrated their algorithmic knowledge you can move on to the Java questions. Since some people work better in front of a computer than in front of the whiteboard, I would give them something simple, but leveraging their knowledge of Java, that they can implement in 30 minutes or so in using the same IDE that you are using at the company. This way if they claim to know the IDE you can also get an idea of how well they know it.

Rob
A: 
  1. Write a function that merges two sorted lists -- stopping at limit. Look for the easy optimizations and correct boundary checks / sublist calls. Tell them T implements compareTo.

    public List<T> merge(List<T> one, List<T> two, int limit)

  2. Write a function that returns true if any two integers in the array sum to the given sum. Have them try to do better than n squared using some sort of set or data structure.

    public boolean containsSum(int[] nums, int sum)

wsorenson
A: 

I would avoid asking them questions that would have been covered in their undergrad classes. I would be more curious about their ability to apply everything they've learned to solve complex technical problems. If your business has a specific need for an IT solution you could use that as a starting point. You could ask the candidate what technologies they would use and the pros and cons of using those technologies versus alternate technologies. As the discussion progresses you could get a feel for their technical skills, problem solving skills, interpersonal skills, etc. I think it is important to avoid coaching them, even in awkward moments. This is important to weed out the BSers.

rich
But you really would want to weed out the guys who forgot all the basics they learned in their undergrad classes! Don't assume just anyone can write FizzBuzz.
Jimmy
A: 

If you don't know what questions to ask them, then may be you are not the right one to interview them in Java. With all due respect, I hate when people ask me questions in interviews which they themselves don't know answers for. Answers for most of the questions can be found online by googling in a few secs. If someone has experience in Java, they will definitely know Abstract class, interface etc as they are the core building blocks. If he/she does not know 'volatile' keyword - big deal.

I guess I agree with your general point, but it sounds like the asker is qualified to answer the question as well. And sure enough, I had to go look up WTF volatile did in Java and I work in J2EE as my day job.
MattGWagner