Java Method Signature

In this Java article we want to learn about Java Method Signature, In Java method signature is a unique identifier that distinguishes one method from another. it consists of the method name, its parameter list and its return type. 

 

 

Now let’s talk about Java method signature.

 

Method Name

Method name is the identifier used to call the method. it is typically written in camelCase and should be descriptive name that accurately reflects what the method does.

 

Parameter List

Parameter list is a comma separated list of parameters that the method takes as input. each parameter includes its data type, followed by its name. if the method does not take any parameters, than parameter list is empty. for example this method signature takes two parameters of type int and String.

 

 

Return Type

return type specifies type of value that the method returns when it is called. if the method does not return anything, return type is void. for example this method signature returns a value of type int.

 

 

These are some examples of Java method signatures.

 

 

Method Overloading

In Java method overloading allows developers to define multiple methods with the same name, but with different parameter lists. this is possible because the method signature includes both the method name and its parameter list. for example we can have two methods with the same name printDetails(), but with different parameter lists:

In the above example two methods have the same name, but different parameter lists. this allows us to use the same method name for related methods and makes the code more readable and maintainable.

 

 

This is practical example

In this examplem we have a method named calculateSum that takes two integer parameters num1 and num2. this method returns an integer value, which is the sum of num1 and num2. 

 

 

This will be the result

Java Method Signature
Java Method Signature

 

 

Learn More

Leave a Comment