The source code to get the list of fields of a class is given below. The given program is compiled and executed successfully.
// Java program to get the list of fields
// of a class
import java.lang.reflect.Field;
public class Main {
public static void main(String[] args) throws ClassNotFoundException {
Class cls = Class.forName("java.lang.Double");
Field fields[] = cls.getFields();
System.out.println("Fields of Double class: ");
for (Field field: fields)
System.out.println(field);
}
}
Output:
Fields of Double class:
public static final double java.lang.Double.POSITIVE_INFINITY
public static final double java.lang.Double.NEGATIVE_INFINITY
public static final double java.lang.Double.NaN
public static final double java.lang.Double.MAX_VALUE
public static final double java.lang.Double.MIN_NORMAL
public static final double java.lang.Double.MIN_VALUE
public static final int java.lang.Double.MAX_EXPONENT
public static final int java.lang.Double.MIN_EXPONENT
public static final int java.lang.Double.SIZE
public static final int java.lang.Double.BYTES
public static final java.lang.Class java.lang.Double.TYPE
Program/Source Code:
The source code to get the list of fields of a class is given below. The given program is compiled and executed successfully.
Output: