Java

From Redbrick Wiki
Jump to navigation Jump to search

J2EE/Java Interview Questions

Back to Interview Questions

JDBC

  • What is connection pooling? Why is it used?
  • How would you ensure a connection is always freed?
  • Write a small piece of pseudo-code to show how you’d open a connection, handle a commit/ rollback, and close the connection.

JSP

  • Explain what a JSP is, and talk about the life cycle of a JSP from code to deployment?
  • What’s the difference between forwarding on to a different page with HttpRequest.forward(url) and HttpResponse.sendRedirect(url);
  • Talk about the differences between different scopes of variables in jsp, e.g. session, page, application scope.
  • If there was a problem with login sessions timing out too early, where would you look to see the setting?

XML

  • What are the differences between the SAX and the DOM models for parsing. What are their advantages/disadvantages?
  • Given this DTD
<!DOCTYPE NEWSPAPER [ 

<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BODY)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>

<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED> 

]>

Write out two short bits of XML that would validate based on this DTD.


  • Given an exception like this, what would be your thoughts on where to look for the problem?
com.ibm.wcm.xml.sax.SAXParseException: The value of attribute "conditions" must not contain the '<' character.
at com.ibm.wcm.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1196)
at com.ibm.wcm.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:654)
at com.ibm.wcm.apache.xerces.framework.XMLDocumentScanner.scanAttValue(XMLDocumentScanner.java(Compiled Code))
at com.ibm.wcm.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java(Compiled Code))
at com.ibm.wcm.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java(Compiled Code))
at com.ibm.wcm.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at com.ibm.wcm.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
at com.ibm.wcm.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195)
at com.ibm.wcm.common.XMLDocumentProcessor.stringToNode(Unknown Source)
at com.ibm.wca.MassLoader.ErrorReporter.ErrorProcessor.createRecordNode(Unknown Source)
at com.ibm.wca.MassLoader.ErrorReporter.ErrorProcessor.addError(UnknownSource)
at com.ibm.wca.MassLoader.ErrorReporter.DefaultErrorReporter.processErrorEvent(Unknown Source)
at com.ibm.wca.MassLoader.ErrorReporter.DefaultErrorReporter.event(Unknown Source)
at com.ibm.wca.MassLoader.Events.MassLoaderEventHandler.notifyListners(Unknown Source)(Compiled Code)
at com.ibm.wca.MassLoader.Writer.JDBCWriter$WriteWorker.processFailure(Unknown Source)
at com.ibm.wca.MassLoader.Writer.JDBCWriter$WriteWorker.run(Unknown Source)(Compiled Code)
Error in MassLoading, please check logs for details.


Java

  • Explain the ideas behind java.lang.Thread and java.lang.Runnable, and the run() and start() methods.
  • Write some pseudo code to show the rough idea of the java.util.Observer / java.util.Observable classes and/or the general Observer/Observable pattern?
  • How would you list the contents of a jar file?


  • What would this class print out if you ran it?
public class test
{

  public Integer i;

  public static void main(String[] args)
  {
    test t = new test(); 

    System.out.println(" 1: " + t.stringEq() );

    String str = "hello 123 there";
    trim(str);
    System.out.println(" 2: " + str ); 

    Integer sq = t.square(t.i);
    System.out.println(" 3: " + sq );
  } 

  public boolean stringEq()
  {
    return "abc" == "abc";
  } 

  private static void trim(String str)
  {
    // remove white space
    str.replaceAll("\\s", "");
    // remove non-letters
    str.replaceAll("\\W", "");
  }          
 
 private Integer square(Integer i )
  {
    return new Integer(i.intValue() * i.intValue());
  }
}

EJB

  • What are the different types of EJB?
  • Draw a diagram showing how EJB usage works, in terms of the different objects which are created and used when you call remote methods on an EJB.