Big idea: Take a large complicated problem and break it down into small pieces called methods. Each of these pieces does one specific job in the program.
AP Computer Science - Unit Four
Void Methods
Methods you have used: .compareTo("zebra") .length() .equals("Howdy") .charAt(1)
AP Computer Science - Unit Four
Void Methods
Method These pieces of code are given a name. The method goes above main. The name lets Java find the correct piece of code
AP Computer Science - Unit Four
Void Methods
Example: Write a method to print "java" public void printJava (){ System.out.println("java"); }
AP Computer Science - Unit Four
Void Methods
So how do we use this? In Main: public static void main (String str[]) throws IOException { }
printJava();
AP Computer Science - Unit Four
Void Methods
So why do we use this? Code Reuse You can set up a really long tricky bit of code and then every time you need to run it you type in: doTrickyStuff();