Interview Questions.

J2EE Interview Questions and Answers

fluid

J2EE Interview Questions and Answers

Q1.What is J2EE?

Ans: J2EE is an environment for developing and deploying business enterprise applications. The J2EE platform includes a fixed of services, software programming interfaces (APIs), and protocols that provide the capability for developing multi tiered, and internet-primarily based packages.

Q2.What is Generic Servlet ?

Ans: Defines a everyday, protocol-independent servlet. GenericServlet implements the Servletand ServletConfig interfaces. GenericServlet makes writing servlets less difficult. It gives simple variations of the lifecycle methods in it and damage. To use Protocol unique servlet like http protocol, we will use HttpServlet. Difference in HttpServlet and GenericServlet is that, HttpServlet presents few greater techniques like doGet and doPost. Same operations can be carried out in carrier method of well-known servlet.  Read Servlet Life cycle

Q3. What is the J2EE module?

Ans: A J2EE module includes one or more J2EE additives for the identical box kind and one factor deployment descriptor of that kind.

Q4. Can summary class have Constructor ?

Ans: Yes. Abstract elegance will have a constructor.

Q5.What are the components of J2EE software?

Ans: A J2EE thing is a self-contained purposeful software unit that is assembled right into a J2EE application with its associated lessons and files and communicates with different components. The J2EE specification defines the subsequent J2EE components:

Application customers and applets are client components.

Java Servlets and Java Server Pages(JSP) technology components are internet components.

Enterprise JavaBeans (EJB) components (employer beans) are commercial enterprise additives.

Resource adapter additives supplied by using EIS and device vendors.

Q6. We can't instantiate the abstract elegance, then what is the want of constructor and the way it is known as?

Ans: You may have now not come upon this case. But answer i very smooth. If need to initialize few parameters for all the subclasses then we will use the constructor of abstract elegance. Constructor calling mechanism is same as ordinary inheritance in java. Default constructor gets called automatically and to call different constructors we have to explicitly call it via the usage of key-word “super”.

Q7. What are the four types of J2EE modules?

Ans:

Application purchaser module

Web module

Enterprise JavaBeans module

Resource adapter module

Q8. Does java have digital feature?

Ans: As such there's no keyword “virtual” found in java. But besides static, final and personal method all of the techniques are virtual bu default.  Refer this newsletter to read extra on it.

Q9. What does application patron module include?

Ans: The software client module carries:class files,an utility consumer deployment descriptor.

Application consumer modules are packaged as JAR files with a .Jar extension.

Q10. What are different ways to create Action training in Struts2?

Ans: Struts2 offer exclusive methods to create action http://classes.By imposing Action interfaceUsing Struts2 @Action annotationBy extending ActionSupport classAny ordinary java elegance with execute() approach returning String can be configured as Action magnificence.

Q11. How you'll create custom tag in JSP?

Ans: Create tld record in “WEB-INF/tlds” folder and configure required houses.

Create a class which implements interface Tag / BodyTag or extends elegance TagSupport / BodyTagSupport. In that magnificence write getter and setter for described property. Few strategies required by using interface are doStartTag(), doEndTag() and release(). Read the way to create custom tagin detail.

Q12. What does resource adapt module comprise?

Ans: The aid adapt module includes:

1.All Java interfaces

2.Classes

3.Local libraries

4.Different documentation

five.A useful resource adapter deployment descriptor.

Resource adapter modules are applications as JAR documents with a .Rar (Resource adapter Archive) extension.

Q13. What is Externalization ?

Ans: Externalization is the interface supplied via the JAVA which extends interface Serializable. It provides  greater methods compared to Serializable interface –

void readExternal(ObjectInput in)

void writeExternal(ObjectOutput out)

The above  techniques gives the flexibility and manipulate over how the object is serialized and deserialized. For similarly read refer this newsletter.

Q14. How many improvement roles are concerned in J2EE application?

Ans: There are at least 5 roles concerned:

Enterprise Bean Developer

Writes and compiles the supply code

Specifies the deployment descriptor

Bundles the .Magnificence files and deployment descriptor into an EJB JAR document

Web Component Developer

Writes and compiles Servlets supply code

Writes JSP and HTML files

Specifies the deployment descriptor for the Web issue

Bundles the .Magnificence, .Jsp, .Html, and deployment descriptor documents in the WAR document

J2EE Application Client Developer

Writes and compiles the supply code

Specifies the deployment descriptor for the purchaser

