SlideShare a Scribd company logo
1 of 9
QUESTION BANK
UNIT –V
Q.1 Explain the architecture of EJB
Ans: A bean runs in a container. The container, which is part of the EJB server, provides a number of
services to the bean. These include transaction services, synchronization services, and security.
To provide these services, the bean container must be able to intercept calls
to bean methods. For example, a client application calls a bean method that
has a transaction attribute that requires the bean to create a new transaction
context. The bean container must be able to interpose code to start a new
transaction before the method call, and to commit the transaction, if possible,
when the method completes, and before any values are returned to the client.
For this reason and others, a client application does not call the remote bean
methods directly. Instead, the client invokes the bean method through a twostep process
mediated by the ORB and by the container.
 First, the client actually calls a local proxy stub for the remote method. The stub
marshalls any parameter data, and then calls a remote skeleton on the server. The
skeleton unmarshalls the data, and upcalls to the bean container.This step is required
because of the remote nature of the call. Note that this step is completely transparent
both to the client application developer as well as to the bean developer. It is a detail
that you do not need to know about to write your application code, either on the client
or the server. Nevertheless, it is useful to know what is going on, especially when it
comes to understanding what happens during bean deployment.
 In the second step, the bean container gets the skeleton upcall, then
interposes whatever services are required by the context. These can
include:
1. authenticating the client, on the first method call
2. performing transaction management
3. calling synchronization methods in the bean itself
4. identity checks and switch
 The container then delegates the method call to the bean. The bean method executes.
When it returns, the thread of control returns to the bean container,which interposes
whatever services are required by the context. For example,if the method is running in a
transaction context, the bean container performs a commit operation, if possible. This
depends on the transaction attributes in the bean descriptor.
 Then the bean container calls the skeleton, which Marshalls return data, and returns it
to the client stub.
These steps are completely invisible to client-side and server-side application
developers. One of the major advantages of the EJB development model is
that it hides the complexity of transaction and identity management from
developers.
Q.2 What are the different types of Enterprise Java Beans ? Explain
Ans: Types of EJB:
1. Session
2. Entity
3. Message-Driven
1. Session EJBs
A session EJB is a nonpersistent object: Its lifetime is the duration of a particular interaction
between the client and the EJB. The client normally creates an EJB, calls methods on it, and
then removes it. If the client fails to remove it, the EJB container will remove it after a certain
period of
inactivity. Session EJBs are subdivided into ‘stateful’ and ‘stateless’ types. A stateless session
EJB is shared amongst a number of clients, while a stateful session EJB is created for a specific
client and not used by any others. The use of stateless EJBs offers efficiency advantages but, of
course, it is not always possible to use them.
2. Entity EJBs
Entity EJBs represent persistent objects: Their lifetimes are not related to the duration of
interaction with clients. In nearly all cases, entity EJBs are synchronized with relational
databases. This is how persistence is achieved. Entity EJBs are always shared amongst clients: A
client cannot get an entity EJB to itself. Thus, entity EJBs are nearly always used as a scheme for
mapping relational databases into object-oriented applications. Whereas a client normally
creates a session EJB and removes it after use, clients normally look up an existing entity EJB.
Creation of an entity EJB corresponds to adding new data items to the application (e.g., adding
rows to database tables). An important feature of entity EJBs is that they have identity—that
is, one can be distinguished from another. This is implemented by assigning a primary key to
each instance of the EJB, where ‘primary key’ has the same meaning as it does for database
management. Primary keys that identify EJBs can be of any type, including programmer-
defined classes.
3. Message-driven EJBs
A message-driven bean acts as a consumer of asynchronous messages: It cannot be called
directly by clients, but is activated by the container when a message arrives. Clients interact
with these EJBs by sending messages to the queues or topics to which they are listening.
Although a message-driven EJB cannot be called directly by clients, it can call other EJBs itself.
Messagedriven EJBs are the only type that does not follow a strict request-response interaction
with clients.
Q.3 What is facelet ? what are its features?
Ans: Features:
 Server-side helper classes, such as database access beans
 A custom tag library for rendering UI components on a page
 A custom tag library for representing event handlers, validators , and other actions
 UI components represented as stateful objects on the server
 Backing beans, which define properties and functions for UI components
 Validators, converters, event listeners, and event handlers
 An application configuration resource file for configuring application resources
