Search This Blog

Sunday, November 30, 2008

Java Interview Question.

Hi Friends,
This is my first posting.This all question asked in one of company interview .I don't want to mention the name of company .

If you have come across my blog read this question and send me the feed back for the same.mail to me :

This question and answer format is entirely changed from all other format.
1.precious information.
2.Clear format.
3.Explain about what?why? type of question answer.
4.Difference explanation in Tabular format.

Thanks & Regards,
Lets Enjoy::

1. What are jar, war and ear?


· Jar stands for Java archive.

· This is a file format that enables us to bundle multiple file in to single archive file.

· A jar file will contain one file inside the META-INF folder that describe the version and other feature of jar file.


· War stands for Web Archive.

· It’s a compressed version of web application.

· We can use war file to deploy web application.


· Ear stands for Enterprise archive.

· A J2EE application with all of its modules is delivered in EAR file (War, Jar).

2. What is abstract class ,interface?. Give similarity and difference between abstract and interface.

Definition Abstract:

· Abstract class is an incomplete class.

· Abstract class is defined with the keyword abstract.

· We can’t create object for the abstract class because is an incomplete class.

· It’s set the behavioral protocol for its child class.

Definition Interface:

· An Interface is the collection of method declaration and constant s.

· In Java interface used for achieving multiple inheritance.

· It’s set the behavioral protocol for implemental class.


· Both are set the behavioral protocol for implemental class.



Abstract class



It have concrete method

Not allowed


It has private protected methods and variable.

Only public method and constant.


Extend only one class.

Implement more than one interface.


Tightly coupling

Loosely coupling.

3. Different access level for instance variable, method and classes.

Public: It’s accessible from anywhere

Protected: it’s accessible from the same class and its subclass.

Default: It’s accessible from the same package.

Private : It’s accessible with in class.

4. What is deployment descriptor?

· It’s a XML file.

· Its describes the component deployment setting.

· J2EE application and each of modules has is it own deployment descriptor.

· Deployment descriptor information is declarative; it can be changed without modifying the bean source code.

· At run time, the J2EE server reads the deployment descriptor and acts upon the component accordingly

· Example an enterprise bean module deployment descriptor declares transaction attributes and security authorizations for an enterprise bean

5. Difference between forward and send redirect?



Send Redirect


The forward, sent request to another source with same server without user known.

Web container indicating browser to new URL to be requested.


This process completely with in web container

This request consider as new req.


Object stored in request attribute are forward to next resource.

New request object is generated.


Its faster approach for forward.

Extra round trip make slower.

6. JSP lifecycle method:

Three life cycle method

· jspInit() –The container call this method for initializing Servlet instance. It’s called before any other method, and is called only once for Servlet instance.

· _jspService()- The container calls the _jspservice for each request, passing it the request and response object.

· jspDestroy – The container call this method when its take instance out of the service. It is the method last called in the Servlet instance.

7. Difference between and <%@ page include file=”” %>


<%@ page include file=”” %>


This is like a function call from one JSP to another JSP.

The content of the included file is textually embedded in the page that have <%@ include file=".."> directive


It’s executed each time the client page is accessed by client.

Its executed only ones.


If the included file changed then the new content will be included in the output.

Included file changes, the changed content will not included in the output.


This approach is useful to for modularizing the web application

This approach is used when the code from one JSP file required including in multiple JSP files.

8. Difference between <%@ page forward=”” %> and response.sendRedirect(URL).




forwards the request object containing the client request information from one JSP file to another file.

sends HTTP temporary redirect response to the browser, and browser creates a new request to go the redirected page


Its maintaining session variable.

The response.sendRedirect kills the session variables.

9. Difference between Session bean and Entity bean?


Entity bean

Session bean


An entity bean represents persistent global data from the database.

Session is one of the EJBs and it represents a single client inside the Application Server.


Entity beans data are stored into database.

A session bean is not persistent and it is destroyed once the session terminates.


Entity bean will support the Transaction.

Session bean won’t support the transaction.

10. What is ActionServlet?

· The class org.apache.struts.action.ActionServlet is the called the ActionServlet.

· In the the Jakarta Struts Framework this class plays the role of controller.

· All the requests to the server go through the controller. Controller is responsible for handling all the requests.

11. What is action class and give example?

· The Action is part of the controller. The purpose of Action Class is to translate the HttpServletRequest to the business logic.

· To use the Action, we need to Subclass and overwrite the execute () method. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method.

· The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.



import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

public class TestAction extends Action


public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception

{ return mapping.findForward("testAction");



12. What is struts action and mapping?

Struts action Definition:

· A Struts action is an instance of a subclass of an Action class, which implements a portion of a Web application and whose perform or execute method returns a forward.

· An action can perform tasks such as validating a user name and password.

Struts mapping:

· An action mapping is a configuration file entry that, in general, associates an action name with an action.

· An action mapping can contain a reference to a form bean that the action can use, and can additionally define a list of local forwards that is visible only to this action.

13. What are struts validate frame work give needed XML file detail?

Struts validate frame work:

· Struts Framework provides the functionality to validate the form data.

· It can be use to validate the data on the users browser as well as on the server side.

· Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.

Details of XML files used in Validator Framework:

· The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml.

· The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations.

· The validation.xml defines the validations applied to a form bean.

14. It’s possible to read two struts configuration file in tomcat container with in same application?




















No comments:

Post a Comment