Methods let you re-use code in multiple places. They also can be used to hide complexity in a process called abstraction (discussed later). The basic structure of a method is the following:

<return type> <method name>(<parameters>) {
	<code>
}

Methods are then called by name with arguments in the place of their parameters.

<method name>(<arguments>);

When a method is called, the code has the option to “return” a value, which means that a value is placed where the method was called from. The return type is the type of the value (discussed in the variables section). If no value is returned, the return type is void and the return operator is not required.

int onePlusOne() {
	return 1 + 1;
}

// Now, calling the function
System.out.println(onePlusOne()); <- Prints 2

void printHello() {
	System.out.println("Hello!");
	// No value is returned because the return type is void
}

Sometimes it is necessary for a method to given extra information to work with. This takes the form of a parameter list, which is a list of variables and their types that will be used inside the function. Between each variable is a comma.

int addIntegers(int number1, int number2) {
	return number1 + number2; <- Using variables declared as parameters
}

When calling a method with parameters, you use arguments, which is a comma-separated list that matches up with the parameter list. The types of the arguments must be the same types as the parameters.

int a = 3;
addIntegers(a, 2); <- Returns 5

In our code, method names use camelCase. Methods that return commands (discussed later) are camelCase and have the word Command at the end to indicate that it returns a command. For example:

void setVelocity() {...}
Command setVelocityCommand() {...}