Skip to content
Related Articles

Related Articles

Argument vs Parameter in Java
  • Difficulty Level : Basic
  • Last Updated : 08 Nov, 2019

Argument

An argument is a value passed to a function when the function is called. Whenever any function is called during the execution of the program there are some values passed with the function. These values are called arguments. An argument when passed with a function replaces with those variables which were used during the function definition and the function is then executed with these values. Let’s look at some examples for easy understanding:

Example:




public class Example {
  
    public static int multiply(int a, int b)
    {
        return a + b;
    }
  
    public static void main(String[] args)
    {
        int x = 2;
        int y = 5;
  
        // the variables x and y are arguments
        int sum = multiply(x, y);
  
        System.out.println("SUM IS: " + sum);
    }
}
Output:
SUM IS: 7
In the above example 
in the function main 
the variable x and y are the arguments

Parameters



A parameter is a variable used to define a particular value during a function definition. Whenever we define a function we introduce our compiler with some variables that are being used in the running of that function. These variables are often termed as Parameters. The parameters and arguments mostly have the same value but theoretically, are different from each other.

Example:




public class Example {
  
    // the variables a and b are parameters
    public static int multiply(int a, int b)
    {
        return a + b;
    }
  
    public static void main(String[] args)
    {
        int x = 2;
        int y = 5;
  
        int sum = multiply(x, y);
  
        System.out.println("SUM IS: " + sum);
    }
}
Output:
SUM IS: 7
In the above example 
in the function multiply 
the variable a and b are the parameters

Difference between an Argument and a Parameter

ArgumentParameter
When a function is called, the values that are passed in the call are called arguments.The values which are written at the time of the function prototype and the definition of the function.
These are used in function call statement to send value from the calling function to the called function.These are used in function header of the called function to receive the value from the arguments.
During the time of call each argument is always assigned to the parameter in the function definition.Parameters are local variables which are assigned value of the arguments when the function is called
They are also called Actual ParametersThey are also called Formal Parameters

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :