Friday 8 January 2016

Enterprise Beans in JAVA

What is Enterprise Beans
A Java EE component is called an Enterprise Beans which implements the EJB technology and runs inside an EJB container. Enterprise Beans are the server side component where the application's business logic is encapsulated. The business logic can be explained as, it is line of statement called code which is written for completing the requirements of application.
What is EJB Container
EJB container is a specification within the Application Server that runs the Enterprise Beans. Services provided by the EJB container is System-level services. In such type of services it provides the transaction and security to its enterprise beans. In addition they also provides for the Resource and life cycle management, remote accessibility, concurrency control, collision etc.
Benefits of Enterprise Beans
Generally, Enterprise beans is used for creating large, distributed applications. This is because of various reasons these are as follows :
  • The first reason is the services that are provided by the EJB container to enterprise beans i.e. System-level services that helps the developer to focus on solving the business problems.
  • The second reason is elaborated from first reason that the bean is responsible for application's business logic not for the client. So, a client developer can focus on only its presentation.
  • The third reason is enterprise bean's portability feature i.e. the enterprise beans components can be easily or conveniently portable.

When use Enterprise Java Bean?
  1. Application needs Remote Access. In other words, it is distributed.
  2. Application needs to be scalable. EJB applications supports load balancing, clustering and fail-over.
  3. Application needs encapsulated business logic. EJB application is separated from presentation and persistent layer.



Types of Enterprise Java Bean
There are 3 types of enterprise bean in java.
Session Bean
Session bean contains business logic that can be invoked by local, remote or webservice client.
Message Driven Bean
Like Session Bean, it contains the business logic but it is invoked by passing message.
Entity Bean
It encapsulates the state that can be persisted in the database. It is deprecated. Now, it is replaced with JPA (Java Persistent API).

Session Bean
 These types of beans directly interact with the client and contains business logic of the business application.
Session bean encapsulates business logic only, it can be invoked by local, remote and webservice client.
It can be used for calculations, database access etc.
The life cycle of session bean is maintained by the application server (EJB Container).
Types of Session Bean
There are 3 types of session bean.
1) Stateless Session Bean: It doesn't maintain state of a client between multiple method calls.
2) Stateful Session Bean: It maintains state of a client across multiple requests.
3) Singleton Session Bean: One instance per application, it is shared between clients and supports concurrent access.

Stateless Session Bean
Stateless Session bean is a business object that represents business logic only. It doesn't have state (data).
In other words, conversational state between multiple method calls is not maintained by the container in case of stateless session bean.
The stateless bean objects are pooled by the EJB container to service the request on demand.
It can be accessed by one client at a time. In case of concurrent access, EJB container routes each request to different instance.
Stateful Session Bean
Stateful Session bean is a business object that represents business logic like stateless session bean. But, it maintains state (data).
In other words, conversational state between multiple method calls is maintained by the container in stateful session bean.
Message-Driven Bean :
 Message-Driven Bean permits the Java Enterprise Edition applications for processing messages asynchronously. Message-Driven beans likewise the JMS message listener, that receives the JMS messages rather than events.

Disadvantages of EJB
  1. Requires application server
  2. Requires only java client. For other language client, you need to go for webservice.
  3. Complex to understand and develop ejb applications.


what is mean by JSF -JAVA

What is JSF?
  Java Server Faces
JSF technology is a framework for developing, building server side User Interface Components and using them in a web application.JSF technology is based on the Model View Controller (MVC) architecture for separating logic from presentation.
What is MVC Design Pattern?
MVC design pattern designs an application using three separate modules:
Module
Description
Model
Carries Data and login
View
Shows User Interface
Controller
Handles processing of an application.

Purpose of MVC design pattern is to separate model and presentation to enable developers to set focus on their core skills and collaborate more clearly.
Web Designers have to concentrate only on view layer rather than model and controller layer. Developers can change the code for model and typically need not to change view layer. Controllers are used to process user actions. In this process layer model and views may be changed.
Benefits Of JSF
JSF has various benefits these are as :
  • The  MVC architecture facilitate to separate the behavior from presentation.
  • JSF provides the facility to link the separate pieces of the development process to a single piece by offering a simple programming model.
  • JSF provides the built-in support of Ajax, bookmarking, and page-load actions.
  • Provides more security.
  • Reusability of codes.
JSF Integration
JSF can be integrated with other frameworks like, Spring, JDBC etc. 
Basic JSF Tags
JSF provides a standard HTML tag library. These tags get rendered into corresponding html output.
For these tags you need to use the following namespaces of URI in html node.
<html
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html"
> 
Following are important Basic Tags in JSF 2.0:
S.N.
Tag & Description
1
h:inputText
Renders a HTML input of type="text", text box.
2
h:inputSecret
Renders a HTML input of type="password", text box.
3
h:inputTextarea
Renders a HTML textarea field.
4
h:inputHidden
Renders a HTML input of type="hidden".
5
h:selectBooleanCheckbox
Renders a single HTML check box.
6
h:selectManyCheckbox
Renders a group of HTML check boxes.
7
h:selectOneRadio
Renders a single HTML radio button.
8
h:selectOneListbox
Renders a HTML single list box.
9
h:selectManyListbox
Renders a HTML multiple list box.
10
h:selectOneMenu
Renders a HTML combo box.
11
h:outputText
Renders a HTML text.
12
h:outputFormat
Renders a HTML text. It accepts parameters.
13
h:commandButton
Renders a HTML input of type="submit" button.
14
h:Link
Renders a HTML anchor.