Class
What do we put into our class definition? Methods, of coarse.
A method is a collection of statements that are grouped together to perform an operation.
Methods must be declared inside of the class definition. To be more specific, the methods must exist inside the opening and closing brackets of the class definition.
An example of a method:
public void bounce()
{
}
The first word public is a Java keyword which declares an access level for the method. In this case, public would mean that it is accessible to everyone. It is public.
The second word void is a Java uninstantiable placeholder. I know. That makes no sense. That's the technical terminology and I would be very wrong not to refer to it as such. Let me just say it means what it sounds like. It's nothing. Void. Get it?
The third word is the name of the method. In this case, bounce is the name of the method. You can name your methods anything you want as long as they don't interfere with Java keywords. Of coarse, there are more rules to naming methods. For now, assume we can name it whatever we feel like. I will explain method naming further into this tutorial.
The half-moon brackets are immediately after the name. Yes, I call them half-moon brackets. You call them whatever you want to call them. They look like this ().
Finally, we have two more curly brackets. Once is considered opening the method and the other is considered closing the method.
We mentioned that a method is a collection of statements. So let us talk about statements.
Statements
Statements are instructions on how the method should perform. Statements end with a semi-colon. There are all kinds of statements. Statements are the heart and soul of programming. It's the part of coding that makes things happen.
thisIsAstatement;
Summary of Learning
We write source code. Then compile it into machine-readable language code that will run as a program by using files with extensions of .java. The program runs on a Java Virtual Machine. Any computer that has a Java Virtual Machine can run our program in the machine-readable language. We use a class definition composed of methods and statements to accomplish the tasks that our program require.
Example Code of our learning.
public class Example
{
public void bounce()
{
statement;
}
}
This example contains one class definition, one method definition, and one statement.