How To Get Bean Property Details In Java

Java API jabs java.bean package for working with the Java beans and its properties. In our previous example I have explained how to write bean PropertyChangeListener. This example is just an extension to that post and it provides the sample for getting the property method details. Lets look at the example.


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

 * Bean property details example
public class BeanPropertyDetails {
	public static void main(String[] args) {
		BeanInfo beanInfo = null;
		try {
			beanInfo = Introspector.getBeanInfo(Bean.class);
		} catch (IntrospectionException exception) {
		PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
		for (int i = 0; i < descriptors.length; i++) {
			String propName = descriptors[i].getName();
			Class<?> propType = descriptors[i].getPropertyType();
			System.out.println("Property with Name: " + propName
					+ " and Type: " + propType);



public class Bean {
	private int id;
	private String name;
	private String city;

	public int getId() {
		return id;

	public void setId(int id) { = id;

	public String getName() {
		return name;

	public void setName(String name) { = name;

	public String getCity() {
		return city;

	public void setCity(String city) { = city;


Property with Name: city and Type: class java.lang.String
Property with Name: class and Type: class java.lang.Class
Property with Name: id and Type: int
Property with Name: name and Type: class java.lang.String

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!