Q.4 Explain the life cycle of JSF
Ans:
Phase 1: Restore view
 JSF begins the restore view phase as soon as a link or a button is clicked and JSF receives
a request.
 During this phase, the JSF builds the view, wires event handlers and validators to UI
components and saves the view in the FacesContext instance. The FacesContext instance
will now contains all the information required to process a request.
Phase 2: Apply request values
 After the component tree is created/restored, each component in component tree uses
decode method to extract its new value from the request parameters. Component stores
this value. If the conversion fails, an error message is generated and queued on
FacesContext. This message will be displayed during the render response phase, along
with any validation errors.
 If any decode methods / event listeners called renderResponse on the current
FacesContext instance, the JSF moves to the render response phase.
Phase 3: Process validation
 During this phase, the JSF processes all validators registered on component tree. It
examines the component attribute rules for the validation and compares these rules to
the local value stored for the component.
 If the local value is invalid, the JSF adds an error message to the FacesContext instance,
and the life cycle advances to the render response phase and display the same page
again with the error message.
Phase 4: Update model values
 After the JSF checks that the data is valid, it walks over the component tree and set the
corresponding server-side object properties to the components' local values. The JSF will
update the bean properties corresponding to input component's value attribute.
 If any updateModels methods called renderResponse on the current FacesContext
instance, the JSF moves to the render response phase.
Phase 5: Invoke application
 During this phase, the JSF handles any application-level events, such as submitting a
form / linking to another page.
Phase 6: Render response
 During this phase, the JSF asks container/application server to render the page if the
application is using JSP pages. For initial request, the components represented on the
page will be added to the component tree as the JSP container executes the page. If this
is not an initial request, the component tree is already built so components need not to
be added again. In either case, the components will render themselves as the JSP
container/Application server traverses the tags in the page.
 After the content of the view is rendered, the response state is saved so that subsequent
requests can access it and it is available to the restore view phase.
Q.5 How does JSF application gets executed ? Explain
Ans: The hello example JSF application goes through the following stages when it is deployed on the
GlassFish Server.
1. When the hello application is built and deployed on the GlassFish Server, the application is
in an uninitiated state.
2. When a client makes an initial request for the beanhello.xhtml web page, the hello Facelets
application is compiled.
3. The compiled Facelets application is executed, and a new component tree is constructed for
the hello application and is placed in ajavax.faces.context.FacesContext.
4. The component tree is populated with the component and the managed bean property
associated with it, represented by the EL expression hello.world.
5. A new view is built, based on the component tree.
6. The view is rendered to the requesting client as a response.
7. The component tree is destroyed automatically.
8. On subsequent (postback) requests, the component tree is rebuilt, and the saved state is
applied.
Q.6 Write a session bean code specification that calculates compound interest. Assume principal,
terms and rate of interest is entered by the user and the input is passed through a servlet
Ans: Clacjsp.jsp: // jsp web page created
<form action="calcservlet" method="post">
Principal: <input type="text" name="t1"/>
Rate: <input type="text" name="t2"/>
No_of_years: <input type="text" name="t3"/>
<input type="submit" name="submit"/>
</form>
Calcservlet.java: // servlet file created
package mybean;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class calcservlet extends HttpServlet {
@EJB
private simpleLocal simple;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet calcservlet</title>");
out.println("</head>");
out.println("<body>");
Double a=Double.parseDouble(request.getParameter("t1"));
Double b=Double.parseDouble(request.getParameter("t2"));
Double c=Double.parseDouble(request.getParameter("t3"));
out.println("<h1>Simple Interest = " + simple.calcsimple(a, b, c)+ "</h1>");
out.println("</body>");
out.println("</html>");
}
}
}
Simple.java : // bean created
package mybean;
import javax.ejb.Stateless;
import java.util.Scanner;
@Stateless
public class simple implements simpleLocal {
@Override
public Double calccomp(double a, double b, double c) {
double ci=a*Math.pow((1+b/100),c);
return ci;
} }
Q.7. Write the benefits of using EJB
Ans: For several reasons, enterprise beans simplify the development of large, distributed
applications.
 because the EJB container provides system-level services to enterprise beans, the bean
