Why do we use formal parameters in java [on hold]
up vote
-4
down vote
favorite
I actually started learning java and my question is why do we use parameters and what are the uses of them? If we can initialize data members then what's the need of parameters? Also, what's the difference between parameters and arguments.
Thanks
java parameters arguments
New contributor
put on hold as unclear what you're asking by khelwood, AKSW, Pshemo, GBlodgett, stealthyninja 17 hours ago
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.
|
show 1 more comment
up vote
-4
down vote
favorite
I actually started learning java and my question is why do we use parameters and what are the uses of them? If we can initialize data members then what's the need of parameters? Also, what's the difference between parameters and arguments.
Thanks
java parameters arguments
New contributor
put on hold as unclear what you're asking by khelwood, AKSW, Pshemo, GBlodgett, stealthyninja 17 hours ago
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.
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we useSystem.out.println("hello world")
we are usingprintln
method which accepts parameter which it should print. Without allowing methods to have parameters there can't beSystem.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.
– Pshemo
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday
|
show 1 more comment
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I actually started learning java and my question is why do we use parameters and what are the uses of them? If we can initialize data members then what's the need of parameters? Also, what's the difference between parameters and arguments.
Thanks
java parameters arguments
New contributor
I actually started learning java and my question is why do we use parameters and what are the uses of them? If we can initialize data members then what's the need of parameters? Also, what's the difference between parameters and arguments.
Thanks
java parameters arguments
java parameters arguments
New contributor
New contributor
edited yesterday
Nick Parsons
2,0682518
2,0682518
New contributor
asked yesterday
Sai pavan
1
1
New contributor
New contributor
put on hold as unclear what you're asking by khelwood, AKSW, Pshemo, GBlodgett, stealthyninja 17 hours ago
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.
put on hold as unclear what you're asking by khelwood, AKSW, Pshemo, GBlodgett, stealthyninja 17 hours ago
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.
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we useSystem.out.println("hello world")
we are usingprintln
method which accepts parameter which it should print. Without allowing methods to have parameters there can't beSystem.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.
– Pshemo
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday
|
show 1 more comment
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we useSystem.out.println("hello world")
we are usingprintln
method which accepts parameter which it should print. Without allowing methods to have parameters there can't beSystem.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.
– Pshemo
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we use
System.out.println("hello world")
we are using println
method which accepts parameter which it should print. Without allowing methods to have parameters there can't be System.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.– Pshemo
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we use
System.out.println("hello world")
we are using println
method which accepts parameter which it should print. Without allowing methods to have parameters there can't be System.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.– Pshemo
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
Parameters are giving information to a method about what it needs to do its job. For an example, a function to find the max number would have an array of numbers as a parameter.
A parameter is a variable in a method definition. When a method is called somewhere, the arguments are the data you pass into the method's parameters.
class A {
void theMethod(String theParameter) {
System.out.println(theParameter);
}
public static void main(String args) {
String argument = "the argument";
new A().theMethod(argument);
}
}
New contributor
add a comment |
up vote
0
down vote
The parameters are used as both local and global variables (initialization purpose), local variables means inside a method or a function and global variables we use as an instance variables, ie. Class variables which are initialized by parameters or arguments.
Generally, in Java we use constructor to initialize the class variables.
For example:
class Circle {
float r ; // instance variable or class variable which has to be used globally
public Circle( float r){
this.r = r;
}
public void area(){
float pi = 3.14f;
float area = pi * r * r;
System.out.println("Area of a circle is "+area);
}
public static void main(String args){
Circle c = new Circle(23.2f);
c.area();
}
}
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Parameters are giving information to a method about what it needs to do its job. For an example, a function to find the max number would have an array of numbers as a parameter.
A parameter is a variable in a method definition. When a method is called somewhere, the arguments are the data you pass into the method's parameters.
class A {
void theMethod(String theParameter) {
System.out.println(theParameter);
}
public static void main(String args) {
String argument = "the argument";
new A().theMethod(argument);
}
}
New contributor
add a comment |
up vote
0
down vote
Parameters are giving information to a method about what it needs to do its job. For an example, a function to find the max number would have an array of numbers as a parameter.
A parameter is a variable in a method definition. When a method is called somewhere, the arguments are the data you pass into the method's parameters.
class A {
void theMethod(String theParameter) {
System.out.println(theParameter);
}
public static void main(String args) {
String argument = "the argument";
new A().theMethod(argument);
}
}
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
Parameters are giving information to a method about what it needs to do its job. For an example, a function to find the max number would have an array of numbers as a parameter.
A parameter is a variable in a method definition. When a method is called somewhere, the arguments are the data you pass into the method's parameters.
class A {
void theMethod(String theParameter) {
System.out.println(theParameter);
}
public static void main(String args) {
String argument = "the argument";
new A().theMethod(argument);
}
}
New contributor
Parameters are giving information to a method about what it needs to do its job. For an example, a function to find the max number would have an array of numbers as a parameter.
A parameter is a variable in a method definition. When a method is called somewhere, the arguments are the data you pass into the method's parameters.
class A {
void theMethod(String theParameter) {
System.out.println(theParameter);
}
public static void main(String args) {
String argument = "the argument";
new A().theMethod(argument);
}
}
New contributor
edited yesterday
New contributor
answered yesterday
Sand
1568
1568
New contributor
New contributor
add a comment |
add a comment |
up vote
0
down vote
The parameters are used as both local and global variables (initialization purpose), local variables means inside a method or a function and global variables we use as an instance variables, ie. Class variables which are initialized by parameters or arguments.
Generally, in Java we use constructor to initialize the class variables.
For example:
class Circle {
float r ; // instance variable or class variable which has to be used globally
public Circle( float r){
this.r = r;
}
public void area(){
float pi = 3.14f;
float area = pi * r * r;
System.out.println("Area of a circle is "+area);
}
public static void main(String args){
Circle c = new Circle(23.2f);
c.area();
}
}
New contributor
add a comment |
up vote
0
down vote
The parameters are used as both local and global variables (initialization purpose), local variables means inside a method or a function and global variables we use as an instance variables, ie. Class variables which are initialized by parameters or arguments.
Generally, in Java we use constructor to initialize the class variables.
For example:
class Circle {
float r ; // instance variable or class variable which has to be used globally
public Circle( float r){
this.r = r;
}
public void area(){
float pi = 3.14f;
float area = pi * r * r;
System.out.println("Area of a circle is "+area);
}
public static void main(String args){
Circle c = new Circle(23.2f);
c.area();
}
}
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
The parameters are used as both local and global variables (initialization purpose), local variables means inside a method or a function and global variables we use as an instance variables, ie. Class variables which are initialized by parameters or arguments.
Generally, in Java we use constructor to initialize the class variables.
For example:
class Circle {
float r ; // instance variable or class variable which has to be used globally
public Circle( float r){
this.r = r;
}
public void area(){
float pi = 3.14f;
float area = pi * r * r;
System.out.println("Area of a circle is "+area);
}
public static void main(String args){
Circle c = new Circle(23.2f);
c.area();
}
}
New contributor
The parameters are used as both local and global variables (initialization purpose), local variables means inside a method or a function and global variables we use as an instance variables, ie. Class variables which are initialized by parameters or arguments.
Generally, in Java we use constructor to initialize the class variables.
For example:
class Circle {
float r ; // instance variable or class variable which has to be used globally
public Circle( float r){
this.r = r;
}
public void area(){
float pi = 3.14f;
float area = pi * r * r;
System.out.println("Area of a circle is "+area);
}
public static void main(String args){
Circle c = new Circle(23.2f);
c.area();
}
}
New contributor
New contributor
answered yesterday
Yash Mirashi
11
11
New contributor
New contributor
add a comment |
add a comment |
I don't know what you're asking and why. Who said that there is a difference? "arguments are the data you pass into the method's parameters. Parameter is variable in the declaration of function. Argument is the actual value of this variable that gets passed to function."
– AKSW
yesterday
And the question "why" is weird. I mean, could also ask why we use methods and classes
– AKSW
yesterday
Maybe the answer is "because functions".
– Michal
yesterday
What do you mean by "why do we use parameters"? It feels like asking "why methods can have parameters" in which case answer is: to let us customize method behavior from outside. For instance when we use
System.out.println("hello world")
we are usingprintln
method which accepts parameter which it should print. Without allowing methods to have parameters there can't beSystem.out.println("hello world")
. Maybe your question then is why we use methods at all? In that case research DRY (Don't Repeat Yourself) principle.– Pshemo
yesterday
Because it would be really cumbersome if the only way to pass data to other methods is by first setting member variables in an object and then calling the method...
– Jesper
yesterday