wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Difference JavaBeans and Java Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference JavaBeans and Java Class" Watch "Difference JavaBeans and Java Class" New topic
Author

Difference JavaBeans and Java Class

Saurabh Saha
Ranch Hand

Joined: Dec 08, 2004
Posts: 52
Hi,
Please tell me what is the difference between javabeans and simple java class.

Thanks,
Vivek
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
JavaBean is simple Java class, but implements Serializable and has getters and setters for its properties.

Correct me, if I'm wrong.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

They only need to implement serializable if they are going to be serialized.
It's a good idea to do so if these beans are going to be stored in session.
Your sessions can't be saved across server restarts or shared in a cluster otherwise.

You should also have a zero argument constructor. (I think, technically, this is not part of the bean spec but a lot of applications require it.)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65

Not JSP-specific so moving along to Java in General(beginner).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Java beans are also Java classes, but they can be considered as reusable component, which by itself is not a complete program but are used in programs. Ideally,
1. they should have no-args constructor (so that they can be instantiated at runtime by say, Class.forName(..) )
2. They should have getter and setter methods to access their attributes
3. They support introspection if required. They can use the classes provided in java.beans package for that.
4. They can support bound and constraint properties.
5. They should support serialization if the state of the java bean needs to be persistance
An Ideal GUI Java Bean can be loaded in any IDE like JBuilder,Eclipse and used just like any Swing component. Infact java swing components are Java Beans.
[ February 15, 2005: Message edited by: Tanveer Rameez ]

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference JavaBeans and Java Class
 
Similar Threads
What is the difference between DTO and Bean?
EJB
EJB versus JavaBean
Handling dynamic configuration data
When is it good to make an class a bean?