Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between parameter and arguments

 
Muhammad Usman
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am having difficulty in understanding what is the difference between parameter and agruments.
also having difficulty to understand the reason for return type "void" in any method.
i hope u guys can help me
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameter are placeholders for values and/or object references in the signature of a method. Arguments are the actual values and/or object references you give when invoking a method.
For instance:
public void aMethod(String s,int i);
in the signature of aMethod, the first parameter is a reference to an object of type String and i is a primitive integer value.
You invoke aMethod (someObject is an instance of the class containing aMethod as member method) like this:
someObject.aMethod("hello",1);
Here "hello" is the first String argument and 1 the second integer argument.
Concerning your second question, "void" is not a return type, it just indicates that nothing is returned by the method.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Colin Kenworthy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java language says a method (but not constructors) has to define a return type in it's header when you code it. What do you do if your method does not return anything ? That is why the reserved word "void" is used - to say that this method does not return anything.
 
Sadaf Zaidi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable use to store value is called Parameter and the valus pass in the method is called Argument.
publis static anyMethod(int a,double d)
In this method the int a and double d is a parameter.
anyObjest.anyMethod(1,5.5)
Here we are calling anyMethod from anyObject and 1 and 5.5 are arguments (values) passing to a ad d.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic