Java Methods / Functions
A method is a block of code which only runs when it is called.
You can pass data, known as parameters, into a method.
Methods are used to perform certain actions, and they are also known as functions. Why use methods? To reuse code: define the code once, and use it many times.
Create a Method
A method must be declared within a class. It is defined with the name of the method, followed by parentheses ().
Call a Method
To call a method in Java, write the method's name followed by two parentheses () and a semicolon;
A method can also be called multiple times.
Parameters and Arguments
Information can be passed to methods as parameter. Parameters act as variables inside the method.
Multiple Parameters
You can have as many parameters as you like
Return Values
The void keyword, used in the examples above, indicates that the method should not return a value. If you want the method to return a value, you can use a primitive data type (such as int, char, etc.) instead of void, and use the return keyword inside the method.
Method Overloading
With method overloading, multiple methods can have the same name with different parameters