Published Sep 27th, 2014, 9/27/14 1:34 pm
- 306 views • 1 today
- 1
- 0
9
And we're back! Welcome to episode 6 of Java Text Tutorials!
Table of Contents:
6. What is a method?
6.1 What is a constructor?
6. What is a method?
A method is essentially, where a majority of your code will go. Think of classes like a folder and methods like a subfolder. You can use a method specifically to execute the code inside. Java does methods like this, to use a method you must call it, then Java will execute all of the code inside of that method. This is what a method looks like:

So here is what this means:
public - The method is useable by all classes (this is called a method modifyer, more on this another tutorial)
void - This means that the method will do all the code inside of itself and then its done. It moves to the next thing ordered by the computer (More on void another time, just know you need to include it in methods for now.)
aMethod() - This specifies the method name. The () is to tell Java that it is a method. Stuff will go inside these parenthesis, but that's another tutorial.
{ } - I call these curly brackets. Basically what this means is that you are telling Java to execute all of the code inside these curly brackets. All your code for the method will go inside of here. There isn't too much to know about methods. I will cover how to use a method in a multiple class tutorial later.
6.1 What is a constructor?
Constructors are almost the same thing as methods. However you cannot call them and they must be the same name as your class name. Whenever that class runs, it will run the constructor. Construcotrs never have void in them. There isn't really much to know about constructors either. Here is an example:

In the next tutorial we will talk about parameters and method modifyers.
Table of Contents:
6. What is a method?
6.1 What is a constructor?
6. What is a method?
A method is essentially, where a majority of your code will go. Think of classes like a folder and methods like a subfolder. You can use a method specifically to execute the code inside. Java does methods like this, to use a method you must call it, then Java will execute all of the code inside of that method. This is what a method looks like:

So here is what this means:
public - The method is useable by all classes (this is called a method modifyer, more on this another tutorial)
void - This means that the method will do all the code inside of itself and then its done. It moves to the next thing ordered by the computer (More on void another time, just know you need to include it in methods for now.)
aMethod() - This specifies the method name. The () is to tell Java that it is a method. Stuff will go inside these parenthesis, but that's another tutorial.
{ } - I call these curly brackets. Basically what this means is that you are telling Java to execute all of the code inside these curly brackets. All your code for the method will go inside of here. There isn't too much to know about methods. I will cover how to use a method in a multiple class tutorial later.
6.1 What is a constructor?
Constructors are almost the same thing as methods. However you cannot call them and they must be the same name as your class name. Whenever that class runs, it will run the constructor. Construcotrs never have void in them. There isn't really much to know about constructors either. Here is an example:

In the next tutorial we will talk about parameters and method modifyers.
| Credit | Image From Oracle(www.oracle.com) |
| Tags |
3092388
6



Have something to say?