Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

encapsulate data easy question.. begginer

slav agui
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to undertand how encapsulate data works.
I have:
TestEncapsulate userdata = new TestEncapsulate (
) ;
was working, good. But another programmer told me that was missing:
userdata.setlast(request.getParameter("last") );
So I added (and is working too!). He told me to keep it because is necessary.
I do not undertand why do I need to do the second section if in the first section I put the values, isn't it?.
Some body can explain me this, please?
David Newton
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure how this is a Struts question.

I suspect the issue the other programmer was talking about is that the JavaBean specification requires getters and setters for bean properties.

Having a constructor that fills all the values is okay, but it's also good practice (and required in many circumstances) to have a default constructor that takes no values, and getters/setters that allow setting and retrieving the bean properties.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!