Difference between arguments and parameters in Java [duplicate] Difference between arguments and parameters in Java [duplicate] java java

Difference between arguments and parameters in Java [duplicate]


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


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!


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".