how-to

Classes

How to list classes fields and methods

For this example you need:

import java.lang.reflect.Field;
import java.lang.reflect.Method;

For writing classes fields and methods, use this code:

try {
  /* get class */

  Class c = Class.forName( "java.io.File" );

  /* -- write class fields */

  System.out.println( "FIELDS\n" );

  Field fields[] = c.getFields();

  for (int i = 0; i < fields.length; i++) {
    System.out.println( fields[i].toString() );
  }

  /* -- write class methods */

  System.out.println( "\nMETHODS\n" );

  Method methods[] = c.getMethods();

  for (int i = 0; i < methods.length; i++) {
    System.out.println( methods[i].toString() );
  }

} catch ( ClassNotFoundException ex ) {
  Logger.getLogger( Window.class.getName() ).log( Level.SEVERE, null, ex );
}

The output could be (depends on used JDK version):

FIELDS

public static final char java.io.File.separatorChar
public static final java.lang.String java.io.File.separator
public static final char java.io.File.pathSeparatorChar
public static final java.lang.String java.io.File.pathSeparator

METHODS

public int java.io.File.hashCode()
public boolean java.io.File.equals(java.lang.Object)
public java.lang.String java.io.File.toString()
public java.lang.String java.io.File.getName()
public int java.io.File.compareTo(java.io.File)
public int java.io.File.compareTo(java.lang.Object)
public long java.io.File.length()
public java.lang.String java.io.File.getCanonicalPath() throws java.io.IOException
public java.lang.String java.io.File.getParent()
public boolean java.io.File.isAbsolute()
public boolean java.io.File.setReadOnly()
public java.lang.String[] java.io.File.list()
public java.lang.String[] java.io.File.list(java.io.FilenameFilter)
public boolean java.io.File.delete()
public boolean java.io.File.exists()
public java.lang.String java.io.File.getPath()
public boolean java.io.File.canExecute()
public boolean java.io.File.canRead()
public boolean java.io.File.canWrite()
public boolean java.io.File.createNewFile() throws java.io.IOException
public static java.io.File java.io.File.createTempFile(java.lang.String,java.lang.String) throws java.io.IOException
public static java.io.File java.io.File.createTempFile(java.lang.String,java.lang.String,java.io.File) throws java.io.IOException
public void java.io.File.deleteOnExit()
public java.io.File java.io.File.getAbsoluteFile()
public java.lang.String java.io.File.getAbsolutePath()
public java.io.File java.io.File.getCanonicalFile() throws java.io.IOException
public long java.io.File.getFreeSpace()
public java.io.File java.io.File.getParentFile()
public long java.io.File.getTotalSpace()
public long java.io.File.getUsableSpace()
public boolean java.io.File.isDirectory()
public boolean java.io.File.isFile()
public boolean java.io.File.isHidden()
public long java.io.File.lastModified()
public java.io.File[] java.io.File.listFiles()
public java.io.File[] java.io.File.listFiles(java.io.FileFilter)
public java.io.File[] java.io.File.listFiles(java.io.FilenameFilter)
public static java.io.File[] java.io.File.listRoots()
public boolean java.io.File.mkdir()
public boolean java.io.File.mkdirs()
public boolean java.io.File.renameTo(java.io.File)
public boolean java.io.File.setExecutable(boolean,boolean)
public boolean java.io.File.setExecutable(boolean)
public boolean java.io.File.setLastModified(long)
public boolean java.io.File.setReadable(boolean)
public boolean java.io.File.setReadable(boolean,boolean)
public boolean java.io.File.setWritable(boolean,boolean)
public boolean java.io.File.setWritable(boolean)
public java.nio.file.Path java.io.File.toPath()
public java.net.URI java.io.File.toURI()
public java.net.URL java.io.File.toURL() throws java.net.MalformedURLException
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,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException

This example shows public fiedls and methods only. For showing all fields/methods use functions Class.getDeclaredFields() / Class.getDeclaredMethods().