Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Using your New Tools Multiple Strings

What is a parameter?

What is the best definition of a parameter?

1 Answer

Simply put, a parameter is a value that you want your method to ask for when you invoke it in your program.

public String mName;
public void setYourName(String name) /*this is a parameter*/ {
  mName  = name;
  System.out.println("Your name is: " + mName);
}

In my example, String name is the parameter.

When you actually invoke the method, and pass in the parameter that the method asks for, then it is called an argument.

ParamPractice.java

public class ParamPractice {
    private static String mName;
    public static void main(String[] args) {
        setYourName("Derek"); //The String "Derek" is the argument, passed into the setYourName() method
    }

    public static void setYourName(String name) /*The empty String "name" is the parameter your method is asking for*/{
        mName = name;
        System.out.println("Your name is: " + mName);
    }
}

OUTPUT

Your name is: Derek

Also, keep in mind, if your method is asking for a parameter of any kind, when you invoke that specific method and you don't pass in that specific argument, your program WILL NOT compile.