3

Its a conceptual question. But I would like to use the right term at the right place. That is why I would like to read some other views on this.

closed as unclear what you're asking by gnat, Telastyn, BЈовић, GlenH7, Doc Brown Feb 12 '15 at 15:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

In layman's words:

  • Imagine a function as a black box.
  • You don't know how the black box works
  • You only know what the black box does, but not how
  • The black box needs something to work on, that you must provide
  • The black box gives you something in return
  • That thing you provide the black box is a parameter
  • The pieces of information you don't know of, that the black box uses to do it's work, are variables
  • But hey!, for you (the caller), the thing you give the black box can be a variable of your own, that you use to do your own work.
  • You can also give the black box a literal, i.e, instead of passing it the variable personName you could pass it "Peter". The black box doesn't know whether you passed it a variable or a literal. Once inside the black box, it's a variable as seen from the perspective of the black box.
  • Finally the black box gives you something back, which is called a "return value", which you can put in a variable or your own, or not, or you can pass to another box as a parameter.
  • Some black boxes don't need you to pass them anything.
  • Some black boxes don't return anything, and people call them "methods".
  • Some people call parameters "arguments".
1

Parameters are variables that only exist within a method, and are initialized automatically with the values passed to the method.

0

Parameters can be used as a special type of variable, but the basic difference is scope: that a variable is local (it only exists within the current method), whereas a parameter is external: it is passed in to the method from the caller. This means that, if the parameter is passed by reference (including essentially any object type), changes to the parameter will be reflected in the calling code once the method exits, whereas anything done to a local variable does not live beyond the method. (Unless it gets passed elsewhere and stored, of course.)

  • 5
    Parameters are never passed by reference in Java. Java is always pass-by-value. Changes to the parameter will not be reflected outside the method. (Changes to the argument which is referenced by the parameter will, but that's a totally different matter. Java is not a purely functional language, it has shared mutable state.) – Jörg W Mittag Feb 12 '15 at 13:22
  • @JörgWMittag: When all objects are reference types anyway, that's hair-splitting at best. – Mason Wheeler Feb 12 '15 at 23:14
  • Pass-by-reference vs. pass-by-value refers to how arguments are being passed, not what those arguments are. That is completely and utterly irrelevant. C is pass-by-value, no matter whether the argument being passed is an int or a pointer to some struct. Java is pass-by-value, no matter whether the argument being passed is an int or a reference to some object. If you can do this: void foo(String bar) { bar = "World"; } void main(String... args) { String baz = "Hello"; foo(baz); assertTrue("World".equals(baz)) } then it is pass-by-reference, otherwise it is pass-by-value. – Jörg W Mittag Feb 13 '15 at 0:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.