Methods

To put it simply, Methods are a kind of short cut in Java that allows the programmer to use a specified segment of code by simply calling it's name and class. For example, take for instance the following Method:

This specific Method is designed to accept the input of Integer "x", and set it equal to zero, add six to itself, and finally to return Integer "x" to the place where the Method was called. If you wanted to have a Method that returned a different Data Type, you would change the first instance of "int" (After "static") to the Data Type that you wanted to return. For instance, take the following code in the main Method for example:

This specific calling of the Method "intExample" from the Method Class would input "x" as zero, run through the Method, and then print out the result on the console.

By calling the Method "intExample" from the Method Class, and instead of typing out all of the code necessary to create a variable - "x" - and set it equal to another variable - "y" -, the code is cleaner than it would be otherwise. Although this Method was short, and could easily be replicated within the main Method with just a few lines of code, imagine the uses for Methods such as in the event of when the amount of code needed for a segment of program is significantly larger than a quick, 2-3 lines of code.

Using Methods saves both the time of the person coding, and the time of any reviewers of the coder's program.