2

Why functions are called methods in java. I am not asking the difference between the two. Why Java community choose to name them methods. Is there any concrete reason behind this decision or it's just a name? When i think of literal meaning as far as i could think function is related to internal working of some machine. Method is a way of working to achieve a goal(mathematical solution) or may be method is a way of implementing an Object. Is that where it came from or i just missed the real picture?

Hello World
  • 944
  • 2
  • 15
  • 39
  • 2
    Guess you should contact James Gosling :) – Balwinder Singh Apr 07 '14 at 13:08
  • As i have already mentioned in my question that i am not asking for difference between the two. – Hello World Apr 07 '14 at 13:09
  • It becomes a lot more clear if you consider languages other than Java, particularly "functional" languages. Functions are more stateless in that they independently operate on what's given to them whereas methods are functionality exposed by a particular stateful object. – David Apr 07 '14 at 13:09
  • 1
    @Mr.Pandey: Actually, you are, basically. The terms mean different things. The correct term for what Java has is "method", for the reasons given in the answer to that question. So that's the term they used. – T.J. Crowder Apr 07 '14 at 13:10
  • 1
    @Mr.Pandey: If you're not asking for the difference between the two, then what *are* you asking? If you know the difference (which, admittedly, I didn't until recently) then what is unclear? – David Apr 07 '14 at 13:10
  • Yes I bet i should Balwinder Singh. – Hello World Apr 07 '14 at 13:10
  • 4
    Functions are not called methods in java. Your premise is wrong because you don't know what the differences between the two are. – Sotirios Delimanolis Apr 07 '14 at 13:11
  • @SotiriosDelimanolis: Ah, good point! Particularly now that Java has functions, as of Java 8. :-) (At least, I don't *think* it did before that...) – T.J. Crowder Apr 07 '14 at 13:12
  • @David:I am asking why Java community name them methods why didn't them them 'procedure' or something else. – Hello World Apr 07 '14 at 13:14
  • @Mr.Pandey: Because they are methods. For the same reason they called variables "variables." Because that's what they are. – David Apr 07 '14 at 13:16
  • @David: So all you are saying is that they are just names? As far as i know Java has a very big community and they don't take any single decision so lightly and please don't down vote as i am newbie in java. I am just eager to learn :) – Hello World Apr 07 '14 at 13:26
  • 1
    @Mr.Pandey: I'm saying that the words "function" and "method" in this context have specific meanings. Java chose to call them "methods" because they fit the already-existing meaning of that word. Had they called them "functions" they would be introduced confusion because that word already has a different meaning. – David Apr 07 '14 at 13:33

3 Answers3

13

It's not in Java, it's an OOP name.

In sort, it defines part of the behavior of an instance of an object, not a general operation.

robertoia
  • 2,301
  • 23
  • 29
1

Every language has it's own syntax to differentiate from others. As for your question

Functions existence is independent.

Methods do not as they are created within the class.

Harry
  • 3,031
  • 7
  • 42
  • 67
1

Why functions are called methods in java?

  1. A method is on an object.
  2. A function is independent of an object.
  3. For Java, there are only methods.
  4. For C, there are only functions.

For C++ it would depend on whether or not you're in a class.

In languages such as C++, functions are bits of code that will perform a particular action - but are not associated with an object. functions that are to do with an object are called methods. in java all functions are methods as they are all to do with objects.

Community
  • 1
  • 1
jmail
  • 5,944
  • 3
  • 21
  • 35
  • Well, IMHO static methods are closer to functions in this respect. But I mostly agree with you. – Joffrey Apr 07 '14 at 13:27