So, you may be wondering "how do I create a method?", well you will type the following code:
public static [type] [name] ( [data type] [variable name], [data type] [variable name], ...){
}
You may be wondering "what dose this mean?". We will take this one step at a time, starting with public. When you say public, you are saying that this method is available for your program to use. Java is a object oriented language, meaning that all methods and classes are actually objects unless their name contains static. When you say static in a method, you are saying that this method is not an object in the program.
Normally when you use methods, you are asking for the computer to spit out a piece of data for you. In my last post, I briefly discussed the ways you can store data. In place of the phrase [type], you would insert the data type that you want the computer to spit out. If you do not want to computer to return any data, you would just type void instead of a data type. Where the code says [name], you simply type what you want to call the method.
In parentheses, you would enter the inputs that the code needs to operate. You do this by first typing the type of the variable, and then what you want to call it. Your method can contain as many variables as you would like it to have. You would type the code that you want the computer to run when calling this method between the curly brackets.
}
You may be wondering "what dose this mean?". We will take this one step at a time, starting with public. When you say public, you are saying that this method is available for your program to use. Java is a object oriented language, meaning that all methods and classes are actually objects unless their name contains static. When you say static in a method, you are saying that this method is not an object in the program.
Normally when you use methods, you are asking for the computer to spit out a piece of data for you. In my last post, I briefly discussed the ways you can store data. In place of the phrase [type], you would insert the data type that you want the computer to spit out. If you do not want to computer to return any data, you would just type void instead of a data type. Where the code says [name], you simply type what you want to call the method.
In parentheses, you would enter the inputs that the code needs to operate. You do this by first typing the type of the variable, and then what you want to call it. Your method can contain as many variables as you would like it to have. You would type the code that you want the computer to run when calling this method between the curly brackets.
No comments:
Post a Comment