Parameters – A parameter is a value that you can pass to a method in Java. Then the method can use the parameter as though it were a local variable initialized with the value of the variable passed to it by the calling method. In simple words, parameters helps to pass values into method.

Arguments – An argument in java is the value passed to the variables defined in the function when the function is called. Whenever the function is called during the execution of the program, arguments are passed to the function. An argument when passed with function, it takes the place of those variables which are used during the function definition and the function is executed with these values. In simple words, arguments are those values which passes through parameters into method.

Let’s understand through an example…

class code1{
    public static void main(String[] args) {
amnt(20);
    }
    static void amnt(int n){
System.out.println(“amnt is “+n);
    }
}
output

From the upper code, you see method ‘amnt’. Integer variable ‘n’ is parameter. Value ‘20’ of method ‘amnt’ is argument.

Calling method – which calls another method inside it.

Called method – this method get calls by another method.

** From the above code, method ‘main’ is calling method and method ‘amnt’ is called method.

Let’s understand another parameter and argument example…

class example{
    public static void main(String[] args) {
               // String value “abdulkalam” = argument    
StuName(“abdulkalam”);
    }
    // String variable ‘m’ = parameter
    static void StuName(String m){
System.out.println(“student name is “+m);
    }
}

Let’s work with multiple different parameters [int String Char] and its corresponding arguments.

Let’s see below code…

public class code2 {
    public static void main(String[] args) {
        student(“neha”, 30);
 
    }
    static void student(String name,int roll){
System.out.println(“name is “+name);
System.out.println(“roll is “+roll);
    }
}
output

From the upper code, you will see method ‘student’ has two different type parameters – string and int.

Formal & Actual argument – actual arguments are the values used in call of the function, while formal arguments are variables named in the parenthesized list in a function definition. Formal arguments receive a copy of actual arguments when function is called.

From the upper code example, ‘name’ and ‘roll’ variables are formal arguments and ‘neha’ and ‘30’ inside ‘student’ method are actual arguments.

Formal & Actual parameters – A formal parameter must be a name, that is, a simple identifier. A formal parameter is very much like a variable, and — like a variable — it has a specified type such as int, boolean, or String. An actual parameter is a value, and so it can be specified by any expression, provided that the expression computes a value of the correct type.

Let’s see another code example…

public class car {
    public static void main(String[] args) {
CarModel(2210,”TATA”, 450000.12f);
    }
// method ‘CarModel’ has 3 different parameters ->m,n,p
    static void CarModel(intm,Stringn,float p){
int model=m;
        String name=n;
        float price=p;
System.out.println(“Car model “+model);
System.out.println(“name is “+name);
System.out.println(“price is “+price);
    }
}
output

That’s why we passes different set of arguments (values).

Remember: when we deals with multiple different parameters, we need to passes same state of arguments.

If you want to return any type of value from method you can use primitive data-types (int, char, float). Methods are designed to return something, but when we don’t specify which type of value it will returns then we can use ‘void’ keyword.

Let’s make a code, which will return sum of three integers.

import java.util.Scanner;
 
public class code3 {
    public static void main(String[] args) {
int res = Sum(5,10,15);
System.out.println(“sum is “+res);
    }
    static int Sum(inta,intb,int c){
int sum=a+b+c;
        return sum;
    }
}
output

If you looks into upper code, you see we mentioned ‘int’ before method ‘Sum’. It’s mean this method will return an integer value.

Let’s make a code, which will takes three float values and returns summation of them as integer form. Perform different set of inputs 2 times.

public class code4 {
    public static void main(String[] args) {
floatSum(10.4f,20.4f,40.6f);
floatSum(20.56F,50.42F,10.16F);
 
    }
    static intfloatSum(float m,floatn,float p){
            float sum=m+n+p;
int Sum=(int)sum;
System.out.println(“sum is “+Sum);
            return Sum;
    }
}
output