March 28, 2005

Java Interview Questions for Java Programmers

This is the short version of the java interview questions I use each time I interview a potential java developer. In person, I'll always add 'Diagram the complete lifecycle of how a request becomes a response in the enterprise architecture of your choosing', but that one is tough over the phone!

Interview Questions

General (tell them you want 10 sec. answers)

  1. What is inheritance?

Re-using the implementation of one class to make a new class. Also might mention subclassing, ‘is-a relationships’, parent/child relationships.

  1. What is polymorphism?

Allowing the same code to be used with different types, resulting in more general and abstract implementations.

  1. What is encapsulation?

Information hiding of design details. Protecting data and private methods, and only exposing the attributes or operations that are necessary.

Java (tell them you want 10 sec. answers)

  1. What kinds of literals/primitives does java provide? (Or, what in java is NOT an object)

boolean, char, byte, short, int, long, float, double

  1. What does the ‘static’ keyword do?

Makes an attribute or method a ‘class’ attribute or method. There exists exactly one incarnation of the field, no matter how many instances (possibly zero) of the class may eventually be created

  1. Describe the different java protection levels.

Private – The member is accessible only within the class that defines it.

Default (aka package) – The member is accessible only within the package in which it is defined.

Protected – The member is accessible only within the package in which it is defined and within subclasses.

Public – The member is accessible anywhere its class is.

  1. What are the differences between checked and unchecked exceptions?

Only checked exceptions need to be explicitly ‘caught’. Unchecked exceptions are subclasses of Error, while checked exceptions are subclasses of Exception.

  1. What are the differences between abstract classes and interfaces?

Anything except visible forehead sweat. Single vs. Multiple inheritance; interfaces are entirely abstract; abstract classes provide partial implementation; etc.

  1. How do you sort a collection?

Call the java.util.Collections.sort() method, passing in the collection you need sorted, and optionally, a comparator

Database (tell them you want 30 sec. answers)

  1. Describe database normalization, including when it’s appropriate.

Database normalization is the process of removing redundant data to improve integrity, scalability, and storage efficiency. Normalization tends to trade off with performance, so it's a question of balancing data redundancy and integrity against performance. Normalize less if you want simple queries, archival quality records, online reporting, or good performance.

Bonus points for definitions of different normal forms:

1NF: tables have no internally redundant columns, and are rows are uniquely identifiable by a unique column or columns

2NF: every non-key column is dependent on the primary key

3NF/BCNF: every non-key column is only dependent on the primary key, and no other columns

4NF: No multi-value dependencies

  1. When would you create an index?

To speed up queries on a non-key column. If a table is large enough that a sequential scan takes too long to filter by some column(s), create an index.

  1. When would you create a view?

To simplify queries. Maybe also to present a part of a table with different names or permissions.

  1. Describe inner, outer and full joins.

An inner join returns only records which satisfy the join condition.

An outer join returns all records from one table, and matching records from the other where the join condition is satisfied.

A full outer join returns all records from both tables, matching where the join condition is satisfied.

Bonus points for mentioning the difference between left/right, or cross joins/cartesian products.

Front End (tell them you want 30 sec. answers)

  1. Describe techniques for updating a page without the browser flashing or redrawing the whole thing.

Use javascript or vbscript to modify the DOM directly. (Bonus for mentioning loading the data in a background iframe)

  1. What is the difference between a Java Server Page and a Servlet?

A JSP is translated into a servlet by a precompiler that converts non-java text into write or print statements. Other than that THEY ARE THE SAME THING.

  1. How do you get data from a FORM in the browser to a servlet?

A browser action (click or Enter) SUBMITs an html form. The servlet accesses the data by calling getParameter on the Request object.

J2EE (tell them you want 30 sec. answers)

  1. Contrast Stateless vs. Statefull Session Beans.

A stateless session bean does not maintain a conversational state with the client it is servicing. A stateful session bean is dedicated to the one client it is servicing for the life of the bean instance, so data about the client can be cached between method invocations.

  1. Contrast CMP vs. BMP.

