PropertyDescriptor Example in Java Program

PropertyDescriptor Example in Java

In this example, We will show you simple example program about, PropertyDescriptor Example in Java. The example program has been tested and shared in the same post.

POJO Class (Customer.class)

package com.dineshkrish;

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class Customer {

	private int id;
	private String name;
	private String phone;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public String toString() {
		return "Customer [id=" + id + ", name=" + name + ", phone=" + phone
				+ "]";
	}

}

Main Program (PropertyDescriptorExample.class)

package com.dineshkrish;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class PropertyDescriptorExample {

	public static void main(String[] args) throws IntrospectionException {

		PropertyDescriptor descriptor = new PropertyDescriptor("id", Customer.class);

		System.out.println("Property Name : "+descriptor.getName());
		System.out.println("Property Type : "+descriptor.getPropertyType());
		System.out.println("Property Setter Method : "+descriptor.getReadMethod());
		System.out.println("Property Getter Methog : "+descriptor.getWriteMethod());

	}
}

Output

Property Name : id
Property Type : int
Property Setter Method : public int com.dineshkrish.Customer.getId()
Property Getter Methog : public void com.dineshkrish.Customer.setId(int)

References

1. PropertyDescriptor Class

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.