Home »
Java Programs »
Java Class and Object Programs
Java program to get the list of methods of a class
Java example to get the list of methods of a class.
Submitted by Nidhi, on May 06, 2022
Problem statement
In this program, we will get the list of methods of a class using the getMethods() method and print the result.
Source Code
The source code to get the list of methods of a class is given below. The given program is compiled and executed successfully.
// Java program to get the list of methods
// of a class
import java.lang.reflect.Method;
public class Main {
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 method: methods)
System.out.println(method);
}
}
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 static java.lang.String java.lang.Integer.toString(int,int)
public java.lang.String java.lang.Integer.toString()
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.reverseBytes(int)
public int java.lang.Integer.compareTo(java.lang.Object)
public int java.lang.Integer.compareTo(java.lang.Integer)
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 static int java.lang.Integer.compare(int,int)
public static int java.lang.Integer.reverse(int)
public static long java.lang.Integer.toUnsignedLong(int)
public static int java.lang.Integer.parseInt(java.lang.String) throws java.lang.NumberFormatException
public static int java.lang.Integer.parseInt(java.lang.String,int) 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.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 java.lang.String java.lang.Integer.toOctalString(int)
public static java.lang.String java.lang.Integer.toBinaryString(int)
public static int java.lang.Integer.parseUnsignedInt(java.lang.String,int) 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) 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 int java.lang.Integer.divideUnsigned(int,int)
public static int java.lang.Integer.remainderUnsigned(int,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 static int java.lang.Integer.signum(int)
public final native 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
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()
Explanation
In the above program, we created a public class Main that contains a main() method. The main() method is the entry point for the program.
In the main() method, we got the list of methods of the Integer class using the getMethods() method and printed the methods using the foreach loop.
Java Class and Object Programs »