Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

what does it mean to not return anything

very simple terms please

1 Answer

You'll notice that, in many cases, your functions will contain the "return" keyword. This means that when they are called, they give back a value that can be assigned to another variable (as in: cereal = getCereal() where getCereal() "returns" the name of a cereal ). Sometimes we create functions that don't need to give us back a value. Like if we made a function called "changeCereal()" that changed the cereal variable. It doesn't give us anything back, it just does some action.

These functions are preceded by a "void" rather than "String" or "int" because they don't return data of any type. Sometimes a void function will print something to our screen, but that print statement can't be assigned into a variable as in cereal = printCereal(). This would throw a compiler error because it's not "return"ing any data to us. Not returning anything basically means that there are no return statements in the function. That's a simple explanation, but not a perfect one.

I hope that helps a little. I'm not the greatest at explaining but hit me back if you need to chat about it further.