r/learnjava • u/jgonzalez-cs • Feb 08 '22
Does Java really not have functions?
Hi, I'm brand new to Java.
I googled "Does Java have functions" and the first/top result says, "There are no functions per se in Java. All you've got is methods."
I'm not sure what the latter part of that means, but you really can't create functions in Java?
Thanks, sorry for the noob question
7
Upvotes
9
u/desrtfx Feb 09 '22
Since Java requires everything to be inside classes, there are technically no functions.
The distinction is that functions can exist outside classes, and methods always belong to a class.
So, what is called a function in languages like Python, is a method in Java.
This has nothing to do with being able to return values or not.
It is just a matter of context.