• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a bean class have public instance variables ??  RSS feed

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have read that for a java class to qualify as a Java Bean there are 3 requirements
1. Bean class must have a zero-argument (empty) constructor.
2. Bean class should have no public instance variables (fields).
3. Persistent values should be accessed through methods called getXxx and setXxx.
I created a similar bean class and used in my JSP using the
<jsp: useBean... />. This works fine.
Now i violated the rule 2 by using public instance variables. Still my JSP works fine. I expected it to give me an error. Y does this happen so?
Arent the 3 requirements given above not so rigid when used in Jsps?
Regards,
Sajee
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you expect an error? What you have done is poor programming practice, not a language error. Just because you can do something, doesn't mean you should.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!