views:

439

answers:

4

The name really throws me off. I'm hoping someone can explain it in a way I won't forget :)

+3  A: 
Jonathan Sampson
+1 for the picture :P
Prasoon Saurav
-1 for quoting Wikipedia directly.
Esko
Esko, when the question is this simple, I don't see the harm in quoting Wikipedia.
Jonathan Sampson
+1  A: 

A java bean is a class that is serializable, has a no-argument constructor, and uses getters and setter methods for its member fields. Its used in Java Enterprise Apps to store business logic data.

controlfreak123
+6  A: 

Any serializable java class (implementing java.io.Serializable) that follows specific conventions: a no-argument constructor, and properties accessible via get/set/is accessors.

The idea is to make it predictable, so that properties etc can be discovered automatically through reflection - of great help in tool and framework development.

Marc Paradise
Beans do not constitute very elegant OO-design since it is essentially a data structure without any behavior, and it completely exposes its innards. See domain-driven design: http://en.wikipedia.org/wiki/Domain-driven_design and http://domaindrivendesign.org/resources/what_is_dddThat said, most designs rely on bean-like classes to represent their model so it is the de-facto standard way of approaching this.
Adriaan Koster
+1  A: 

Sun's JavaBean Tutorial says...

The JavaBeans™ architecture is based on a component model which enables developers to >create software units called components. Components are self-contained, reusable software units that can be visually assembled into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as beans.

A set of APIs describes a component model for a particular language. The JavaBeans API specificationdescribes the core detailed elaboration for the JavaBeans component architecture.

Beans are dynamic in that they can be changed or customized. Through the design mode of a builder tool you can use the Properties window of the bean to customize the bean and then save (persist) your beans using visual manipulation. You can select a bean from the toolbox, drop it into a form, modify its appearance and behavior, define its interaction with other beans, and combine it and other beans into an applet, application, or a new bean.

If you've used Swing's 'button', then you've used a component (visible JavaBean). You can use developers tools (like NetbeansIDE) to change the Bean's available 'properties'. Netbeans uses something called 'introspection' to discover which JavaBean properties can be modified by the coder/user (e.g. name, text-title and alignment for a Swing Button JavaBean component). You can save its state too (the IDE/Beans developer might use 'serialization' to do this) allowing re-use with your favourite settings another time.

JavaBeans don't need to be visible (like a swing component). You could create your own JavaBean to encrypt text in a textbox when someone clicks an 'OK' button on a form. You don't see your custom written JavaBean, but some other developer could re-use your 'encryption' JavaBean in their code with some 'property' changes that you allowed to be public (i.e. encryption-type="blowfish").

Regards, SteJav

SteJav