• Post Reply Bookmark Topic Watch Topic
  • New Topic

javaBeans vs regular objects  RSS feed

 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Could someone explain any benefits to using javabeans over normal class objects. I would have thought the normal objects would be more flexible. I realise that you can use ides to develop beans and that it makes it easier to identifier the names of methods to get and set fields in beans but other than that i cant see any advantages, am I missing something here?

Thanks
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First lets make sure were ont he same page... I assume you're refering to just regular beans not enterprise beans.
A bean is just a class file, there is no special extension and no special class or interface to extend or implement, and nothing extra to do to compile it. The biggest difference is that you need to follow the naming convention of the getter and setter methods in the class. With that said a bean can be just as flexible as a regular class and as an added advantage, make it easier to work with JSPs.
The best examples are the get and set property methods you can use in a JSP. Instead of having to specifically call a method to get or set a variable in a class you simply use one of the JSP tags to do it. Even more powerfull is the
<jsp:setProperty name=�beanID� propery=�*� />
tag. This will set all of the corresponding variables in the bean to the correspondingly named parameters submitted on a form. Try that with a normal class
hope that helps
 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave thanks for the answer (and the excellent tip)
So the advantage in using beans is the flexibility in JSP page?
Thanks again
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A majos advantage is also it's reusability. Beans can be used in servlets, normal classes, and not only JSP pages. JSP tags make using beans and setting/getting their properties very easy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!