Вы находитесь на странице: 1из 4

What is J2EE/JAVA EE standard ??

Java EE is a specification. As with other Java Community Process specifications, providers must
meet certain conformance requirements in order to declare their products as Java EE compliant.
Java EE includes several API specifications, such as RMI, e-mail, JMS, web services, XML, etc.,
and defines how to coordinate them. Java EE also features some specifications unique to Java
EE for components. These include Enterprise JavaBeans, connectors, servlets, JavaServer
Pages and several web service technologies. This allows developers to create enterprise
applications that are portable and scalable, and that integrate with legacy technologies. A Java
EE application server can handle transactions, security, scalability, concurrency and
management of the components it is deploying, in order to enable developers to concentrate
more on the business logic of the components rather than on infrastructure and integration tasks.

What is EJB???
EJB (Enterprise Java Beans) is a server-side model
that encapsulates the business logic of an application.
That is why we deploy all the EJBs in deploy folder in JBOSS
application server.

Advantages of EJB ??
For several reasons, enterprise beans simplify the development of large,
distributed applications. First, 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.

When to Use Enterprise Beans


You should consider using enterprise beans if your application has any
of the following requirements.

The application must be scalable. To accommodate a growing


number of users, you may need to distribute an applications

components across multiple machines. Not only can the enterprise


beans of an application run on different machines, but also their
location will remain transparent to the clients.
Transactions must ensure data integrity. Enterprise beans support
transactions, the mechanisms that manage the concurrent access
of shared objects.
The application will have a variety of clients. With only a few lines of
code, remote clients can easily locate enterprise beans. These
clients can be thin, various, and numerous.

Types of EJBs in JAVA


1) Stateful Session Bean
The state of an object consists of the values of its instance variables. In
a stateful session bean, the instance variables represent the state of a
unique client/bean session. Because the client interacts (talks) with its
bean, this state is often called the conversational state
For stateless session beans the server can maintain a variable amount of instances in a pool.
Each time a client requests such a stateless bean (e.g. through a method) a random instance is
chosen to serve that request. That means if the client does two subsequent requests it is
possible that two different instances of the stateless bean serve the requests. In fact there is no
conversational state between the two requests. Also if the client disappears, the stateless bean
does not get destroyed and can serve the next request from another client.

2) Stateless Session Bean


A stateless session bean does not maintain a conversational state with
the client. When a client invokes the methods of a stateless bean, the
beans instance variables may contain a state specific to that client but
only for the duration of the invocation. When the method is finished, the
client-specific state should not be retained.
On the other hand a stateful session bean is closely connected to the client. Each instance is
created and bounded to a single client and serves only requests from that particular client. So
happens that if you do two subsequent requests on a stateful bean, your request will be served
always from the same instance of the bean. That means you can maintain a conversational state
between the requests. If the clients disappears the bean get destroyed too.

Annotation used with Beans:@ Stateless is used to specify component-defining annotation for a
stateless session bean.
So when to use stateless or stateful?
That mainly depends on whether you want to maintain the conversational state. For example if
you have a method that adds up to numbers and return the result you use a stateless bean
because its a one time operation. If you call this method a second time with other numbers you
are not interested in the result of the previous addition anymore.
But if you want for example count the number of requests a client has done, you have to use a
stateful bean. In this scenario it is important to know how often the client has requested the bean
method before, so you have to maintain conversational state in the bean (e.g. with a variable). If
you would use a stateless bean here the request of the client would be served each time from a
different bean what messes up your results.

3) Entity Bean
Entity beans are objects, and they can be designed using objectoriented principles and used in applications as objects. The data in these
entity bean objects are persisted in some data store, usually relational
databases.
Annotation used with Entities:@Table annotation is used to specify the table to persist the data.
@Column is used to specify a mapped column for a persistent property
or field.
@Id is used to specify the primary key of an entity.
JBOSS Application server
JBOSS internally uses Hibernate as its ORM tool. Hibernate's primary
feature is mapping from Java classes to database tables (and from Java
data types to SQL data types). Hibernate also provides data query and
retrieval facilities. It generates SQL calls and relieves the developer from
manual result set handling and object conversion. Applications using
Hibernate are portable to supported SQL databases with little
performance overhead.

What is EAR and why it is used??


An EAR file is basically a zip file with a .ear extension, with one or more entries representing the
modules of the application, and a metadata directory called META-INF which contains one or
more deployment descriptors. EAR (Enterprise ARchive) is a file format used by Java EE for
packaging one or more modules such as JAR,WAR into a single archive so that the deployment
of the various modules onto an application server happens simultaneously and coherently.
The META-INF directory contains application.xml deployment descriptor, known as
the Java EE Deployment Descriptor. It contains the following XML entities:

display-name , which identifies the application

description

A module element for each module in the archive

Each module element contains an ejb , web or java element which describes the individual
modules within the application.

Вам также может понравиться