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

7

u/popey123 Feb 08 '22 edited Feb 08 '22

A function can be accessed without object whereas method does.
Because java is a full OOP langage, it doesn t have function.
Technically, when you use a static method, you may be implicitly calling the class from where it is declared.

public class Main {
public static main().... {
Main.a(); // or a()
}
a static method A()
}

But it doesn t matter. What is more important is the diff between methods (return) and procedures (void)

18

u/jgonzalez-cs Feb 08 '22

A function can be accessed without object whereas method does. Because java is a full OOP langage, it doesn t have function.

Ah ok so let me know if I'm understanding this right.

Java basically forces you to use classes, right? I've learned that much looking at code snippets.

And since Java is object oriented, basically a function needs to belong to an object/class, making it technically a method, therefore no functions?

5

u/s7oev Feb 08 '22

100% correct