developer can concentrate on solving business problems. The EJB container, rather than
the bean developer, is responsible for system-level services, such as transaction
management and security authorization.
 because the beans rather than the clients contain the application’s business logic, the
client developer can focus on the presentation of the client. The client developer does
not have to code the routines that implement business rules or access databases. As a
result, the clients are thinner, a benefit that is particularly important for clients that run
on small devices.
 because enterprise beans are portable components, the application assembler can build
new applications from existing beans. Provided that they use the standard APIs, these
applications can run on any compliant Java EE server.
Q.8 Create a JSF application for checking the validity of the user
Ans: Example:
<%@ page contentType="text/html"%>
<%@ tagliburi="http://java.sun.com/jsf/core" prefix="f"%>
<%@ tagliburi="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<html>
<head><title>JSF Login Application</title></head>
<body> <h:form>
<h:panelGroup rendered="#{login.validationComplete and (!login.isUsernameValid or
!login.isPasswordValid)}">
<h:outputText value="Username is a Required Field" rendered="#{!login.isUsernameValid}"
style="color:red"></h:outputText> <br>
<h:outputText value="Password is a Required Field" rendered="#{!login.isPasswordValid}"
style="color:red"></h:outputText>
</h:panelGroup>
<h:panelGroup rendered="#{login.validationComplete and (login.isUsernameValid and
login.isPasswordValid)}">
<h:outputText value="Username & Password are valid" style="color:green"></h:outputText>
</h:panelGroup>
<table>
<tr>
<td><h:outputText value="Enter Username: " /></td>
<td><h:inputText id="username" value="#{login.username}" /> </td>
</tr>
<tr>
<td><h:outputText value="Enter Password: " /></td>
<td><h:inputSecret id="password" value="#{login.password}" /> </td>
</tr>
<tr>
<td> </td>
<td><h:commandButton value="Login" action="#{login.checkValidity}"/> </td>
</tr>
</table>
</h:form> </body>
</html>
</f:view>
1. <%@ tagliburi="http://java.sun.com/jsf/core" prefix="f"%>
<%@ tagliburi="http://java.sun.com/jsf/html" prefix="h"%>
This line links to the jsf core and jsf html tag libraries. The jsf html tag
library carries regular html components like text box, buttons, etc.
2. <f:view></f:view>
This tag at the beginning of the document acts as a container for all the
components enclosed between them.
3. <h:panelGroup rendered="#{login.validationComplete and (!login.isUsernameValid or
!login.isPasswordValid)}">
<h:outputText value="Username is a Required Field"
rendered="#{!login.isUsernameValid}" style="color:red"></h:outputText> <br>
<h:outputText value="Password is a Required Field"
rendered="#{!login.isPasswordValid}" style="color:red"></h:outputText>
</h:panelGroup>
The above code snippet is intended to display error and success messages.
The first part displays the error messages one after the other. The second
part displays a single success message. This code uses Expression
Language (EL) to do conditional checks and reference the managed bean
values.
4. <h:panelGroup rendered="#{login.validationComplete and (login.isUsernameValid and
login.isPasswordValid)}">
<h:outputText value="Username & Password are valid"
style="color:green"></h:outputText> </h:panelGroup>
The following line in the above code snippet checks to see if the validation
failed before displaying the error messages
Q.9 Explain with suitable example <navigation-rule> element of faces-config.xml file of JSF
Ans:  Navigation between different pages of a Java Server Faces application, such as choosing
the next page to be displayed after a button or hyperlink component is clicked, is defined
by a set of rules.
 Navigation rules can be implicit, or they can be explicitly defined in the application
configuration resource file.
 These navigation rules are defined in JSF configuration files along with other definitions
