Java Beans Explained in Detail
Java Beans Explained in Detail
4. Start the BeanBox, & using load jar option load mybean.jar file.
5. Toolbox now contains an additional entry mybean.
JavaBean Specification guidelines1. A zero argument constructor must be provided for the bean class.
2. The constructor must not throw Exceptions.
3. Every property must have either setter or getter methods, with unique
name.
4. A bean must support persistence, i.e it must be serializable. The data
members, which do not need to be serialized, must be marked as
transient.
JAR (Java Archive Files)
- JAR file allows you to efficiently deploy a set of classes & their
associated resources
The utility is capable of packaging and storing files in compressed
format.
- The packaging is useful for java Applets & Beans to locate & load the
resource files as & when required.
- Its browser independent archive file format.
- Capable of storing audio & image files as well as class files.
The jar program is executed from command linejar {ctx} {vfm0M} {jarFile} {manifestfile} file1 file2 file3
[ The file1 are the name of class files. ]
Options arec
t
x
v
f
m
0 (Zero)
M
- They are data objects i.e. java objects that cache database information.
Ex.- a product, an order, an employee etc.
- These beans are transactional & survive from server crashes.
3. Message Driven beans- Same like session beans.
- You can call message-driven beans only by sending messages to those
beans.
Difference between EJB and Java Beans.
JavaBeans
----------------Basically used to CUSTOMIZE EXISTING OBJECTS. i.e. You can create USER
OBJECTS, which are based on existing objects.
Ex.: A default button operates as a Single-State Switch. i.e. when you press a
button on a web page, it doesn't remain pressed. Infact, it immediately bounces
back to its OFF state like a Door-Bell. Now, let's say, you need a button, which
should have 2 stable
states, like the typical Electrical Light Switch. So, in this case, what you can do is,
take an existing button (having 1 stable state) and CUSTOMIZE it so that it has 2
stable states. This is possible using JavaBeans.
Java Bean is a software component written in the Java programming
language that conforms to the JavaBeans component specification. The
JavaBeans APIs became part of the "core" Java APIs as of the 1.1 release of the
JDK.
The JavaBeans specification defines a Java-based software component
model that adds a number of features to the Java programming language. Some
of these features include: introspection , customization , events , properties ,
persistence
Enterprise Java Beans (EJB)
--------------------------EJB is a completely different concept than the one mentioned above. It is NOT
used to customize existing objects. Instead they are basically used to
STANDARDIZE the way, in which business logic is written.
Ex.: We can write our business logic as well as the GUI logic, inside
Servlets/Applets/StandAlone applications itself. But this way, there will be no
clear distinction between the Code that is responsible for the GUI and the actual
Business logic code, because everything is written inside the same class file.
So, to COMPONENTIZE we write business logic in separate class files
than the GUI logic, thereby making a clear distinction between the
responsibilities.
Enterprise JavaBeans (EJBs) are Java-based software components that
are built to comply with Java's EJB specification and run inside of an EJB
Entity Bean
The life of the session bean is limited to An entity bean persists as long as the
the life of its client.
data exists in the database.
Session beans can be transaction
aware.
EJB Architecture
EJB Server
EJB
Home
Client
EJB
Object
Container
Existing
System
s
EJB
Component
Database
EJB Server
The EJB Server is a collection of services for supporting an EJB installation
These services include management of distributed transactions, management
of distributed objects and distributed invocations on these objects, and low-level
system services
EJB Container
A container is a home for EJB components. EJB components live in a
container just as a record lives in a database
The container handles the EJBean lifecycle, including creating and destroying
an object
It provides a scalable, secure, transactional environment in which EJBeans can
operate
It handles state management of EJBeans
Container
The container provides an implementation of the EJBHome interface and an
implementation of the EJBObject remote interface
The container is also responsible for making the EJBHome interface available in
JNDI
EJB types
Session Beans
represent a transient conversation with a client and may or may not execute
database reads and writes
a session can be brief (as in a whois lookup) or can last a long time (as in a
large ftp download)
may invoke JDBC calls directly or may use Entity Beans to make the calls
acting as a client to the Entity Bean