CSM-15 Lecture 2 2
CSM-15 Lecture 2 2
Software Engineering
Introduction to Java Beans
Paul Krause
and
Sotiris Moschoyiannis
Java Beans
Contents
Definition
Bean Basics
What is a Java Bean?
“A Java Bean is a reusable software
component that can be manipulated
visually in a builder tool”
JavaSoft
Sources of Builder Tools
NetBeans:
http://www.netbeans.org
JBuilder:
http://www.borland.com/jbuilder/
Locate a component at run-time and
determine its supported interfaces
Registration process for a component to make
itself and its interfaces known
Beans (or JavaBeans components) use
events to communicate with other Beans
A Bean that wants to receive events (a
listener Bean) registers its interest with the
Bean that triggers the event (a source Bean)
The Component Model
Persistence
Persistence enables Beans to save and
restore their state
JavaBeans uses Java Object Serialization to
support persistence
The Component Model
Visual Presentation
The Bean is free to choose its own visual
presentation (fonts, colours, shape, etc)
Many of these characteristics will be
properties of the Bean (some might be
persistent too)
The Component Model
Support of Visual Programming
User can select a component from the
toolbox and place it into a container
Properties of the component can then be
edited to create the desired behaviour
Bean’s Properties
Properties are a Bean’s appearance and
behaviour characteristics that can be
changed at design time
It is not necessary for a Bean to be visible at
run-time (e.g. Bean controlling access to a
device or data feed)
It is necessary however for a Bean to support
the visual builder tool. Even an ‘invisible’ run-
time Bean shall be shown on the builder tool
Further Features
Multithreading
Always assume your code will be used in a
multithreaded environment
Make sure that your Beans are thread-safe
Multithreading in JavaBeans is no different
than multithreading in Java
Further Features
Security
By default assume that your Beans are
running in a non-trusted applet
Apply security restrictions such as
• Allow no access to the local file system
• Limit socket connections to the host system
Summary
Beans build on Java features that already
exist
We add a Builder Tool
We use design patterns
We record information about the Classes
that implement Beans