for a JSF application. Usually, this file is named faces-config.xml.
Here is a navigation rule that could be used with the example just described:
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-action>#{LoginForm.login}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/storefront.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{LoginForm.logon}</from-action>
<from-outcome>failure</from-outcome>
<to-view-id>/logon.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
This navigation rule defines the possible ways to navigate from login.xhtml. Each navigation-
case element defines one possible navigation path fromlogin.xhtml. The first navigation-
case says that if LoginForm.login returns an outcome of success, then storefront.xhtml will be
accessed. The second navigation-case says that login.xhtml will be re-rendered
if LoginForm.login returns failure.

More Related Content

What's hot

Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)Fahad Golra
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applicationselliando dias
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedIMC Institute
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Courseguest764934
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicIMC Institute
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsIMC Institute
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 
Introduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcAbdelmonaim Remani
 

What's hot (20)

Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Struts course material
Struts course materialStruts course material
Struts course material
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
Jsf
JsfJsf
Jsf
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 Basics
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
EJB 2
EJB 2EJB 2
EJB 2
 
Introduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring Mvc
 

Viewers also liked

Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTA
Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTAStrategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTA
Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTAWenna Foeh Son
 
PERENCANAAN STRATEGIS KAMPANYE DAN PELAKSANAAN KAMPANYE
PERENCANAAN STRATEGIS KAMPANYE  DAN PELAKSANAAN KAMPANYE PERENCANAAN STRATEGIS KAMPANYE  DAN PELAKSANAAN KAMPANYE
PERENCANAAN STRATEGIS KAMPANYE DAN PELAKSANAAN KAMPANYE University of Andalas
 
Konsep ringsatu
Konsep ringsatuKonsep ringsatu
Konsep ringsatuFdj Gsb
 
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"Strategi Pencitraan "Personal Branding Concept of Indonesia Political"
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"Giant Hermanto
 
Pedoman Manajemen relawan
Pedoman Manajemen relawanPedoman Manajemen relawan
Pedoman Manajemen relawanAnahdraw Naidra
 
strategi kampanye politik di social media
strategi kampanye politik di social mediastrategi kampanye politik di social media
strategi kampanye politik di social mediakatapedia
 
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...Wenna Foeh Son
 
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA Polmantic
 

Viewers also liked (11)

Tppd kabupaten indramayu
Tppd kabupaten indramayuTppd kabupaten indramayu
Tppd kabupaten indramayu
 
Sosok pilihan
Sosok pilihanSosok pilihan
Sosok pilihan
 
Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTA
Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTAStrategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTA
Strategi memenangkan PILKADA GUBERNUR, BUPATI WALIKOTA
 
PERENCANAAN STRATEGIS KAMPANYE DAN PELAKSANAAN KAMPANYE
PERENCANAAN STRATEGIS KAMPANYE  DAN PELAKSANAAN KAMPANYE PERENCANAAN STRATEGIS KAMPANYE  DAN PELAKSANAAN KAMPANYE
PERENCANAAN STRATEGIS KAMPANYE DAN PELAKSANAAN KAMPANYE
 
Team Sukses
Team SuksesTeam Sukses
Team Sukses
 
Konsep ringsatu
Konsep ringsatuKonsep ringsatu
Konsep ringsatu
 
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"Strategi Pencitraan "Personal Branding Concept of Indonesia Political"
Strategi Pencitraan "Personal Branding Concept of Indonesia Political"
 
Pedoman Manajemen relawan
Pedoman Manajemen relawanPedoman Manajemen relawan
Pedoman Manajemen relawan
 
strategi kampanye politik di social media
strategi kampanye politik di social mediastrategi kampanye politik di social media
strategi kampanye politik di social media
 
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...
Strategi memenangkan pilkada gubernur, bupati, walikota & pemilihan legislati...
 
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA
PROPOSAL STRATEGI MENANG PILKADA 2015 DENGAN PETA SUARA
 

Similar to TY.BSc.IT Java QB U5

ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006achraf_ing
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideBOSC Tech Labs
 
Student_result_management_system_project.doc
Student_result_management_system_project.docStudent_result_management_system_project.doc
Student_result_management_system_project.docAnshChhabra6
 
