50

Possible Duplicate:
What's the difference between an argument and a parameter?

I was going through some interview questions. I wasn't able to come up with a solid answer to this question:

Difference between arguments and parameters in Java?
How are they different?

5
  • 1
    This seems related: What's the difference between an argument and a parameter? Commented Oct 3, 2012 at 13:00
  • 1
    public static void main(String[]args) : args is a parameter containing list of arguments Commented Oct 3, 2012 at 13:00
  • 9
    You only have to worry about arguments if you're married. Otherwise just use the term parameter for both. Commented Oct 3, 2012 at 13:18
  • 3
    The main point is that the terminology in this area is not clear-cut, so this makes for Yet Another Stupid Interview Question. Commented Oct 3, 2012 at 13:26
  • 1
    From Oracle's tutorial (docs.oracle.com/javase/tutorial/java/javaOO/arguments.html): Note: Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order. Commented Jan 27, 2016 at 14:50

5 Answers 5

64

Generally a parameter is what appears in the definition of the method. An argument is the instance passed to the method during runtime.

You can see a description here: http://en.wikipedia.org/wiki/Parameter_(computer_programming)#Parameters_and_arguments

Sign up to request clarification or add additional context in comments.

2 Comments

primitives can be arguments too. ;)
@PeterLawrey The way these terms are used in the linked WP page, 42 can be considered an instance of the type int.
20

The term parameter refers to any declaration within the parentheses following the method/function name in a method/function declaration or definition; the term argument refers to any expression within the parentheses of a method/function call. i.e.

  1. parameter used in function/method definition.
  2. arguments used in function/method call.

Please have a look at the below example for better understanding:

package com.stackoverflow.works;

public class ArithmeticOperations {

    public static int add(int x, int y) { //x, y are parameters here
        return x + y;
    }

    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int sum = add(x, y); //x, y are arguments here
        System.out.println("SUM IS: " +sum);
    }

}

Thank you!

1 Comment

System.out.println(344); vs int v=344; System.out.println(v); which is argument/parameter? Can you please help me?
10

They are not. They're exactly the same.

However, some people say that parameters are placeholders in method signatures:

public void doMethod(String s, int i) {
  ..
}

String s and int i are sometimes said to be parameters. The arguments are the actual values/references:

myClassReference.doMethod("someString", 25);

"someString" and 25 are sometimes said to be the arguments.

1 Comment

Ohh ok, then why two different terms if they are same?
7

There are different points of view. One is they are the same. But in practice, we need to differentiate formal parameters (declarations in the method's header) and actual parameters (values passed at the point of invocation). While phrases "formal parameter" and "actual parameter" are common, "formal argument" and "actual argument" are not used. This is because "argument" is used mainly to denote "actual parameter". As a result, some people insist that "parameter" can denote only "formal parameter".

Comments

2

In java, there are two types of parameters, implicit parameters and explicit parameters. Explicit parameters are the arguments passed into a method. The implicit parameter of a method is the instance that the method is called from. Arguments are simply one of the two types of parameters.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.