What Is The Difference Between Function And Method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunil samal
    New Member
    • Jan 2008
    • 1

    #1

    What Is The Difference Between Function And Method

    What Is The Difference Between Function And Method
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sunil samal
    What Is The Difference Between Function And Method
    The mathematicians that hang around this forum will probably tell you that a function is a method that returns exactly one value.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by r035198x
      The mathematicians that hang around this forum will probably tell you that a function is a method that returns exactly one value.
      There are different notions about functions and methods: a method in Java can
      do what it wants: bake a cake for you, print "foo" on every paper page in your
      printer until the printer is out of paper, attempt to format your harddisks and a
      lot more usefull things. A function in Java can do the same but it must return
      a value of a certain type.

      A lot more restrictive (but very useful) functions are the 'referential transparent'
      functions: those functions don't have side effects (no cake, no out of paper and
      no fresh hard disks) and every time you call them with the same parameter
      values they return the same value again and again. According to this definition
      e.g. the Random.nextint( ) method is not a function.

      Of course mathematics nags a bit further about, e,g. continuous functions,
      bijective, injective, surjective functions, (primitive) recursive functions, computable
      functions and the list goes on and on. Those mathematicians are loonies, there's
      no need to pay any attention to them when you deal with Java.

      kind regards,

      Jos

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        In Java, the preferred terminology is method. I don't know if the word "function" even appears in the Java Language Specification (JLS), although a Java programmer would know what you're talking about. Here is the relevant section, enjoy:

        JLS: methods

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

          This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

          MODERATOR

          Comment

          Working...