Questions, Questions, Questions

Q. Give a tabular definition of common Collection classes.

Q. How would you classify exceptions?

Q Can we call ordinary methods from a synchronized method?

It is good programming advice not to call methods from inside a synchronized method because you may lose track of methods being called and end up in a deadlock because of bad programming. Don’t call any methods within a synchronized block except the class Object methods (wait, notify,).

Q What are the types of validation in Struts?

Validations in Struts are server side.
1. Server side using validation.xml without using javascript and
2. Validation using ValidatorForm with validate() method
In both cases the Form Bean needs to extend ValidatorForm. What you write in validation.xml is invoked by super.validate().
Struts framework reads validation.xml and puts some request attributes as error messages which gets passed on to the tag class behind


, which then creates html and sends it to the client.
If you are overriding the validate() method and plan to use both validation.xml as well as handcode the validate() method then you need to use super.validate().
validation.xml will still work if you don’t override the validate() method in your Form Bean extending ValidatorForm because it will inherit super’s validate() method.

Q How would you compare statement, prepared statement and callable statement in SQL?

Callable statement is a different animal, comparing it to queries is like apples and oranges.
Prepared statement is the faster of the two- statement and prepared statement. You write a query “select * from blah where foo=’a’” and next time it is “select * from blah where foo=’b’”, there is a slight change in passed parameter, but the database doesn’t know the difference. It will parse the second query without any memory of the first.
If you use the prepared statement with “?” as placeholder, then the database knows that the query does NOT need to be reparsed. It is cached internally, only the parameter value is changed.

Q Compare SAX and DOM parsers.

A DOM parser processes XML data and creates a tree representation of the document that you can navigate at run-time. The tree representation occupies memory and can be a major resource overhead.
The SAX parser on the other hand raises events that you can handle as you see fit.
Because of this design, the SAX implementation is generally faster and requires fewer resources. On the other hand, SAX code is frequently complex. A SAX parser is suitable for sequential and infrequent access while a DOM parser is more useful for frequent and random access.

Q Name some xsl:fo tags.

A snippet demonstrating use of some xsl:fo tags follows:

<xsl:stylesheet version="1.0"
	xmlns:xsl="" xmlns:fo="">
							<xsl:apply-templates select="category" />

	<xsl:template match="category">
			<xsl:value-of select="." />


An asset to our company

Q Name some xsl tags.

A snippet demonstrating use of xsl tags follows:


<xsl:for-each select="ENTRY">
	<xsl:for-each select="ENGLISH">
		<td width="25%">
			<xsl:if test="string(.)!='null'">
					<xsl:value-of select="." />



Q Name some JSF tags:

A snippet demonstrating JSF tags follows:

		<h:panelGrid id="grid1" columns="2" border="0" width="100%">
			<h:outputText id="text1" style="color: #000099;" value="Enter ISBN Code :" />
			<h:inputText value="#{authorBean.isbnCode}" />

A similar snippet using ADF faces would look like this:

<ui:define name="body">
	<div id="MyForm" class="HeaderBlock">
		<h:panelGrid columns="2">
			<af:outputLabel for="userName" value="Enter UserName " />
			<af:inputText id=" userName " columns="30"
				value="#{MyBean.userName}" maximumLength="40" />

Q What are the implicit variables in JSP, and what are their servlet equivalents?

Implicit vars in JSP       Scope           Servlet-Equivalent

application      application       ServletContext
request          request           HttpServletRequest
session          session           HttpSession
response                         HttpServletResponse
out                              PrintWriter
config                           ServletConfig
exception                        Throwable
page                             Object

Q Name some Ant tags.

<target name="war" depends="compile">
	<war warfile="${war}" webxml="${conf.dir}/web.xml">
		<classes dir="${build.classes.dir}">
			<include name="**/**" />
		</classes><!--All files included in this fileset will end up in the WEB-INF/classes
			directory of the war file -->
		<fileset dir="${css.dir}">
			<include name="**/**" />
		</fileset><!--places files from css dir(build) into root of the war -->
		<webinf dir="${conf.dir}">
			<include name="**/**" />
		</webinf><!--places files from conf dir(build) into WEB-INF of war -->
		<zipfileset dir="${images.dir}" prefix="images" />
		<!--places folder of images dir(build and places it in folder called "images"
			in root of war) > <lib dir="${jsf.lib.dir}"/><!--places files from lib(build
			into WEB-INF/lib folder of war) -->

Q what are inner and outer joins in SQL?

Inner joins will return all rows from multiple tables where the join condition(in the “where” clause) is met.
An outer join returns all rows from one table and only those rows from a secondary table where the joined fields are equal (join condition is met).

Q. Name some Struts tags:

Some Struts tags:

Struts html tags: <html:text../> <html:form../> <html:errors/> <html:submit../> <html:reset../>
Struts bean tags: <bean:write.../> <bean:message.../>
Struts logic tags: <logic:iterate../> <logic:empty.../>
Struts nested tags: <nested:write... /> <nested:iterate.../>
Struts tiles tags: <tiles:insert../> <tiles:put../>

What is connection pooling?

A connection pool is a cache of open connections that can be used and reused, thus cutting down on the overhead of creating and destroying database connections.

Q. Briefly describe Servlet and JSP life cycles.

Servlet Life Cycle

When the Servlet Container starts up, it looks for web.xml, which includes an entry for each of the servlet the application uses. The servlet creates an instance of the compiled class and loads it. Next the servlet is initialized with initialization parameters in the ServletConfig object. The servlet is initialized after init() method returns. (Lazy loading – The servlet container does not initialize the servlet as soon as it starts up but rather when it receives a specific request for that servlet for the first time).
After the servlet instance is initialized, it is ready to service client requests. When the servlet container no longer needs the servlet instance(such as when the container is shutting down, or it is running low on resources, or no request has arrived for that servlet for a long itme), the servlet instance again goes to the unloaded state and cannot service any requests. Once destroyed, the servlet instance is garbage collected.

JSP life cycle

For each client request, the jsp container checks if the JSP page is new or has already been converted to a class file. If so, page translation occurs where the jsp code is converted to a regular java file, after checking for translation time errors. This java file is then compiled into a class file after compile time errors are checked. Once an instance of the class file is loaded it follows the same life cycle pattern as a regular servlet except that the following methods are involved
jspInit() instead of init()
jspDestroy() instead of destroy()
The container calls _jspService(), which was created during translation time by the jsp container, for each request.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Comments are closed.