14

I'm currently working on java legacy code and I encounter with a class that represent a formal parameter but I don't know why is that. I read about C++ Formal Parameters, but it confused me because in C++ it is the same as the argument (I'm in doubt about this affirmation) and in my legacy code it is a class, that has only a private int member that store a number (with their set & get methods) but honestly, I didn't find the why of that declaration.

PlainOldProgrammer
  • 2,725
  • 5
  • 22
  • 30
  • 1
    check for actual parameter as well – Kick Buttowski Dec 15 '14 at 22:31
  • 1
    I think you should check if your class has any documentation, and if not, see where it is used. It could be used in the context of a language parser of some sort. If you find it, you can edit your question and add your new information, and maybe we'll be able to point out the connection between your class and "formal parameters" (this expression is rarely used in Java so I doubt the class represents anything in the Java language). – RealSkeptic Dec 15 '14 at 22:37

3 Answers3

15

In Java and in C++ the formal parameter is specified in the signature of the method:

public void callIt(String a)

callIt has a single formal parameter that is a String. At run-time we talk about actual parameters (or arguments), the :

callIt("Hello, World");

"Hello, World" String is an actual parameter, String a is a formal parameter.

From the Wikipedia entry for parameter:

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

and:

argument (sometimes called actual parameter) refers to the actual input passed.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
4

Not disagreeing with Elliot Frisch at all, but I can say it more simply:

The variable w is a "formal parameter" in the following function definition:

void foobar(Widget w) {
    ...
}

The value returned by nextWidget(...) is the "actual parameter" when you write the following function call:

foobar(nextWidget(...));
Solomon Slow
  • 25,130
  • 5
  • 37
  • 57
2

Well, coming to Java or any language these definitions always hold true:

  • caller — the function is invoking the function call.

  • callee — the function that is invoked by the caller.

An argument term technically in programming refers to the data that is passed by caller to the callee.

And a parameter term technically refers to the type of data being passed more specifically to an identifier which identifies the type of data. So a parameter more or less refers to the identifier that identifies a particular type. Coming further, a formal parameter is the identifier used in the callee's method signature.

And an actual parameter is the identifier used by the caller when invoking the call.

Since you know that we can even pass the arguments (i.e. data) in the call to the callee directly, actual parameters are not compulsory and hence directly data can be passed whereas formal parameters are always compulsory.