Session 9 Tp9
Session 9 Tp9Session 9 Tp9
Session 9 Tp9phanleson
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2phanleson
 
J2EEFeb11 (1).ppt
J2EEFeb11 (1).pptJ2EEFeb11 (1).ppt
J2EEFeb11 (1).pptrani marri
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part IIMichael Fons
 

Similar to TY.BSc.IT Java QB U5 (20)

ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
JSF.pptx
JSF.pptxJSF.pptx
JSF.pptx
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
Jsf
JsfJsf
Jsf
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Jsf 2
Jsf 2Jsf 2
Jsf 2
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive Guide
 
Java unit 4_cs_notes
Java unit 4_cs_notesJava unit 4_cs_notes
Java unit 4_cs_notes
 
Student_result_management_system_project.doc
Student_result_management_system_project.docStudent_result_management_system_project.doc
Student_result_management_system_project.doc
 
J2EEFeb11.ppt
J2EEFeb11.pptJ2EEFeb11.ppt
J2EEFeb11.ppt
 
Session 9 Tp9
Session 9 Tp9Session 9 Tp9
Session 9 Tp9
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2
 
Ejb notes
Ejb notesEjb notes
Ejb notes
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
J2EEFeb11 (1).ppt
J2EEFeb11 (1).pptJ2EEFeb11 (1).ppt
J2EEFeb11 (1).ppt
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 

More from Lokesh Singrol

Project black book TYIT
Project black book TYITProject black book TYIT
Project black book TYITLokesh Singrol
 
Computer institute website(TYIT project)
Computer institute website(TYIT project)Computer institute website(TYIT project)
Computer institute website(TYIT project)Lokesh Singrol
 
Top Technology product failure
Top Technology product failureTop Technology product failure
Top Technology product failureLokesh Singrol
 
HP Software Testing project (Advanced)
HP Software Testing project (Advanced)HP Software Testing project (Advanced)
HP Software Testing project (Advanced)Lokesh Singrol
 
Testing project (basic)
Testing project (basic)Testing project (basic)
Testing project (basic)Lokesh Singrol
 
Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Lokesh Singrol
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)Lokesh Singrol
 
Desktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemDesktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemLokesh Singrol
 

More from Lokesh Singrol (16)

MCLS 45 Lab Manual
MCLS 45 Lab ManualMCLS 45 Lab Manual
MCLS 45 Lab Manual
 
MCSL 036 (Jan 2018)
MCSL 036 (Jan 2018)MCSL 036 (Jan 2018)
MCSL 036 (Jan 2018)
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
TY.BSc.IT Java QB U2
TY.BSc.IT Java QB U2TY.BSc.IT Java QB U2
TY.BSc.IT Java QB U2
 
Project black book TYIT
Project black book TYITProject black book TYIT
Project black book TYIT
 
Computer institute website(TYIT project)
Computer institute website(TYIT project)Computer institute website(TYIT project)
Computer institute website(TYIT project)
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
Top Technology product failure
Top Technology product failureTop Technology product failure
Top Technology product failure
 
HP Software Testing project (Advanced)
HP Software Testing project (Advanced)HP Software Testing project (Advanced)
HP Software Testing project (Advanced)
 
Testing project (basic)
Testing project (basic)Testing project (basic)
Testing project (basic)
 
Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Computer institute Website(TYIT project)
Computer institute Website(TYIT project)
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)
 
Desktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemDesktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld system
 
Raster Scan display
Raster Scan displayRaster Scan display
Raster Scan display
 
Flash memory
Flash memoryFlash memory
Flash memory
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