Bundles the .Magnificence files and deployment descriptor into the JAR record

Application Assembler The utility assembler is the company or character who gets application element JAR documents from thing companies and assembles them into a J2EE utility EAR report. The assembler or deployer can edit the deployment descriptor without delay or use gear that correctly upload XML tags consistent with interactive picks. A software program developer performs the following obligations to deliver an EAR document containing the J2EE software:

Assembles EJB JAR and WAR documents created inside the previous levels right into a J2EE application (EAR) document

Specifies the deployment descriptor for the J2EE application

Verifies that the contents of the EAR report are nicely formed and comply with the J2EE specification

Application Deployer and Administrator

Configures and deploys the J2EE application

Resolves outside dependencies

Specifies protection settings & attributes

Assigns transaction attributes and units transaction controls

Specifies connections to databases

Deploys or installs the J2EE application EAR record into the J2EE server

Administers the computing and networking infrastructure where J2EE applications run

Oversees the runtime surroundings

But a developer function depends on the process challenge. For a small company, one developer might also take these five roles altogether.

Q15. What is the usage of serialVersionUID in JAVA?

Ans: Whenever object is created, one specific ID is associated with object and its implementation may also defer from compiler to compiler. Whenever any object is serialized and deserealized, this variable is used to determine whether the item is in equal nation or now not ? Task of default serialVersionUID is generally depends upon the techniques and fields present in elegance and if any discipline is introduced or eliminated from the magnificence definition then its serialVersionUID additionally adjustments and if the cost does now not match then it effects in “InvalidClassException”. Because of this motive it's far advocated to have a default unique serialVersionUID with every serialized undergoing elegance. To read in element with instance, refer this text.

Q16. What is difference between J2EE 1.3 and J2EE 1.4?

Ans: J2EE 1.4 is an enhancement version of J2EE 1.3. It is the most complete Web services platform ever.

J2EE 1.Four consists of:

Java API for XML-Based RPC (JAX-RPC 1.1)

SOAP with Attachments API for Java (SAAJ),

Web Services for J2EE(JSR 921)

J2EE Management Model(1.Zero)

J2EE Deployment API(1.1)

Java Management Extensions (JMX),

Java Authorization Contract for Containers(JavaACC)

Java API for XML Registries (JAXR)

Servlet 2.Four

JSP 2.Zero

EJB 2.1

JMS 1.1

J2EE Connector 1.5

The J2EE 1.4 features whole Web services guide thru the new JAX-RPC 1.1 API, which helps service endpoints based on Servlets and business enterprise beans. JAX-RPC 1.1 presents interoperability with Web offerings based at the WSDL and SOAP protocols.

The J2EE 1.4 platform also helps the Web Services for J2EE specification (JSR 921), which defines deployment requirements for Web offerings and makes use of the JAX-RPC programming version.

In addition to numerous Web services APIs, J2EE 1.Four platform also features help for the WS-I Basic Profile 1.Zero. This way that in addition to platform independence and complete Web offerings guide, J2EE 1.Four gives platform Web offerings interoperability.

The J2EE 1.Four platform additionally introduces the J2EE Management 1.0 API, which defines the information version for J2EE management, along with the standard Management EJB (MEJB). The J2EE Management 1.Zero API uses the Java Management Extensions API (JMX).

The J2EE 1.Four platform also introduces the J2EE Deployment 1.1 API, which affords a popular API for deployment of J2EE packages.

The J2EE 1.Four platform consists of safety enhancements through the introduction of the Java Authorization Contract for Containers (JavaACC). The JavaACC API improves security with the aid of standardizing how authentication mechanisms are included into J2EE packing containers.

The J2EE platform now makes it simpler to develop internet the front ends with enhancements to Java Servlet and JavaServer Pages (JSP) technologies. Servlets now aid request listeners and improved filters. JSP technology has simplified the web page and extension development models with the introduction of a simple expression language, tag documents, and a simpler tag extension API, amongst other functions. This makes it simpler than ever for developers to construct JSP-enabled pages, specifically those who are familiar with scripting languages.

Q17. If i don’t need to serialize a few fields in elegance, then the way to gain this?

