I was the first person hired for my Java skills at the company I work for. Consequently, during the hiring process, the people I talked to relied upon my previous experience in the financial markets as a C++ programmer, and asked questions related to that field only. It worked for them (I am still here), but it was nevertheless a hit-or-miss situation. It comes as no surprise, since Java is a still young language, that good Java programmers are hard to find and come at a premium (commanding salaries larger than those C++ programmers receive). The September 1996 issue of Dr. Dobb's Journal included a column by Al Stevens entitled "Wanted: Senior C++ Programmer." While Al made some good points about interviewing practices in general, the details of his column didn't help me, since I was looking for Java programmers. Still, Al's article provided a framework for zeroing in on the specifics of what "good" Java programmers should be comfortable with. This article shares the guidelines I've implemented. Hopefully, it will help both managers who want to hire good Java developers, but don't know what questions to ask; and developers looking for a dream job who aren't sure what to expect from interviews.
I have developed a set of questions for separating Java programmers into different knowledge levels. These guidelines are by no means set in stone. If you have any criticisms or comments about my plan, I'd love to hear from you.
The questions fall into four categories:
I start by asking general questions about the person, based on the résumé, but I don't spend too much time on specifics. I do generally ask how a candidate liked his previous environment.
The general discussion will gradually lead to questions from the first category, which provide a means of moving on to more technical aspects of the interviewee's knowledge and abilities.
Category One: Basic Java Understanding
Q: Apart from a Java background, do you know any C++ or have you been exposed to an object-oriented programming paradigm before?
A: Yes.
Senior Java developers should have a solid background in object-oriented languages. C++ is the most common language in use today. If the person has a C++ background, I can move on to the second question:
Q: Do you have an understanding of some of the differences and similarities between C++ and Java?
A: Yes or No.
If the answer is "no," then right away we can start discussing some of the differences/similarities, providing points that give you a better understanding of the person's object-oriented background. I talk about some C++ points and try to get the person to tell me why they are similar (or different) to Java. For example, the easiest point is that C++ has a stand-alone main function. When I mention this, I expect the person to respond, "Oh, but in Java, main is part of a class." If they don't, I have an indication to a possibly significant problem. If they do, I can then ask what the signature of main is, in Java. (It's public static void main (String[] args).)
If they have responded "yes," I ease them into describing some of the differences. Avoid a confrontational "list at least three examples." Applicants should have no problem coming up with similarities such as: Both are object-oriented languages, where classes and objects are the main tools for development; both have similar construction mechanisms (constructor for classes). Differences might include: Java does not make use of pointers anywhere, whereas C++ relies heavily on them; Java has garbage collection, C++ does not; there is no delete() method in Java (because of garbage collection and the absence of pointers); Java runs on a Virtual Machine; Java supports multithreading.
Q: Do you recognize the distinctions between a Java application and Java applet?
A: Yes.
There are three important points here:
Q: How big is an int in Java?
A: An int is four bytes. Ranges are from -231 to 231-1. (Or from -2147483648 to 2147483647, but I digress...)
Knowing the size of an int means applicants have come across conversions from other types to int, or vice versa. A little depth is starting to show. Not knowing this is not necessarily terrible either, but it is useful information, since it allows programmers to be less wasteful when selecting the size of types they will use.
Q: Can you give me an example of a default constructor in a simple class that extends the Vector class?
A: Anything that will have at least the following:
Class Vector1 extends Vector{
...
public Vector1()
{
// implied call to super()
}
}
This shows that the candidate knows about constructors in Java. They won't necessarily include the call to super(), since that call is implied, but you can ask them about it by saying something like "what is the sequence of code execution when the constructor is called?". They should respond by at least mentioning something about the super() implicit call.
Q: What is the use of the Java "interface" facility and could you give an example?
A: From the language specification:
An interface declaration introduces a new reference type whose members are constants and abstract methods. This type has no implementation, but otherwise unrelated classes can implement it by providing implementations for its abstract methods.
Java programs can use interfaces to make it unnecessary for related classes to share a common abstract superclass or to add methods to Object. In other words, an interface allows for abstracting methods and constants that would otherwise lead to unnecessary code repetition. It also provides a paradigm for replacing multiple inheritance (which is not implemented in Java).
The other hidden facility of an interface is that a variable whose declared type is an interface type may have as its value a reference to any object that is an instance of a class declared to implement the specified interface. That allows any class to become of the desired type, by implementing the methods declared in the interface. Applicants should be able to show a simple example that possibly uses an interface to allow callback mechanisms to come into play without knowing the class type at compile time.
Category Two: Intermediate Java Knowledge
Candidates should be warming up by now, and these questions will become tougher as the interview progresses.
Q: Do you know what a race condition is? How do you guard against it?
A: "I don't know," or "A race condition occurs when two threads are trying to modify the same data at the same time in such a way that the modification interferes with the logic of the thread. You guard against that by synchronizing the method that changes the data by using the 'synchronized' qualifier."
An "I don't know" answer is acceptable for the first part of the question only. Applicants may not have heard of the phrase, but they should be able to answer the second part after the race condition is described to them. Synchronization is a vital part of Java, since the language is inherently multithreaded. Any application that you'll develop, apart from simple ones, requires a good bit of multithreading.
Q: What is an exception, and how do you implement exception handling in Java?
A: An exception is a potential error condition that a method cannot anticipate and does not know how to handle, but instead needs to be passed to the caller of the function, who potentially knows what it means. Java implements exceptions by defining the Exception class and the Throwable class (and allowing them to be extended). The way to handle exceptions is to enclose methods that throw them into a try-catch block.
Q: How can one write a thread in Java? How does a thread start? How does it end?
A: There are two ways to use threads in Java. One way is to create a subclass of the Thread class, which belongs to the java.lang package. The other is to use the Java Runnable interface. The Thread class defines methods called start(), run(), and stop(), which need to be overridden to provide the desired functionality for the extended class. The Runnable interface is used when your class is already extending another class that is not part of the Thread hierarchy, so you wouldn't be able to extend it. It declares a run() method that you need to define to complete the class.
Q: How do you handle a "mouse clicked" event in JDK 1.02? How would you handle it in JDK 1.1?
A: In JDK 1.02, you'd need to override the handleEvent(Event evt) method; see Example 1(a). In JDK 1.1 (and later versions), assuming there was a button that users pressed by clicking on it with the mouse, the code would look like Example 1(b).
Don't forget to add the implements ActionListener part at the class declaration.
Category Three: Extended Java Knowledge
I usually take a short break before jumping into the third category. I've found that after the second category, having spent 30-45 minutes with the interviewee, I have an idea of what she will or will not be able to answer. This break serves as a way to see how candidates perform when they're a little more relaxed.
Q: Have you worked with RMI (Remote Method Invocation) before? How much do you know about it?
A: (Most often) No. But I do know that it is an API to allow a Java program running on one platform to invoke the methods of a Java program running on a different platform. It is used for distributed applications, either on a two-tier or a three-tier client-server paradigm.
RMI is so new that many applicants will not yet have worked with it. Of all the Java developers I know, most have read a bit about it, but never had a chance to use it. One friend of mine had the luxury of being taught at Harvard by Jim Waldo, and he did a project using RMI. This is unlikely of most candidates, so don't expect too much.
If, however, applicants start talking about it, I encourage them. It will show me how much they know about distributed computing, client-server methodologies, and the like. Even if a project's requirements today do not involve distributed computing, it is likely that they will in the near future (or they should, anyway).
(a)
public handleEvent(Event evt)
{
if ( evt.id == Event.MOUSE_DOWN ) {
System.out.println("Mouse was clicked");
}
}
(b)
Button b = new Button("Press Me");
b.addActionListener(this);
...
Public viod actionPerformed(ActionEvent evt)
{
if ((Button) evt.getSource() == b)
System.out.plrintln("Button was pressed")
}
|
| Example 1: (a) Handling mouse clicks using JDK 1.02; (b) handling mouse clicks using JDK 1.1. |
A: CORBA, RPC, (or DCOM, if they come from a Microsoft background).
CORBA is another big topic. If applicants start a conversation on CORBA, I ask a couple of questions about it. Such questions will help hash out whether or not they know about it, or have simply heard about it and are parroting the information. This will be very obvious when I ask:
Q: What is the main difference between CORBA and RMI?
A: Either "CORBA needs an ORB (Object Request Broker), whereas RMI doesn't," or "RMI runs only between Java programs, whereas CORBA can be run between Java, C++, or any other language implementation of an ORB."
Q: What is a JAR file?
A: It is a "Java ARchive File." It helps in speeding up the downloading of class files associated with applets. Applets frequently contain many class files, image files, and the like. With JAR files (a feature only available in the latest versions of the JDK 1.1 and above), you can package individual small files into one JAR file. This allows applets to only open one HTTP connection for the file, instead of the many HTTP connections required before, and it also provides a standard, convenient way to package JavaBeans.
Q: What is JDBC? Where is it used?
A: JDBC is the Java Database Connectivity API. It is the adaptation of Microsoft's ODBC Standard for Java. JDBC allows connectivity between Java programs and relational databases such as Microsoft SQL Server, Sybase SQL Server, Oracle, Informix, and the like. In fact, the claim is that any database that conforms to the ODBC Standard should be accessible to Java via JDBC, when the vendor implements the API for their server.
Q: Can you describe an example of a database access function using JDBC?
A: (Any sane person) No. I can instead look it up and do it for you from the book.
I would not expect most Java programmers to be able to recite how to perform a connect to a database server, retrieve data, and close the connection, off the top of their head. However, they should be familiar with what a SQL connection is, with SQL statements, with "commit transaction" and "rollback transaction," and so on. They should be able to go into some detail on SQL (if they have done that type of work before), but I don't hold it against them if they've never touched a database in their lives. They'll learn easily.
Q: What is an "inner class"? Where would you use one?
A: An inner class enables classes to be defined in any scope. Previously, Java supported only top-level classes, which had to be members of packages. Now the programmer can define inner classes as members within other classes-locally within a block of statements, or anonymously within an expression (see Inside Java, by Karanjit S. Siyan and James L. Weaver, New Riders, 1997).
The use of inner classes allows programmers to connect objects together, by directly using the methods and variables they need.
Category Four: "I like Klingon Opera and Wear Pointy Ears"
If I've gotten this far, I'm pretty much assured that the person in front of me knows his stuff. Now, if I want to see whether I can stump the interviewee, I'll ask:
Q: How much do you know about bytecodes? Have you ever debugged an application for which you had no source code and had to rely on bytecode?
A: If the answer is even remotely close to an affirmative, I know the person is enthusiastic about Java and will be a good fit, technically.
Q: When does garbage collection occur? What is the priority for the garbage collection thread?
A: The Java run-time environment has a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java's dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (that is, not referenced) are known to be garbage and are collected. (A more complete description of Java's garbage-collection algorithm might be "a compacting, mark-sweep collector with some conservative scanning.") The garbage collector runs in a low priority thread and runs both synchronously and asynchronously depending on the situation and the system on which Java is running. The garbage collector runs synchronously when the system runs out of memory or in response to a request from a Java program. Your Java program can ask the garbage collector to run at any time by calling System.gc().
On systems that allow the Java run time to note when a thread has begun and to interrupt another thread (such as Windows 95/NT), the Java garbage collector runs asynchronously when the system is idle. As soon as another thread becomes active, the garbage collector is asked to get to a consistent state and then terminate.
The priority of the garbage collection thread is set to NORM_PRIORITY-1 in the current version of the JDK.
Q: Can you name a couple of differences between various Java platform implementations?
A: There are none. Or, at least, there should not be any.
This is a bit of a tricky question, what I was really looking for is any knowledge of JDK bugs that are manifested only on some of the implementations. Such bugs include (from the Javasoft web site):
The interview is almost over by now, the applicant is probably mentally exhausted. They have certainly learned a lot. Hopefully, I've given them pointers to read about the parts they didn't know. As the interviewer, I'm evaluating how I feel about their personality and ability to work under pressure. Their Java skills might be lacking, but that's not as important as their ability to learn and assimilate what they will be taught. Remember that a good senior Java programmer is hard to find. I may ask them to come back to talk again. That should be a chance for them to impress me by showing me they've read up on the questions they couldn't answer before. I expect that from applicants, since it shows eagerness to work.
Now comes the hard part of my job: Convincing the management that they have to pay the premium for the Java programmer when they're used to the salaries they pay for senior C++ programmers.
DDJ