Java Beans
Java Beans
JAVA BEANS
REUSABLE SOFTWARE COMPONENTS IN JAVA
SHRUTI MITTAL
JCBUST, YMCA
2
JAVA BEANS
JavaBeans are reusable software components written in Java that follow a
specific set of conventions
Key Characteristics of JavaBeans:
• Serializable – Implements java.io.Serializable so the bean’s state can be saved
and restored.
• No-argument Constructor – Has a public default (no-argument) constructor.
• Getter and Setter Methods – Uses standard naming conventions for methods
to access properties:
• getPropertyName() to retrieve a value
• setPropertyName() to set a value
3
Design Pattern Follows the JavaBean conventions Can follow any design pattern
PROPERTIES IN JAVABEANS 6
BEAN BUILDER
BDK INTROSPECTION
BDK (bean development kit) was a toolkit provided by sun microsystems to help developers create, test,
and visualize java beans. One of its core strengths is its support for introspection, which is the process of
analyzing a bean’s properties, events, and methods at runtime.
Introspection is the ability of a JavaBean to be examined BDK uses the java.beans.Introspector class
by builder tools or other code to determine: from the JavaBeans API to:
•What properties it has (like name, age) 1.Analyze class structure based on
•What events it can fire (like ActionEvent) standard naming (get/set/is)
•What methods it exposes (like getName(), setName()) 2.Extract metadata like:
It allows tools like BeanBox (part of BDK) to •Property descriptors (get/set
automatically discover and display bean information. methods)
•Method descriptors (public methods)
•Event set descriptors (event listeners)
10
BEANINFO INTERFACE
WHAT IS EJB?
• Enterprise JavaBeans (EJB) is a server-side component architecture for building modular, scalable,
transactional, and secure enterprise-level applications in Java.
• Developed as part of Java EE (now Jakarta EE), EJB simplifies the development of large, distributed
systems.
• Key features of EJB
Feature Description
Component-based EJB modules are reusable and independent
Security Declarative and programmatic security
Transaction Mgmt Built-in support for distributed transactions
Remote Access Supports remote method invocation (RMI/IIOP)
Lifecycle Mgmt Managed entirely by the EJB container
12
EJB ARCHITECTURE
13
TYPES OF EJBS
Session Beans Handle business logic; short-lived
Type Use Case
Stateless Login/authentication, single transactions
Stateful Shopping cart, session tracking
Singleton Caching, logging (shared app-wide)