Method

- block of code that you write that you can call from anywhere, anytime if it is included in that class and folder. - Block of code that does one specific task - Separate blocks of code to do specific action ex. setHeight, move(int x, int y) - Reasoning call the same code over and over - Names for method are always like the lowerCase toStart Upper After. - Methods are always named like an Action and Verbs. - A java method is a series of statements that perform some repeated task. Instead of writing 10 lines of code we can put those ten lines in a method and just call it in one line. It is like a shortcut.
 * __Method__**

__**Concept:**__ Instead of just repeating the following over and over again... code System.out.println("Attn: AP Computer Science"); System.out.println("Woodbridge Senior High School"); System.out.println("3001 Old Bridge Road"); System.out.println("Woodbridge VA 22192");

code ...we could just put it in a method like this... code public static void printHeader {   System.out.println("Attn: AP Computer Science"); System.out.println("Woodbridge Senior High School"); System.out.println("3001 Old Bridge Road"); System.out.println("Woodbridge VA 22192");

}

code ...and then all we'd have to do is call it using the method name... code printHeader;

code ...so it'll still print the same thing: Attn: AP Computer Science Woodbridge Senior High School 3001 Old Bridge Road Woodbridge VA 22192

code public static void main (String[]args) { // this is a method // void - returns nothing, just does what it says to do // main - the name of the method // names for methods are always like this lowerCastToStartUpperAfter // methods are always named like an action, verb // methods do something: actions or verbs // parameters or arguments are values that are being sent in } public ()
 * __How to write a Method__**

example: public void move (int xChange, int yChange) { // the code that moves your whatever you want based on xChange and yChange head.move(xChange, yChange); } code move( 3, 3 ); which would move the object 3 to the right & 3 down**
 * an example of this move method would be:

__Types of Methods__ Accessors: **get info about your fields** -example: **getHeight, getNumBaths** -example in code: code public class House

{      private int baths; private int bedrooms; //accessor methods public int getNumBaths {           return baths; }          public int getNumBedrooms {          return bedrooms; } }

code

Mutator: **changes things** -example: **setHeight, move(x,y)** -example in code:** code public class House { private int numRooms; private int x,y;

//mutator public void setNumRooms(int Num) {   numRooms = num; } public void move (int xChange, yChange) {   x = x + xChange; y = y + yChange; } }

code Remember, the method you create only works for the one program it's in unless other programs use the original one. Trying to call the method in a different class will not work unless there is some relationship established between the two.