• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Difference JavaBeans and Java Class

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please tell me what is the difference between javabeans and simple java class.

Thanks,
Vivek
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaBean is simple Java class, but implements Serializable and has getters and setters for its properties.

Correct me, if I'm wrong.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not JSP-specific so moving along to Java in General(beginner).
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
I was born with webbed fish toes. This tiny ad is my only friend:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic