it is used in a function to define the return type, means there isn't one. Just roll with it.
If the function returned an integer, it would be int blah() {}
The point is that w/o keyword void, Java compiler's parser wouldn't be able to distinguish (or at least have a very hard time to figure that out) whether we're defining some function w/o a returning type or simply invoking it! ;))
From experience, it is important for automatic syntax checking. If you have something like float myFunction(){}, then you will have an error stating that myFunction needs to return a float:
float myFunction(){
float f=0.0;
return f;
}
On the other hand, you won't have any complaints when using void. Syntax checking will know that there is nothing to return.
Answers
it is used in a function to define the return type, means there isn't one. Just roll with it. If the function returned an integer, it would be int blah() {}
It indicates that the function does not return a value. For instance the method
must return a
float
The point is that w/o keyword
void
, Java compiler's parser wouldn't be able to distinguish (or at least have a very hard time to figure that out) whether we're defining some function w/o a returning type or simply invoking it! ;))From experience, it is important for automatic syntax checking. If you have something like float myFunction(){}, then you will have an error stating that myFunction needs to return a float:
On the other hand, you won't have any complaints when using void. Syntax checking will know that there is nothing to return.
I hope this helps,
Kf