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










share|improve this question









New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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 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















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










share|improve this question









New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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 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













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










share|improve this question









New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Nick Parsons

2,0682518




2,0682518






New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Sai pavan

1




1




New contributor




Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sai pavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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 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


















  • 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 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
















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












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);
}
}





share|improve this answer










New contributor




Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    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();
    }
    }





    share|improve this answer








    New contributor




    Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      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);
      }
      }





      share|improve this answer










      New contributor




      Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        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);
        }
        }





        share|improve this answer










        New contributor




        Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          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);
          }
          }





          share|improve this answer










          New contributor




          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          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);
          }
          }






          share|improve this answer










          New contributor




          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer








          edited yesterday





















          New contributor




          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered yesterday









          Sand

          1568




          1568




          New contributor




          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Sand is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.
























              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();
              }
              }





              share|improve this answer








              New contributor




              Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                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();
                }
                }





                share|improve this answer








                New contributor




                Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




















                  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();
                  }
                  }





                  share|improve this answer








                  New contributor




                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  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();
                  }
                  }






                  share|improve this answer








                  New contributor




                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered yesterday









                  Yash Mirashi

                  11




                  11




                  New contributor




                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Yash Mirashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.















                      Popular posts from this blog

                      Full-time equivalent

                      Bicuculline

                      さくらももこ