Ans: This question also can be requested as “What is the transientvariable ?”. “transient variables and static variables” can be used to avoid the field being serialized in Java. (As static variable is class stage variable, and it does now not related at item stage – it isn't always serialized).

Q18. What will show up if one of the members within the class doesn’t enforce Serializable interface?

Ans: If you attempt to serialize an object of a category which implements Serializable, but the item includes a reference to an non- Serializable magnificence then a “˜NotSerializableException‘ might be thrown at runtime.

Q19. If a class is Serializable but its awesome elegance in not, what will be the kingdom of the example variables inherited from extremely good class after deserialization?

Ans: Java serialization process simplest maintains in object hierarchy until the class is Serializable and values of the instance variables inherited from exceptional magnificence might be initialized through calling constructorof Non-Serializable Super elegance all through deserialization method .

Q20. What is the conceptual distinction among interface and abstract magnificence ? When to use interface and summary magnificence ?

Abstract elegance and its usage :

Ans: A magnificence which is in part applied and have few summary methods are recognise an “summary class“. Few builders suppose that why everybody have to create a partial implementation ? The best instance i have in my thoughts is “DataMapper Pattern”. For the CRUD operation – open connection and close connection and series of keep technique might be recognised to the programmer but which question could be executed to keep or retrieve differs for special object. In that case createInsertSQL() technique can be made abstract and internally shop() will name openConnection() and closeConnection() that is applied. Beneath code snap explains the keep() technique.

Summary public String createInsertSQL();//abstract technique

public void store() //technique applied

try

openConnection();//technique applied

String square = createInsertSQL(); //summary technique

executeStatement();//approach carried out

 

trap(SQLException ex)

 

in the end

closeconnection();//technique carried out

 

Interface and its usage: As you can see in above code snap, best unknown implementation is the SQL Query which is made summary and others are applied. And consequently underlying child magnificence must put into effect the method createInsertSQL() and phone store().Interface also are known as “agreement”. When we understand the skeleton/ structure of the magnificence however it whole implementation differs then we must use interface. In following situation we must use interface:

Dependency injection

Runtime polymorphism

In design sample programming to interface is superior as opposed to programming to implementation (inheritance).

Q21. How to iterate over keys of HashMap in JDK 4 and 5?

Ans: This is the not unusual query requested in interview.

In JAVA five : we will use boost for loop as shown in above code, use map.KeySet(). This will return the Set (As Keys have to be unique)

In JAVA four : use map.KeySet() and get the Iterator object using map.Iterate() . Then using while loop , get the value for each key.

Q1.What is J2EE?

Ans: J2EE is an environment for developing and deploying business enterprise applications. The J2EE platform includes a fixed of services, software programming interfaces (APIs), and protocols that provide the capability for developing multi tiered, and internet-primarily based packages.

Q2.What is Generic Servlet ?

Ans: Defines a everyday, protocol-independent servlet. GenericServlet implements the Servletand ServletConfig interfaces. GenericServlet makes writing servlets less difficult. It gives simple variations of the lifecycle methods in it and damage. To use Protocol unique servlet like http protocol, we will use HttpServlet. Difference in HttpServlet and GenericServlet is that, HttpServlet presents few greater techniques like doGet and doPost. Same operations can be carried out in carrier method of well-known servlet.  Read Servlet Life cycle

Q3. What is the J2EE module?

Ans: A J2EE module includes one or more J2EE additives for the identical box kind and one factor deployment descriptor of that kind.

Q4. Can summary class have Constructor ?

Ans: Yes. Abstract elegance will have a constructor.

Q5.What are the components of J2EE software?

Ans: A J2EE thing is a self-contained purposeful software unit that is assembled right into a J2EE application with its associated lessons and files and communicates with different components. The J2EE specification defines the subsequent J2EE components:

Application customers and applets are client components.

Java Servlets and Java Server Pages(JSP) technology components are internet components.

Enterprise JavaBeans (EJB) components (employer beans) are commercial enterprise additives.

Resource adapter additives supplied by using EIS and device vendors.

Q6. We can't instantiate the abstract elegance, then what is the want of constructor and the way it is known as?

Ans: You may have now not come upon this case. But answer i very smooth. If need to initialize few parameters for all the subclasses then we will use the constructor of abstract elegance. Constructor calling mechanism is same as ordinary inheritance in java. Default constructor gets called automatically and to call different constructors we have to explicitly call it via the usage of key-word “super”.

Q7. What are the four types of J2EE modules?

Ans:

Application purchaser module

Web module

Enterprise JavaBeans module

Resource adapter module

Q8. Does java have digital feature?

Ans: As such there's no keyword “virtual” found in java. But besides static, final and personal method all of the techniques are virtual bu default.  Refer this newsletter to read extra on it.

Q9. What does application patron module include?

Ans: The software client module carries:class files,an utility consumer deployment descriptor.

Application consumer modules are packaged as JAR files with a .Jar extension.

Q10. What are different ways to create Action training in Struts2?

Ans: Struts2 offer exclusive methods to create action http://classes.By imposing Action interfaceUsing Struts2 @Action annotationBy extending ActionSupport classAny ordinary java elegance with execute() approach returning String can be configured as Action magnificence.

Q11. How you'll create custom tag in JSP?

Ans: Create tld record in “WEB-INF/tlds” folder and configure required houses.

Create a class which implements interface Tag / BodyTag or extends elegance TagSupport / BodyTagSupport. In that magnificence write getter and setter for described property. Few strategies required by using interface are doStartTag(), doEndTag() and release(). Read the way to create custom tagin detail.

Q12. What does resource adapt module comprise?

Ans: The aid adapt module includes:

1.All Java interfaces

2.Classes

3.Local libraries

4.Different documentation

five.A useful resource adapter deployment descriptor.

Resource adapter modules are applications as JAR documents with a .Rar (Resource adapter Archive) extension.

Q13. What is Externalization ?

Ans: Externalization is the interface supplied via the JAVA which extends interface Serializable. It provides  greater methods compared to Serializable interface –

void readExternal(ObjectInput in)

void writeExternal(ObjectOutput out)

The above  techniques gives the flexibility and manipulate over how the object is serialized and deserialized. For similarly read refer this newsletter.

Q14. How many improvement roles are concerned in J2EE application?

Ans: There are at least 5 roles concerned:

Enterprise Bean Developer

Writes and compiles the supply code

Specifies the deployment descriptor

Bundles the .Magnificence files and deployment descriptor into an EJB JAR document

Web Component Developer

Writes and compiles Servlets supply code

Writes JSP and HTML files

Specifies the deployment descriptor for the Web issue

Bundles the .Magnificence, .Jsp, .Html, and deployment descriptor documents in the WAR document

J2EE Application Client Developer

Writes and compiles the supply code

Specifies the deployment descriptor for the purchaser

Bundles the .Magnificence files and deployment descriptor into the JAR record

Application Assembler The utility assembler is the company or character who gets application element JAR documents from thing companies and assembles them into a J2EE utility EAR report. The assembler or deployer can edit the deployment descriptor without delay or use gear that correctly upload XML tags consistent with interactive picks. A software program developer performs the following obligations to deliver an EAR document containing the J2EE software:

Assembles EJB JAR and WAR documents created inside the previous levels right into a J2EE application (EAR) document

Specifies the deployment descriptor for the J2EE application

Verifies that the contents of the EAR report are nicely formed and comply with the J2EE specification

Application Deployer and Administrator

Configures and deploys the J2EE application

Resolves outside dependencies

Specifies protection settings & attributes

Assigns transaction attributes and units transaction controls

Specifies connections to databases

Deploys or installs the J2EE application EAR record into the J2EE server

Administers the computing and networking infrastructure where J2EE applications run

Oversees the runtime surroundings

But a developer function depends on the process challenge. For a small company, one developer might also take these five roles altogether.

Q15. What is the usage of serialVersionUID in JAVA?

Ans: Whenever object is created, one specific ID is associated with object and its implementation may also defer from compiler to compiler. Whenever any object is serialized and deserealized, this variable is used to determine whether the item is in equal nation or now not ? Task of default serialVersionUID is generally depends upon the techniques and fields present in elegance and if any discipline is introduced or eliminated from the magnificence definition then its serialVersionUID additionally adjustments and if the cost does now not match then it effects in “InvalidClassException”. Because of this motive it's far advocated to have a default unique serialVersionUID with every serialized undergoing elegance. To read in element with instance, refer this text.

Q16. What is difference between J2EE 1.3 and J2EE 1.4?

Ans: J2EE 1.4 is an enhancement version of J2EE 1.3. It is the most complete Web services platform ever.

J2EE 1.Four consists of:

Java API for XML-Based RPC (JAX-RPC 1.1)

SOAP with Attachments API for Java (SAAJ),

Web Services for J2EE(JSR 921)

J2EE Management Model(1.Zero)

J2EE Deployment API(1.1)

Java Management Extensions (JMX),

Java Authorization Contract for Containers(JavaACC)

Java API for XML Registries (JAXR)

Servlet 2.Four

JSP 2.Zero

EJB 2.1

JMS 1.1

J2EE Connector 1.5

The J2EE 1.4 features whole Web services guide thru the new JAX-RPC 1.1 API, which helps service endpoints based on Servlets and business enterprise beans. JAX-RPC 1.1 presents interoperability with Web offerings based at the WSDL and SOAP protocols.

The J2EE 1.4 platform also helps the Web Services for J2EE specification (JSR 921), which defines deployment requirements for Web offerings and makes use of the JAX-RPC programming version.

In addition to numerous Web services APIs, J2EE 1.Four platform also features help for the WS-I Basic Profile 1.Zero. This way that in addition to platform independence and complete Web offerings guide, J2EE 1.Four gives platform Web offerings interoperability.

The J2EE 1.Four platform additionally introduces the J2EE Management 1.0 API, which defines the information version for J2EE management, along with the standard Management EJB (MEJB). The J2EE Management 1.Zero API uses the Java Management Extensions API (JMX).

The J2EE 1.Four platform also introduces the J2EE Deployment 1.1 API, which affords a popular API for deployment of J2EE packages.

The J2EE 1.Four platform consists of safety enhancements through the introduction of the Java Authorization Contract for Containers (JavaACC). The JavaACC API improves security with the aid of standardizing how authentication mechanisms are included into J2EE packing containers.

The J2EE platform now makes it simpler to develop internet the front ends with enhancements to Java Servlet and JavaServer Pages (JSP) technologies. Servlets now aid request listeners and improved filters. JSP technology has simplified the web page and extension development models with the introduction of a simple expression language, tag documents, and a simpler tag extension API, amongst other functions. This makes it simpler than ever for developers to construct JSP-enabled pages, specifically those who are familiar with scripting languages.

Q17. If i don’t need to serialize a few fields in elegance, then the way to gain this?

Ans: This question also can be requested as “What is the transientvariable ?”. “transient variables and static variables” can be used to avoid the field being serialized in Java. (As static variable is class stage variable, and it does now not related at item stage – it isn't always serialized).

Q18. What will show up if one of the members within the class doesn’t enforce Serializable interface?

Ans: If you attempt to serialize an object of a category which implements Serializable, but the item includes a reference to an non- Serializable magnificence then a “˜NotSerializableException‘ might be thrown at runtime.

Q19. If a class is Serializable but its awesome elegance in not, what will be the kingdom of the example variables inherited from extremely good class after deserialization?

Ans: Java serialization process simplest maintains in object hierarchy until the class is Serializable and values of the instance variables inherited from exceptional magnificence might be initialized through calling constructorof Non-Serializable Super elegance all through deserialization method .

Q20. What is the conceptual distinction among interface and abstract magnificence ? When to use interface and summary magnificence ?

Abstract elegance and its usage :

Ans: A magnificence which is in part applied and have few summary methods are recognise an “summary class“. Few builders suppose that why everybody have to create a partial implementation ? The best instance i have in my thoughts is “DataMapper Pattern”. For the CRUD operation – open connection and close connection and series of keep technique might be recognised to the programmer but which question could be executed to keep or retrieve differs for special object. In that case createInsertSQL() technique can be made abstract and internally shop() will name openConnection() and closeConnection() that is applied. Beneath code snap explains the keep() technique.

Summary public String createInsertSQL();//abstract technique

public void store() //technique applied

try

openConnection();//technique applied

String square = createInsertSQL(); //summary technique

executeStatement();//approach carried out

 

trap(SQLException ex)

 

in the end

closeconnection();//technique carried out

 

Interface and its usage: As you can see in above code snap, best unknown implementation is the SQL Query which is made summary and others are applied. And consequently underlying child magnificence must put into effect the method createInsertSQL() and phone store().Interface also are known as “agreement”. When we understand the skeleton/ structure of the magnificence however it whole implementation differs then we must use interface. In following situation we must use interface:

Dependency injection

Runtime polymorphism

In design sample programming to interface is superior as opposed to programming to implementation (inheritance).

Q21. How to iterate over keys of HashMap in JDK 4 and 5?

Ans: This is the not unusual query requested in interview.

In JAVA five : we will use boost for loop as shown in above code, use map.KeySet(). This will return the Set (As Keys have to be unique)

In JAVA four : use map.KeySet() and get the Iterator object using map.Iterate() . Then using while loop , get the value for each key.




CFG