What Does Method Signature Mean in Java?

Method Signature Definition

Young woman using laptop
Tetra Images/Getty Images

In Java, a method signature is part of the method declaration. It's the combination of the method name and the parameter list.

The reason for the emphasis on just the method name and parameter list is because of overloading. It's the ability to write methods that have the same name but accept different parameters. The Java compiler is able to discern the difference between the methods through their method signatures.

Method Signature Examples

public void setMapReference(int xCoordinate, int yCoordinate)
{
  //method code
}

The method signature in the above example is setMapReference(int, int). In other words, it's the method name and the parameter list of two integers. 

public void setMapReference(Point position)
{
  //method code
}

The Java compiler will let us add another method like the above example because its method signature is different, setMapReference(Point) in this case.

public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons)
{
    //method code
}

In our last example of a Java method signature, if you follow the same rules as the first two examples, you can see that the method signature here is calculateAnswer(double, int, double, double).

Format
mla apa chicago
Your Citation
Leahy, Paul. "What Does Method Signature Mean in Java?" ThoughtCo, Apr. 9, 2018, thoughtco.com/method-signature-2034235. Leahy, Paul. (2018, April 9). What Does Method Signature Mean in Java? Retrieved from https://www.thoughtco.com/method-signature-2034235 Leahy, Paul. "What Does Method Signature Mean in Java?" ThoughtCo. https://www.thoughtco.com/method-signature-2034235 (accessed May 21, 2018).