| Author |
Difference between Arguments and parameters
|
munish gupta
Greenhorn
Joined: Feb 21, 2012
Posts: 6
|
|
|
What is the Difference between Arguments and parameters ...
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12950
|
|
|
Those are two words that are often used for the same thing. There's no real difference.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
I always figured "parameter" refers to the local variable in the method signature. "Argument" refers to the value that's passed to this parameter.
Here 'x' is a parameter of foo(). '3' is an argument passed to foo().
|
 |
Roberto Perillo
Bartender
Joined: Dec 28, 2007
Posts: 2216
|
|
|
I too always had this same idea shown by Stephan...
|
Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12950
|
|
|
So, in your example, the x in line 1 is the parameter, while the 3 in line 6 is the argument.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
|
Yup.
|
 |
dennis deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 808
|
|
|
Is it useful to make such a distinction?
|
 |
Roberto Perillo
Bartender
Joined: Dec 28, 2007
Posts: 2216
|
|
|
Well, it's just that you often find these terms in the literature. It's good to know precisely what each term means.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
I too have the Opinion like Stephan and Roberto. but when I refer JLS, surprisingly it says it is argument .
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#40942
For a method, an ordered 3-tuple consisting of:
argument types: a list of the types of the arguments to the method member.
return type: the return type of the method member and the
throws clause: exception types declared in the throws clause of the method member.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
|
The distinction is just as important as knowing the difference between "variable" and "value". It's an especially great help when you're studying generics, because the phrases "type parameter" and "type argument" are often used. Here "type parameter" will refer to a variable, often named T or E, which is able to hold a "type argument" or "type value" or simply a "type".
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 6109
|
|
Seetharaman Venkatasamy wrote:I too have the Opinion like Stephan and Roberto. but when I refer JLS, surprisingly it says it is argument .
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#40942
For a method, an ordered 3-tuple consisting of:
argument types: a list of the types of the arguments to the method member.
return type: the return type of the method member and the
throws clause: exception types declared in the throws clause of the method member.
As Jesper said in the first reply:
Those are two words that are often used for the same thing. There's no real difference.
And I will add: ...unless somebody chooses to make a distinction in some particular context.
If you look at the JLS's index under "argument", you'll see one or two entries, and "See also: parameter".
And in the text, you find stuff like this: "...then the anonymous constructor has one formal parameter for each actual argument..." (http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9.5.1)
So it may not be entirely consistent in its usage. Although I do think the section you quoted could be referring the actual argument types. That is, the argument types list is telling us what the types of the actual arguments must be.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 6109
|
|
Stephan van Hulst wrote:The distinction is just as important as knowing the difference between "variable" and "value".
In other words, in many contexts it doesn't matter.
It's an especially great help when you're studying generics
Definitely.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
thank you Stephan and Jeff
|
 |
 |
|
|
subject: Difference between Arguments and parameters
|
|
|