Method Class | getName() Method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The getName() method of java.lang.reflect.Method class is helpful to get the name of methods, as a String. To get name of all methods of a class, get all the methods of that class object. Then call getName() on those method objects. Syntax: public String getName() Return Value: It returns the name of the method, as String. Example: Method:public void getValue(){} getName() returns: getValue Explanation: The getName() function on object of above method returns name of method which is getValue. Method:public void paint(){} getName() returns: paint Below programs illustrates getName() method of Method class: Example 1: Print name of all methods of Method Object. Java /* * Program Demonstrate how to apply getName() method * of Method Class. */ import java.lang.reflect.Method; public class GFG { // Main method public static void main(String[] args) { try { // create class object Class classobj = GFG.class; // get list of methods Method[] methods = classobj.getMethods(); // get the name of every method present in the list for (Method method : methods) { String MethodName = method.getName(); System.out.println("Name of the method: " + MethodName); } } catch (Exception e) { e.printStackTrace(); } } // method name setValue public static int setValue() { System.out.println("setValue"); return 24; } // method name getValue public String getValue() { System.out.println("getValue"); return "getValue"; } // method name setManyValues public void setManyValues() { System.out.println("setManyValues"); } } Output: Name of the method: main Name of the method: getValue Name of the method: setValue Name of the method: setManyValues Name of the method: wait Name of the method: wait Name of the method: wait Name of the method: equals Name of the method: toString Name of the method: hashCode Name of the method: getClass Name of the method: notify Name of the method: notifyAll Example 2: Program to check whether class contains a certain specific method. Java /* * Program Demonstrate how to apply getName() method * of Method Class within a class */ import java.lang.reflect.Method; public class GFG { // Main method public static void main(String[] args) { String checkMethod = "method1"; try { // create class object Class classobj = democlass.class; // get list of methods Method[] methods = classobj.getMethods(); // get the name of every method present in the list for (Method method : methods) { String MethodName = method.getName(); if (MethodName.equals(checkMethod)) { System.out.println("Class Object Contains" + " Method whose name is " + MethodName); } } } catch (Exception e) { e.printStackTrace(); } } } // a simple class class democlass { public int method1() { return 24; } public String method2() { return "Happy hours"; } public void method3() { System.out.println("Happy hours"); } } Output: Class Object Contains Method whose name is method1 Reference: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#getName-- Comment More infoAdvertise with us Next Article Method Class | getAnnotation() method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Method Class java-lang-reflect-package Practice Tags : Java Similar Reads Method Class | getModifiers() method in Java The java.lang.reflect.Method.getModifiers() method of Method class returns the modifiers for the method represented by this Method object. It returns int value. Then with the use Modifier class, the name of modifiers corresponding to that value is fetched. Syntax: public int getModifiers() Return Va 3 min read Method Class | getAnnotation() method in Java The java.lang.reflect.Method.getAnnotation(Class< T > annotationClass) method of Method class returns Method objects' annotation for the specified type passed as parameter if such an annotation is present, else null. This is important method to get annotation for Method object. Syntax: public 3 min read Method Class | getReturnType() Method in Java Prerequisite : Java.lang.Class class in Java | Set 1, Java.lang.Class class in Java | Set 2The java.lang.reflectMethod Class help in getting information of a single method on a class or interface. This class also provides access to the methods of classes and invoke them at runtime. The getReturnType 4 min read Method Class | equals() Method in Java The java.lang.reflect.Method.equals(Object obj) method of Method class compares this Method Object against the specified object as parameter to equal(object obj) method. This method returns true if the Method object is the same as the passed object. Two Methods are the same if they were declared by 3 min read Method Class | getTypeParameters() Method in Java The java.lang.reflect.Method.getTypeParameters() method of Method class returns an array of TypeVariable objects declared by the generic declaration of this Method object, in declaration order. Elements of array represent the type variables objects declared by Method. An array of length 0 is returne 4 min read Method Class | getParameterCount() method in Java The java.lang.reflect.Method.getParameterCount() method of Method class returns the number of parameters declared on a method Object. Syntax: public int getParameterCount() Return Value: This method returns number of formal parameters defined on this Method Object. Below programs illustrates getPara 3 min read Like