File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes encapsulate data easy question.. begginer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "encapsulate data easy question.. begginer " Watch "encapsulate data easy question.. begginer " New topic

encapsulate data easy question.. begginer

slav agui

Joined: Jan 15, 2008
Posts: 4
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

Joined: Sep 29, 2008
Posts: 12617

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.
I agree. Here's the link:
subject: encapsulate data easy question.. begginer
It's not a secret anymore!