Method Declarations – Intro to Java Programming


Let’s have a closer look at how methods are described in javadoc. Here is an example. Before the parenthesis you have the name of the method, in this case pixels. Before the name, you have the type of the return value. In this case, that’s int because the pixels method returns the number of pixels in an image as an integer since you can’t have half a pixel. Let’s look at another example, the grow method. Again, the name is before the parentheses and before that is the return type but in this case, remember the grow method doesn’t return anything and we use this special word void to denote that. Void means that nothing is returned. Now this method call has another feature. It describes what kind of arguments to pass. You call this method with two arguments and here you find the types you can grow by any decimal number. It doesn’t have to be an integer. Now actually and that’s a minor detail, that you don’t really need to think about until the next lesson. What you see inside here, the double dw and the double dh are themselves variable declarations. They declare two variables that are called the parameter variables. Like I said, right now you don’t yet have to worry about the parameter variables but when you see the word parameters in javadoc, then you’ll know where that comes from. Now you know all the technical terms that you need to decipher a javadoc documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *