1
public double computePayment(double loanAmt,                   
                 double rate,
                 double futureValue,
                 int numPeriods) {
   double interest = rate / 100.0;
   double partial1 = Math.pow((1 + interest), 
                - numPeriods);
   double denominator = (1 - partial1) / interest;
   double answer = (-loanAmt / denominator)
                - ((futureValue * partial1) / denominator);
   return answer;
}

I am a beginner at Java and had a question about parameters. What exactly are they? I thought they were the variables used in the method, but now I see other variables like interest and partial1 being used in the method. These variables are derived from the parameter variables but still, what are parameters?

Thanks in advance.

1
  • To put it simply, they are variables whose value is defined by the invocation of the method. Note that all the values are a copy of the original ones. Commented Jul 6, 2015 at 9:31

5 Answers 5

1

The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.

You can look at Defining Methods for more details.

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

Comments

1

loanAmt, rate, futureValue and numPeriods are parameters while interest, partial1 etc. are local variables. Parameters are passed from the outside as part of the method call, local variables are for internal use.

Comments

1

Method Parameters are basically just a possibility to pass values (or references to objects) to methods. If you have a method which adds two values, you need those values before. They are passed through the Parameters for this method. So if your methods need some additional information to work with, you pass this information through parameters.

Comments

1

It's not certainly solely about Java but general programming language concept, here below mentioned variables are method/function argument which also makes a part of method signature whereas partial1 and interest are declared local variables which are declared within the function and so scoped within the function only.

             double loanAmt,
              double rate,
              double futureValue,
              int numPeriods

So, while calling the function computePayment you will have to provide those arguments without which it will not work/your program will not compile since those arguments are the dependency of the function.

2 Comments

Thanks. I get it now. So when you say scoped within the function, they cannot be used outside it, right?
Yes, that's exactly what it means.
0

The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition, parameters appear in procedure definitions.

A parameter is an intrinsic property of the procedure, included in its definition. For example, in many languages, a procedure to add two supplied integers together and calculate the sum would need two parameters, one for each integer.

The function test has two parameters, named parm1 and parm2. It adds the values passed into the parameters, and returns the result to the subroutine's caller.

int test(int parm1, int parm2)
{
    return parm1 + parm2;
}

1 Comment

Probably it's worth mentioning the difference between parameters and arguments. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.