• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Normal Java Class and Java Bean

 
Vasu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls tell me about Java Bean and Java Class
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JavaBean is just a normal Java class that conforms to a number of conventions:

- it should have a public default constructor (i.e. a constructor that takes no arguments)
- it should be serializable
- it has getter and setter methods to get and set its properties

See: http://en.wikipedia.org/wiki/JavaBean

(Note, an EJB (Enterprise Java Bean) is something entirely different from a normal JavaBean).
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Side note: when you remove the implements Serializable clause, then the JavaBean as described at Wikipedia behaves as an ordinary DTO (Data Transfer Object).

An JavaBean is more than just a data wrapper, you can implement action methods in it to play with the data in it.
[ October 10, 2006: Message edited by: B L Scholtz ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also more in the JavaBeans specification: properties can be observable, you can create descriptors for beans etc. pp. Most of that is optional, though.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who's so kind to update this Wikipedia article?

By the way, I just found this at sun.com:
What Distinguishes JavaBeans from Java Classes?

Any Java class that adheres to certain conventions regarding property and event interface definitions can be a JavaBean. Beans are Java classes that can be manipulated in a visual builder tool and composed into applications.

Introspection, the process by which a builder tool analyzes how a Bean works, differentiates Beans from typical Java classes. Because Beans are coded with predefined patterns for their method signatures and class definitions, tools that recognize these patterns can "look inside" a Bean and determine its properties and behavior.

Introspection allows a Bean's state to be manipulated at design time�that is, at the time it is being assembled as a part within a larger application. For this to work, method signatures within Beans must follow a certain pattern so that introspection tools recognize how Beans can be manipulated, both at design time and at run time.

In effect, Beans publish their attributes and behaviors through special method signature patterns that are recognized by beans-aware application construction tools. However, these construction tools are not required to build or test your beans. The pattern signatures are easily recognized by human readers, as well as builder tools. One of the first things you'll learn when building beans is how to recognize and construct methods that adhere to these patterns.

Beans should not be used indiscriminately. Beans are best suited to software components intended to be visually manipulated within builder tools. Some functionality, such as the JDBC API, is still best provided through a programmatic or textual interface, rather than a visual manipulation interface.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic