r/learnjava • • 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

23 comments sorted by

View all comments

36

u/_Atomfinger_ Feb 08 '22

In java methods = functions.

-1

u/dissusgsbkl Feb 09 '22

no they’re not… how do you think C++ has both methods and functions?

4

u/_Atomfinger_ Feb 09 '22

Read the "in java" part.

1

u/dissusgsbkl Feb 09 '22

a method is part of a class and has access to data members of the class, hence why it’s a method and not a function.

quite different. saying functions = methods in java is EXTREMELY short sighted, especially since the question specifically asked the difference

3

u/_Atomfinger_ Feb 09 '22

I know the difference.

The point was not to provide an in-depth answer about methods vs functions but to give OP a simple sentence that will make it easier for them to just get on with it. There are so many "well, actually" moments in programming that it often is better to ignore some of the technicalities.

Also, there are plenty of other excellent comments in this thread that does bring up what you say, so I'm not sure what you want from me.