TY.BSc.IT Java QB U5

  • 1. QUESTION BANK UNIT –V Q.1 Explain the architecture of EJB Ans: A bean runs in a container. The container, which is part of the EJB server, provides a number of services to the bean. These include transaction services, synchronization services, and security. To provide these services, the bean container must be able to intercept calls to bean methods. For example, a client application calls a bean method that has a transaction attribute that requires the bean to create a new transaction context. The bean container must be able to interpose code to start a new transaction before the method call, and to commit the transaction, if possible, when the method completes, and before any values are returned to the client. For this reason and others, a client application does not call the remote bean methods directly. Instead, the client invokes the bean method through a twostep process mediated by the ORB and by the container.  First, the client actually calls a local proxy stub for the remote method. The stub marshalls any parameter data, and then calls a remote skeleton on the server. The skeleton unmarshalls the data, and upcalls to the bean container.This step is required because of the remote nature of the call. Note that this step is completely transparent both to the client application developer as well as to the bean developer. It is a detail that you do not need to know about to write your application code, either on the client or the server. Nevertheless, it is useful to know what is going on, especially when it comes to understanding what happens during bean deployment.  In the second step, the bean container gets the skeleton upcall, then interposes whatever services are required by the context. These can include: 1. authenticating the client, on the first method call 2. performing transaction management 3. calling synchronization methods in the bean itself 4. identity checks and switch  The container then delegates the method call to the bean. The bean method executes. When it returns, the thread of control returns to the bean container,which interposes whatever services are required by the context. For example,if the method is running in a transaction context, the bean container performs a commit operation, if possible. This depends on the transaction attributes in the bean descriptor.  Then the bean container calls the skeleton, which Marshalls return data, and returns it to the client stub. These steps are completely invisible to client-side and server-side application developers. One of the major advantages of the EJB development model is that it hides the complexity of transaction and identity management from
  • 2. developers. Q.2 What are the different types of Enterprise Java Beans ? Explain Ans: Types of EJB: 1. Session 2. Entity 3. Message-Driven 1. Session EJBs A session EJB is a nonpersistent object: Its lifetime is the duration of a particular interaction between the client and the EJB. The client normally creates an EJB, calls methods on it, and then removes it. If the client fails to remove it, the EJB container will remove it after a certain period of inactivity. Session EJBs are subdivided into ‘stateful’ and ‘stateless’ types. A stateless session EJB is shared amongst a number of clients, while a stateful session EJB is created for a specific client and not used by any others. The use of stateless EJBs offers efficiency advantages but, of course, it is not always possible to use them. 2. Entity EJBs Entity EJBs represent persistent objects: Their lifetimes are not related to the duration of interaction with clients. In nearly all cases, entity EJBs are synchronized with relational databases. This is how persistence is achieved. Entity EJBs are always shared amongst clients: A client cannot get an entity EJB to itself. Thus, entity EJBs are nearly always used as a scheme for mapping relational databases into object-oriented applications. Whereas a client normally creates a session EJB and removes it after use, clients normally look up an existing entity EJB. Creation of an entity EJB corresponds to adding new data items to the application (e.g., adding rows to database tables). An important feature of entity EJBs is that they have identity—that is, one can be distinguished from another. This is implemented by assigning a primary key to each instance of the EJB, where ‘primary key’ has the same meaning as it does for database management. Primary keys that identify EJBs can be of any type, including programmer- defined classes. 3. Message-driven EJBs A message-driven bean acts as a consumer of asynchronous messages: It cannot be called directly by clients, but is activated by the container when a message arrives. Clients interact with these EJBs by sending messages to the queues or topics to which they are listening. Although a message-driven EJB cannot be called directly by clients, it can call other EJBs itself. Messagedriven EJBs are the only type that does not follow a strict request-response interaction with clients. Q.3 What is facelet ? what are its features? Ans: Features:  Server-side helper classes, such as database access beans  A custom tag library for rendering UI components on a page  A custom tag library for representing event handlers, validators , and other actions
  • 3.  UI components represented as stateful objects on the server  Backing beans, which define properties and functions for UI components  Validators, converters, event listeners, and event handlers  An application configuration resource file for configuring application resources Q.4 Explain the life cycle of JSF Ans: Phase 1: Restore view  JSF begins the restore view phase as soon as a link or a button is clicked and JSF receives a request.  During this phase, the JSF builds the view, wires event handlers and validators to UI components and saves the view in the FacesContext instance. The FacesContext instance will now contains all the information required to process a request. Phase 2: Apply request values  After the component tree is created/restored, each component in component tree uses decode method to extract its new value from the request parameters. Component stores this value. If the conversion fails, an error message is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any validation errors.  If any decode methods / event listeners called renderResponse on the current FacesContext instance, the JSF moves to the render response phase. Phase 3: Process validation  During this phase, the JSF processes all validators registered on component tree. It examines the component attribute rules for the validation and compares these rules to the local value stored for the component.
  • 4.  If the local value is invalid, the JSF adds an error message to the FacesContext instance, and the life cycle advances to the render response phase and display the same page again with the error message. Phase 4: Update model values  After the JSF checks that the data is valid, it walks over the component tree and set the corresponding server-side object properties to the components' local values. The JSF will update the bean properties corresponding to input component's value attribute.  If any updateModels methods called renderResponse on the current FacesContext instance, the JSF moves to the render response phase. Phase 5: Invoke application  During this phase, the JSF handles any application-level events, such as submitting a form / linking to another page. Phase 6: Render response  During this phase, the JSF asks container/application server to render the page if the application is using JSP pages. For initial request, the components represented on the page will be added to the component tree as the JSP container executes the page. If this is not an initial request, the component tree is already built so components need not to be added again. In either case, the components will render themselves as the JSP container/Application server traverses the tags in the page.  After the content of the view is rendered, the response state is saved so that subsequent requests can access it and it is available to the restore view phase. Q.5 How does JSF application gets executed ? Explain Ans: The hello example JSF application goes through the following stages when it is deployed on the GlassFish Server. 1. When the hello application is built and deployed on the GlassFish Server, the application is in an uninitiated state. 2. When a client makes an initial request for the beanhello.xhtml web page, the hello Facelets application is compiled. 3. The compiled Facelets application is executed, and a new component tree is constructed for the hello application and is placed in ajavax.faces.context.FacesContext. 4. The component tree is populated with the component and the managed bean property associated with it, represented by the EL expression hello.world. 5. A new view is built, based on the component tree. 6. The view is rendered to the requesting client as a response. 7. The component tree is destroyed automatically. 8. On subsequent (postback) requests, the component tree is rebuilt, and the saved state is applied. Q.6 Write a session bean code specification that calculates compound interest. Assume principal,
  • 5. terms and rate of interest is entered by the user and the input is passed through a servlet Ans: Clacjsp.jsp: // jsp web page created <form action="calcservlet" method="post"> Principal: <input type="text" name="t1"/> Rate: <input type="text" name="t2"/> No_of_years: <input type="text" name="t3"/> <input type="submit" name="submit"/> </form> Calcservlet.java: // servlet file created package mybean; import java.io.IOException; import java.io.PrintWriter; import javax.ejb.EJB; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class calcservlet extends HttpServlet { @EJB private simpleLocal simple; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet calcservlet</title>"); out.println("</head>"); out.println("<body>"); Double a=Double.parseDouble(request.getParameter("t1")); Double b=Double.parseDouble(request.getParameter("t2")); Double c=Double.parseDouble(request.getParameter("t3")); out.println("<h1>Simple Interest = " + simple.calcsimple(a, b, c)+ "</h1>"); out.println("</body>"); out.println("</html>"); } } } Simple.java : // bean created
  • 6. package mybean; import javax.ejb.Stateless; import java.util.Scanner; @Stateless public class simple implements simpleLocal { @Override public Double calccomp(double a, double b, double c) { double ci=a*Math.pow((1+b/100),c); return ci; } } Q.7. Write the benefits of using EJB Ans: For several reasons, enterprise beans simplify the development of large, distributed applications.  because the EJB container provides system-level services to enterprise beans, the bean developer can concentrate on solving business problems. The EJB container, rather than the bean developer, is responsible for system-level services, such as transaction management and security authorization.  because the beans rather than the clients contain the application’s business logic, the client developer can focus on the presentation of the client. The client developer does not have to code the routines that implement business rules or access databases. As a result, the clients are thinner, a benefit that is particularly important for clients that run on small devices.  because enterprise beans are portable components, the application assembler can build new applications from existing beans. Provided that they use the standard APIs, these applications can run on any compliant Java EE server. Q.8 Create a JSF application for checking the validity of the user Ans: Example: <%@ page contentType="text/html"%> <%@ tagliburi="http://java.sun.com/jsf/core" prefix="f"%> <%@ tagliburi="http://java.sun.com/jsf/html" prefix="h"%> <f:view> <html> <head><title>JSF Login Application</title></head> <body> <h:form> <h:panelGroup rendered="#{login.validationComplete and (!login.isUsernameValid or !login.isPasswordValid)}"> <h:outputText value="Username is a Required Field" rendered="#{!login.isUsernameValid}" style="color:red"></h:outputText> <br> <h:outputText value="Password is a Required Field" rendered="#{!login.isPasswordValid}" style="color:red"></h:outputText>
  • 7. </h:panelGroup> <h:panelGroup rendered="#{login.validationComplete and (login.isUsernameValid and login.isPasswordValid)}"> <h:outputText value="Username & Password are valid" style="color:green"></h:outputText> </h:panelGroup> <table> <tr> <td><h:outputText value="Enter Username: " /></td> <td><h:inputText id="username" value="#{login.username}" /> </td> </tr> <tr> <td><h:outputText value="Enter Password: " /></td> <td><h:inputSecret id="password" value="#{login.password}" /> </td> </tr> <tr> <td> </td> <td><h:commandButton value="Login" action="#{login.checkValidity}"/> </td> </tr> </table> </h:form> </body> </html> </f:view> 1. <%@ tagliburi="http://java.sun.com/jsf/core" prefix="f"%> <%@ tagliburi="http://java.sun.com/jsf/html" prefix="h"%>
  • 8. This line links to the jsf core and jsf html tag libraries. The jsf html tag library carries regular html components like text box, buttons, etc. 2. <f:view></f:view> This tag at the beginning of the document acts as a container for all the components enclosed between them. 3. <h:panelGroup rendered="#{login.validationComplete and (!login.isUsernameValid or !login.isPasswordValid)}"> <h:outputText value="Username is a Required Field" rendered="#{!login.isUsernameValid}" style="color:red"></h:outputText> <br> <h:outputText value="Password is a Required Field" rendered="#{!login.isPasswordValid}" style="color:red"></h:outputText> </h:panelGroup> The above code snippet is intended to display error and success messages. The first part displays the error messages one after the other. The second part displays a single success message. This code uses Expression Language (EL) to do conditional checks and reference the managed bean values. 4. <h:panelGroup rendered="#{login.validationComplete and (login.isUsernameValid and login.isPasswordValid)}"> <h:outputText value="Username & Password are valid" style="color:green"></h:outputText> </h:panelGroup> The following line in the above code snippet checks to see if the validation failed before displaying the error messages Q.9 Explain with suitable example <navigation-rule> element of faces-config.xml file of JSF Ans:  Navigation between different pages of a Java Server Faces application, such as choosing the next page to be displayed after a button or hyperlink component is clicked, is defined by a set of rules.  Navigation rules can be implicit, or they can be explicitly defined in the application configuration resource file.  These navigation rules are defined in JSF configuration files along with other definitions for a JSF application. Usually, this file is named faces-config.xml. Here is a navigation rule that could be used with the example just described: <navigation-rule> <from-view-id>/login.xhtml</from-view-id>
  • 9. <navigation-case> <from-action>#{LoginForm.login}</from-action> <from-outcome>success</from-outcome> <to-view-id>/storefront.xhtml</to-view-id> </navigation-case> <navigation-case> <from-action>#{LoginForm.logon}</from-action> <from-outcome>failure</from-outcome> <to-view-id>/logon.xhtml</to-view-id> </navigation-case> </navigation-rule> This navigation rule defines the possible ways to navigate from login.xhtml. Each navigation- case element defines one possible navigation path fromlogin.xhtml. The first navigation- case says that if LoginForm.login returns an outcome of success, then storefront.xhtml will be accessed. The second navigation-case says that login.xhtml will be re-rendered if LoginForm.login returns failure.