Source Code : Listing the Property Names of a Bean

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Listing the Property Names of a Bean

    
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public class Main {
  public static void main(String[] argv) throws Exception {

    BeanInfo bi = Introspector.getBeanInfo(MyBean.class);
    PropertyDescriptor[] pds = bi.getPropertyDescriptors();
    for (int i = 0; i < pds.length; i++) {

      String propName = pds[i].getDisplayName();
      System.out.println(propName);
    }

  }
}

class MyBean {
  public String getProp1() {
    return null;
  }

  public void setProp1(String s) {
  }

  public int getProp2() {
    return 0;
  }

  public void setProp2(int i) {
  }

  public byte[] getPROP3() {
    return null;
  }

  public void setPROP3(byte[] bytes) {
  }
}

   
    
    
    
  

Thank with us