Write a Java program to get the list of methods of a class


This is a Java program that demonstrates how to list all the methods of a class using the getMethods() method of the Class class.

In the main() method, the program uses the Class.forName() method to get the Class object associated with the java.lang.Integer class.

The program then uses the getMethods() method of the Class object to get an array of all the public methods of the Integer class. This method returns an array of Method objects that represent the public methods of the class.

The program then uses a for loop to iterate through the array of Method objects and print each method to the console using the println() method. When the program is run, it will output a list of all the public methods of the Integer class to the console.

Source Code

import java.lang.reflect.Method;
public class ListMethods
{
	public static void main(String[] args) throws ClassNotFoundException
	{
		Class cls = Class.forName("java.lang.Integer");
 
		Method methods[] = cls.getMethods();
 
		System.out.println("Methods of Integer class: ");
		for (Method m: methods)
		{
			System.out.println(m);
		}
	}
}

Output

Methods of Integer class:
public static int java.lang.Integer.numberOfLeadingZeros(int)
public static int java.lang.Integer.numberOfTrailingZeros(int)
public static int java.lang.Integer.bitCount(int)
public boolean java.lang.Integer.equals(java.lang.Object)
public static java.lang.String java.lang.Integer.toString(int)
public java.lang.String java.lang.Integer.toString()
public static java.lang.String java.lang.Integer.toString(int,int)
public static int java.lang.Integer.hashCode(int)
public int java.lang.Integer.hashCode()
public static int java.lang.Integer.min(int,int)
public static int java.lang.Integer.max(int,int)
public static int java.lang.Integer.signum(int)
public static int java.lang.Integer.expand(int,int)
public static int java.lang.Integer.divideUnsigned(int,int)
public static int java.lang.Integer.remainderUnsigned(int,int)
public static int java.lang.Integer.reverseBytes(int)
public static int java.lang.Integer.compress(int,int)
public int java.lang.Integer.compareTo(java.lang.Object)
public int java.lang.Integer.compareTo(java.lang.Integer)
public static int java.lang.Integer.compare(int,int)
public byte java.lang.Integer.byteValue()
public short java.lang.Integer.shortValue()
public int java.lang.Integer.intValue()
public long java.lang.Integer.longValue()
public float java.lang.Integer.floatValue()
public double java.lang.Integer.doubleValue()
public static java.lang.Integer java.lang.Integer.valueOf(int)
public static java.lang.Integer java.lang.Integer.valueOf(java.lang.String,int) throws java.lang.NumberFormatException
public static java.lang.Integer java.lang.Integer.valueOf(java.lang.String) throws java.lang.NumberFormatException
public static java.lang.String java.lang.Integer.toHexString(int)
public static java.lang.Integer java.lang.Integer.decode(java.lang.String) throws java.lang.NumberFormatException
public java.lang.Integer java.lang.Integer.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup)
public java.lang.Object java.lang.Integer.resolveConstantDesc(java.lang.invoke.MethodHandles$Lookup) throws java.lang.ReflectiveOperationException
public java.util.Optional java.lang.Integer.describeConstable()
public static int java.lang.Integer.parseInt(java.lang.String,int) throws java.lang.NumberFormatException
public static int java.lang.Integer.parseInt(java.lang.String) throws java.lang.NumberFormatException
public static int java.lang.Integer.parseInt(java.lang.CharSequence,int,int,int) throws java.lang.NumberFormatException
public static int java.lang.Integer.reverse(int)
public static long java.lang.Integer.toUnsignedLong(int)
public static int java.lang.Integer.sum(int,int)
public static int java.lang.Integer.compareUnsigned(int,int)
public static java.lang.String java.lang.Integer.toUnsignedString(int,int)
public static java.lang.String java.lang.Integer.toUnsignedString(int)
public static int java.lang.Integer.parseUnsignedInt(java.lang.String) throws java.lang.NumberFormatException
public static int java.lang.Integer.parseUnsignedInt(java.lang.CharSequence,int,int,int) throws java.lang.NumberFormatException
public static int java.lang.Integer.parseUnsignedInt(java.lang.String,int) throws java.lang.NumberFormatException
public static java.lang.Integer java.lang.Integer.getInteger(java.lang.String,java.lang.Integer)
public static java.lang.Integer java.lang.Integer.getInteger(java.lang.String,int)
public static java.lang.Integer java.lang.Integer.getInteger(java.lang.String)
public static java.lang.String java.lang.Integer.toOctalString(int)
public static java.lang.String java.lang.Integer.toBinaryString(int)
public static int java.lang.Integer.highestOneBit(int)
public static int java.lang.Integer.lowestOneBit(int)
public static int java.lang.Integer.rotateLeft(int,int)
public static int java.lang.Integer.rotateRight(int,int)
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public final void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException