General question: What does return mean?


I keep seeing this being referred to and I'm not sure what it means. Examples being "Return type" or "Return Value". Thank you!


With a
google search
java return statement


The return keyword stops the execution of a method, and gives a value as a result for the method's caller to use.

For example:

    public class Foo {
        public static void main(String[] args) {
            //The getRandomNumber() method returns the number 4, which is printed in this code.

        public int getRandomNumber() {
            return 4; //This is an Xkcd reference. :P

4 is the return value of the getRandomNumber(). int is the return type, because 4 is an int. The return type is specified on line 7 (public int getRandomNumber)