Definition of a Java Method Signature

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. "Definition of a Java Method Signature." ThoughtCo, Aug. 26, 2020, thoughtco.com/method-signature-2034235. Leahy, Paul. (2020, August 26). Definition of a Java Method Signature. Retrieved from https://www.thoughtco.com/method-signature-2034235 Leahy, Paul. "Definition of a Java Method Signature." ThoughtCo. https://www.thoughtco.com/method-signature-2034235 (accessed March 19, 2024).