Method signature

Method signature

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. 

In another word -:

In Java, method signature consist of method names followed by arguments types. return type is not part of method signature in Java.

 E.g.-:

  public static int m(int x, float y){
 
 }

Compiler will use method signature to resolve methods calls.

class Test{
    public static void m1(int x, float y){
    }
    public static int  m2(String str){
    }
    public static int m3(double d){
    }
  public static void main(String... args){
      Test t=new Test();
       t.m1(10,13.4f);
       t.m2("Hello World !");
       t.m3(13.4);
       t.m4(); //compile time error : cannot find symbol : method m4() location in Test
  }
}
                class Test

        m1(int x, float y);

        m2(String str);

        m3(double d);

                method Table

Within a class to method with same signature, not allowed.
E.g.-:

class Test{
  public static void m(int x){
  
  }
  public static int m(int y){
    return y;
  }
public static void main(String... args){
     Test t=new Test();
      t.m(10);
}
}
//compile time error: m(int) already define in class Test

Basic description of overloading-:

Method overloading allows different methods to have the same name, but different signatures, where the signature can differ by the number of input parameters or type of input parameters, or a mixture of both.

Two method said to be overloaded if and only if both methods having same name but different argument types. 

    In C language-:
                               In the c language, method overloading concept is not available, hence we can't declare multiple methods with the same name but different argument types. If there is a change in argument type compulsory we should go for new method name which increases the complexity of programming.

E.g.-:
    abs(int);
    labs(long);
    fabs(float);


  In Java-:
                But in Java we can declare multiple method with same name but different argument types. Such type of methods are called overloaded methods. Having overloading concept in Java reduces complexity of programming. 


E.g.-:
    abs(int);
    abs(float);
    abs(long);


* In overloading method resolution always takes care by compiler based on reference type hence overloading is also consider as compile time polymorphism or static polymorphism or early binding. 

class Test{
  public static void m(int x){
      System.out.print(x);
  }
  public static void m(float y){
    System.out.print(y);
  }
 public static void m(String str){
     System.out.print(str);
  }
  public static void m(double d){
    System.out.print(d);
  }
public static void main(String... args){
     Test t=new Test();
      t.m(10);                                            //output is 10
      t.m(12.3f);                                        //output is 12.3
      t.m(12.3);                                        //output is 12.3
      t.m("Hello World!");                    // Hello World!
}
}