Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Re: Java Bean

 
Joe Cheung
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I am new to Java. I want to ask what is the difference between Java Bean and the ordinary Java Classes?
Regards,
Joe
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only requirement that an ordinary java class be considered a bean is that it must have a public default constructor and use getters and setters to access its public properties. Properties can be read-only, write-only and read-write. So if you have a read-write int property named age then you must have methods public int getAge() and public void setAge(int age) For a boolean instead of prefixxing with get you can use is instead for example public boolean isLogged().
Also you can have indexed properties which are simply arrays using getters and setters. Finally you can fire property changes for interested listeners whenever a bean's property changes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic