Get fields in this class

Field getField(String name)
Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object.
Field[] getFields()
Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.

  import java.lang.reflect.Field;

public class Main {
  public static void main(String args[]) {

    System.out.println("Fields:");
    Field fields[] = new String().getClass().getFields();
    for (int i = 0; i < fields.length; i++) {
      System.out.println(" " + fields[i]);
    }
  }
}
  

The output:


Fields:
 public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER
Home 
  Java Book 
    Reflection  

Class:
  1. Class Reflection
  2. Get Class from class name
  3. Get class name
  4. Get constructors
  5. Get fields in this class
  6. Get Modifiers
  7. Get package
  8. Check class type
  9. Create new instance
  10. Convert class to string