Container Managed Persistence means all persistence is handled by the EJB container. A developer doesn’t have to worry about writing persistence code that is specific to the database because it is automatically generated by the EJB container. In Bean Managed Persistence developers write all of the code to manage persistence.

  1. What is a Home Interface, Local Interface, and a Remote Interface.

Home Interface –Home interfaces are used to create, locate, and remove objects from EJB containers (and sometimes databases).

Local Interface – Used when calling the business methods by clients that reside in the same JVM. Parameters are passed by reference.

Remote Interface – Used when calling the business methods by clients that reside in another JVM. Parameters are passed by value.

Subjective

  1. How do you get started coding when you don’t have good documentation for your task?

Just looking for some answer that says they’ll get along here. Anything except “I won’t start coding until the BAs give me good UML diagrams”

  1. You are given requirements to create a new screen that allows the user to input customer contact information. What are the steps you would take to implement it? What would you consider when designing and implementing the code?

The key is asking for more information. Anything except “just start coding”.

  1. Talk about design diagrams and what you find useful.

Looking for anything that sounds compatible with the status quo here. Nice to have, good tool for developers to use to communicate, etc.

  1. When you need to learn something new, where do you go for information?

Google. Books. Anything that demonstrates that they can learn new things.

  1. How do you feel about working on projects in an Agile environment vs. a linear methodology?

Must like agile.

  1. How do you feel about pair programming?

Must be ok with pairing and think it at least ‘has its place.’

Grand Total:

And the scoresheet I use for each candidate:

Interview Questions

Name_________________________________

General (tell them you want 10 sec. answers)

bad great

  1. What is inheritance?

0 1 2 3 4 5

  1. What is polymorphism?

0 1 2 3 4 5

  1. What is encapsulation?

0 1 2 3 4 5

total

Java (tell them you want 10 sec. answers)

0 1 2 3 4 5

  1. What kinds of literals/primitives does java provide? (Or, what in java is NOT an object)

0 1 2 3 4 5

  1. What does the ‘static’ keyword do?

0 1 2 3 4 5

  1. Describe the different java protection levels.

0 1 2 3 4 5

  1. What are the differences between checked and unchecked exceptions?

0 1 2 3 4 5

  1. What are the differences between abstract classes and interfaces?

0 1 2 3 4 5

  1. How do you sort a collection?

0 1 2 3 4 5

total

Database (tell them you want 30 sec. answers)

  1. Describe database normalization, including when it’s appropriate.

0 1 2 3 4 5

  1. When would you create an index?

0 1 2 3 4 5

  1. When would you create a view?

0 1 2 3 4 5

  1. Describe inner, outer and full joins.

0 1 2 3 4 5

total

Front End (tell them you want 30 sec. answers)

  1. Describe techniques for updating a page without the browser flashing or redrawing the whole thing.

0 1 2 3 4 5

  1. What is the difference between a Java Server Page and a Servlet?

0 1 2 3 4 5

  1. How do you get data from a FORM in the browser to a servlet?

0 1 2 3 4 5

total

J2EE (tell them you want 30 sec. answers)

  1. Contrast Stateless vs. Statefull Session Beans.

0 1 2 3 4 5

  1. Contrast CMP vs. BMP.

0 1 2 3 4 5

  1. What is a Home Interface, Local Interface, and a Remote Interface.

0 1 2 3 4 5

total

Subjective

  1. How do you get started coding when you don’t have good documentation for your task?

0 1 2 3 4 5

  1. You are given requirements to create a new screen that allows the user to input customer contact information. What are the steps you would take to implement it? What would you consider when designing and implementing the code?

0 1 2 3 4 5

  1. Talk about design diagrams and what you find useful.

0 1 2 3 4 5

  1. When you need to learn something new, where do you go for information?

0 1 2 3 4 5

  1. How do you feel about working on projects in an Agile environment vs. a linear methodology?

0 1 2 3 4 5

  1. How do you feel about pair programming?

0 1 2 3 4 5

total

Grand Total:

No comments: