| Author |
Difference between attributes and parameters
|
Ravi kapa
Ranch Hand
Joined: Jan 05, 2012
Posts: 76
|
|
|
hi,What is the difference between attributes and parameters???give any good example so that i can understand clearly please......
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
For me, parameters are passed to a method and attributes store the parameters and act like local variables inside a method.
In the above sample name is the attribute and "Ravi" is the parameter.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Not convinced. “Attribute” is not a standard word in Java™ jargon. The nearest I can think is that you are talking about the attributes of an object, which means the values of its fields. But some people would use it with a wider meaning, including behavioiur (its methods) in that term too.
In the example shown, name is the method parameter and "Ravi" is an argument passed to that method. In that instance there is specific Java™ jargon.
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3865
|
|
Unless you're specifically talking about servlets? There there's a particular distinction. For instance, a request parameter is a read-only string that is passed in from the URL arguments, and a request attribute is a request-scoped object that can be added to the Request object by the servlet (and then accessed elsewhere).
If you're talking in general terms, in object-oriented design (not specifically limited to Java) attributes are the properties of a conceptual class, which (usually) end up corresponding to the fields of the corresponding Java (or whatever language) class.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
I didn’t think we were talking about servlets. I think you, Matthew, and I are in agreement here.
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3865
|
|
Campbell Ritchie wrote:I didn’t think we were talking about servlets. I think you, Matthew, and I are in agreement here.
No, I didn't think we were either (it ought to have been in the servlet forum if that was intended!). But I've seen the question asked in that context before quite a few times, so I thought I'd mention it in case.
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
Campbell Ritchie wrote:In the example shown, name is the method parameter and "Ravi" is an argument passed to that method. In that instance there is specific Java™ jargon.
Yes - I think I made a mistake in my understanding of swapping them both. Thanks Campbell!
|
 |
 |
|
|
subject: Difference between attributes and parameters
|
|
|