• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javabeans  RSS feed

 
Christopher Au
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question which has been bugging me for a while. If I have javabean example

savingsbankaccount

the properties I have are accountnumber, balance, accountname, address etc

I what I would like to know is besides the regular getters and setters for the properties.

Can I add other methods, an example method is that I may need to calculate the interest rate based on a couple of properties and I only want to calculate this value only on request because not everyone may want it. This is just a hypothetical method.

Thanks

lasher
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Chris, welcome to JavaRanch.

Please check your private messages. You can see them by clicking "My Profile" at the top right of the page.
 
Christopher Au
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi have changed my display name however it does not seem to be reflected.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see your new name, "Chris Stries". Thank you for changing it. Sometimes pages are cached somewhere in JavaRanch's forum software and you don't immediately see that it's changed.

To answer your question: You can add any other methods to a JavaBean as you like. JavaBeans are just regular Java classes that follow a specific pattern (mainly, getter and setter methods). But nothing stops you from adding other methods to your class, and it will still work with other pieces of software that expect your class to behave like a JavaBean.

See JavaBean on Wikipedia; it lists the conventions that a class must follow in order to be used as a JavaBean.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!