Technical Interview Questions and Answers ----------------------------------------- - Key - II = SEII III = SEIII The following are subjective, depending on the skill set you are looking for: XC = Extra Credit REQD = Required Phone Interview ------------------------------------------------- ------- Basic Java -------- * (II XC, III REQD) Is Java a pure OO language? Why or why not? Nope. The natives are not objects - double, int, boolean, etc. * (II XC, III REQD) What's the difference between overloading and overriding? Overload = 2 methods with same name, different signature. Override = 2 methods with same name, same signature, inheritance reln. Method in subclass takes precedence over super's version. * (II REQD, III REQD) What's the difference between == and "equals"? == compares references. equals compares symantically if you override. * (II REQD, III REQD) If you override equals, what else might you override? hashcode * (II REQD, III REQD) How does a Javadoc comment look? Give me an example of a javadoc tag. /** javadoc here * @param parameter tag */ * (II REQD, III REQD) How is the problem of multiple implementation inheritance solved in Java? Not allowed. Instead, interfaces. * (II XC, III REQD) What Java keyword is used to protect a method against concurrent access? synchronized * (II REQD, III REQD) When would you use an ArrayList vs a LinkedList? Fixed size. Linked list for lots of add/remove inside list. * (II REQD, III REQD) When is it typically appropriate to use anonymous class? Listener implementations. * (II REQD, III REQD) If I want to write an object to an ObjectOutputStream, what interface does that object's class have to "implement"? Serializable * (II REQD, III REQD) How do I represent the number 12 as an object? How do I then change that object's value to represent the number 14? new Integer( 12 ); Cannot change wrapper class's values - immutable. * (II REQD, III REQD) How do I modify a String? You dont since immutable. Use StringBuffer. ------- Swing/AWT -------- * (II REQD, III REQD) With the Swing class JFrame, one should not "add" components to the JFrame directly. Instead, add the components to the JFrame's what? Content Pane (getContentPane()). * (II XC, III REQD) Lots of Swing is based on knowledge of what design pattern? MVC. Observer. Composite. * (II REQD, III REQD) What controls the size and position of Components within a Container? LayoutManager * (II REQD, III REQD) Name some of the Layout Managers. Can you explain the difference between some of them? Grid, Card, Flow, Border, Box, GridBag. * (II XC, III REQD) To react to mouse events, what two interfaces might your class implement? MouseListener, MouseMotionListener. * (II XC, III REQD) What's the difference between the AWT and Swing? Swing = lightweight and Java does the drawing. AWT = heavyweight and native components do the drawing. * (II REQD, III REQD) What's an Adapter class and when would you use one? eg: MouseAdapter, extends it when you want to override one or two of the methods, but dont have an existing implementation superclass. * (II XC, III REQD) If you write Swing applications, you will typically import classes and interfaces from what two or more packages? java.awt.* java.awt.event.* javax.swing.* ------- UML -------- * (II REQD for 1 examples, III REQD for 3 examples) What are some of the UML diagrams? UseCase, Class, Object, Deployment, Component, State, Activity, Sequence, Collab. * (II XC, III XC) With respect to OO Analysis and Design, what is meant by "use case driven, architecture centric"? Come up with Use Case (descriptions and scenarios) and use them to help distribute responsibilities to candidate classes. This ultimately results in classes that support the use cases. ------- J2EE -------- * (III REQD) Explain the separation of concerns wrt Servlets, EJBs and JSPs. Or describe the Model 2 Architecture. Servlet = controller. Web component person. EJB = model. Domain expert. JSP = view. Markup expert. * (III REQD) With respect to Model 2 architecture, what should you NOT put in your servlet code? What should you NOT put in your JSP code? Servlets should not have HTML. JSPs should not have java. * (III REQD) Servlets can share resources by accessing the what? ServletContext * (III REQD) How does one maintain state across a specific client's http requests? HttpSession. * (III REQD) Are there any concurrency issues with Servlets/JSPs? Explain. Each request on different thread accessing service() method on same servlet instance. * (III REQD) Should one put SQL in a JSP, or a Servlet? If not, where should the SQL go? Is there a J2EE design pattern for this? Use a persistance layer. DAO - DataAccessObject. * (III REQD) In general, what does an AppServer do with a ".jsp" file the *first* time someone hits that page? Converts to .java, compiles it. loads the class, instantiates, invokes jspInit and on new thread invokes jspService. * (III XC) In order to completely eliminate scriptlets from your JSPs, what might you use? Custom tag library * (III XC) There are two ways to "include" jsp fragments into another JSP. What are the two ways and when would you use each? <%@ include > directive is done at translation time, for cases when the fragment doesnt change frequently and you care about perfromance. standard action for cases when the fragment changes frequently, and we dont much care about performance. * (III XC) Do you know what the "petstore" application is? Sun's complete J2EE example. * (III XC) Have you used any servlet frameworks? If so, which? Struts Live Interview ------------------------------------------------------------ -------- General --------- * How large of a project (lines of code) have you worked on? What was your role? What language(s)? * Tell me about a time when you had to spend significant time working with someone else's code. * Tell me about the software development process used in past roles. What worked or was useful, and what didnt or was frustrating? * What practices have you adopted to encourage code reuse? What tools might help with this? * How would you approach debugging a ton of code that you did not write? * What tools do you use on a regular basis? IDE? Debugger? CVS? Browser/Javadoc? UML? Website, eg: JDJ? * Do you have graphics programming experience? * What platform are you most comfortable with? Are you adept at others? * Is Java great for text processing and mangling? What might be better? Is Java great for CPU intensive calculations and optimization? What might be better? Is Java great for intensive Matrix math operations? What might be better? * Have you ever done any XP? What are some of the requirements/features of XP? Test first. Pair programming. On site client. Simple. 40 hours. Code stds. Collab codebase. Integration always. * What journal publications do you read? What computer sciency websites to you visit? ------- Basic Java -------- * (II XC, III REQD) Say I have the following: String s1 = "Hello"; String s2 = "Hello"; Does ( s1 == s2 )? yes Does ( s1.equals( s2 ) )? yes Now assume we have the following: String s1 = new String( "Hello" ); String s2 = new String( "Hello" ); Does ( s1 == s2 )? no Does ( s1.equals( s2 ) )? yes * (II XC, III REQD) If I have the classes: public class Emp { private String name = ""; public Emp() { } public Emp( String name ) { this.name = name; } } public class Mgr extends Emp { } Which of the following lines will compile? Emp e = new Emp(); Emp e = new Emp( "roberto" ); Mgr m = new Mgr(); Mgr m = new Mgr( "jerry" ); Mgr m = new Mgr( "jerry" ); will not compile. If the Mgr class looked like the following instead, then which of the above lines would compile? public class Mgr extends Emp { public Mgr( String name ) { } } Mgr m = new Mgr(); will not compile * (II XC, III REQD) Given the following: // Emp.java public class Emp { private String name = ""; public Emp( String name ) { this.name = name; } } // Mgr.java public class Mgr extends Emp { public Mgr() { super( "" ); // REQUIRES THIS FIX TO COMPILE } } Will it compile? Fix it if necessary. * (II XC, III REQD) What's the output of the "main" method? // Emp.java public class Emp { protected String name = ""; public void work() { System.out.println( "The employee " + name + " did some work." ); } } // Mgr.java public class Mgr extends Emp { public void work() { System.out.println( "The manager " + name + " did some work." ); } } // Test.java ... public static void doTest( Emp e ) { e.work(); } public static void main( String args[] ) { Emp e = new Mgr(); doTest( e ); } "The manager did some work." * (II REQD, III REQD; Anonymous = XC) Show me the syntax for an inner class. public class Person { public class Soul { } } * (II REQD, III REQD) Show me the code for the equals method in the Employee class. public class Employee { private String name = ""; public boolean equals( Object o ) { if( o == null || ! ( o instanceof Employee ) ) return false; Employee otherE = (Employee) o; if( otherE.name != null && otherE.name.equals( name ) ) return true; return false; } } * (II REQD, III REQD) If I have: ArrayList theList = new ArrayList(); What would be better for the LHS declaration of theList variable? List theList = new ArrayList() so can change RHS without affect theList references. * (II XC, III REQD) How does one get a Resource out of a jar file (any jar file that you are deploying with) ? URL url = MyClass.class.getClassLoader().getResource( "edu/ucar/rap/jade/model/resource.jpg" ); * (II XC, III REQD) If you wanted to sort a Collection of objects, what methods might you call, and what are the different classes/interfaces you'd probably implement? In the java.util.Collections class: static void sort( List list ) {} static void sort( List list, Comparator comparator ) {} To use the first one, implement java.lang.Comparable: public int compareTo( Object o ) which returns a negative number if this is less than o. To use the second one, write a Comparator with this method: public int compare( Object o1, Object o2 ) * (II REQD, III REQD) What's the difference between static methods vs a Singleton? static methods cannot be overridden. On the other hand, subclasses of Singletons are possible, and thereby allow overridden methods. * (II XC, III REQD) Why should one not invoke wait() outside of a loop? When an object is "notified", others may have been notified simultaneously, and in order for an object to move on, it must acquire the target's lock. However, if someone beats you to the lock, then the condition that you were waiting for may not be true anymore. Hence, when notified, check the condition again to make sure no one beat you to it. * What is the advantage to using interfaces over classes? No required implementation. ------ Swing/AWT -------- ------ J2EE ------ * (III XC) What kinds of EJBs exist? Entity, Session, Message Driven * (III XC) Select a few components from a J2EE application you've worked on, and describe their responsibilities. * (III XC) Where does one define initialization parameters for a servlet? What is the XML tag? web.xml, and the tag = ------ UML ------ * (II REQD, III REQD) How do you communicate complex software design issues to others? UML ;-) * (II XC, III REQD) Describe to me your favorite design. Can you sketch it on the board in UML? * (II XC, III REQD) Describe a software development process that you use. How do you go about architecting your system or designing your software? * (II XC, III REQD) Name and lightly describe three design patterns. Sketch with UML if you wish. Observer, Singleton, State, MVC, Strategy, Memento, etc. * (II XC, III REQD) When would you use a Sequence Diagram? What can a Sequence Diagram help expose? To validate the Class diagram/object model. Helps expose flaws in the the object model. * (II XC, III XC) What's the difference between aggregation and composition? How can one support those differences in Java? Aggregation = whole/part but indep lifetimes. Composition = whole/part but coincident lifetimes. Support thru your own code (no built in constructs like in C++). * (II XC, III XC) What diagram is useful for showing software or component distribution? Deployment/Component Diagram ------ XML ------ * (II REQD, III REQD) What's the difference between SAX and DOM? SAX = one way stream. Need listeners. DOM = in memory and can traverse when done. * (II REQD, III REQD) What's the difference between and Element and an Attribute? * (II REQD, III REQD) Is XML case sensitive? YeS yOu BeT iT iS.