A method -- or sometimes called function -- is a group of statements that are grouped together to solve or perform a specific task.
Currently, you only coded inside of the main method and when solving more difficult tasks, this can make the code unreadable and hard to debug.
By grouping code into a method, we can simply call that method over and over again while only writing the code once.
Then whatever task we are trying to solve can be broken down into sizable chunks for easier understanding and debugging.
A void method is a type of method that simply executes the code written inside the method braces. A void method returns no values (returns will be covered in 3.9).
A method header is a list of keywords, name, and parentheses that defines how your method will function.
1. Visibility -> For now, just put public.
This first part allows you to set the visibility for other classes. Since we are only working with one class right now, just keep it public.
2. Static -> For now, you have to write static.
This is another one of those, "we will get to it later because it has to do with classes but if we don't write it now our code will be more boring. Don't worry fam, I got you in Unit 4.
3. Void -> This tells java that your method will not return any values.
4. Method Name -> This is where you give your method/function a name to refer it by. Give it a useful name, you know, something that isn't.... Jared.
Start your method name with a lowercase letter, either use camelCase or underscores to separate words. No spaces allowed and do not start with numbers.
5. Parentheses () -> Every method has to have parentheses and you guessed it... we will eventually be putting code inside of the parentheses, that'll be 3.8.
6. Braces {} - Every line of code that you wanted executed with this method has to go inside the {}.
Methods from the creators of java.