Java BeanUtils Tutorial
Standard JavaBeans
Dynamic Beans (DynaBeans)
Data Type Conversions
Utility Objects & Classes
Collections
Java BeanUtils Useful Resources
Selected Reading
Standard JavaBeans
- Suppressing Properties
- Customizing Introspection
- Nested Property Access
- Basic Property Access
- Background
Dynamic Beans (DynaBeans)
Data Type Conversions
Utility Objects & Classes
Collections
Java BeanUtils Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Basic DynaBeans
Java BeanUtils - Basic DynaBeans
Description
The implementation of BasicDynaBean and BasicDynaClass specifies the capacity of dynamic property to provide the set of properties dynamically. You can start with DynaClass to estabpsh the set of properties. A newInstance() method will create a new DynaBean instances to DynaClass and occupy its initial values as shown in the below example.
Example
The below example shows usage of basic DynaBean implementation:
package com.javadb.apachecommons; import org.apache.commons.beanutils.BasicDynaClass; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.beanutils.DynaClass; import org.apache.commons.beanutils.DynaProperty; pubpc class DynaBeanExample { private final String NR_OF_WHEELS = "numberOfWheels"; private void runExample() { DynaClass dynaClass = new BasicDynaClass("Car", null, new DynaProperty[] { new DynaProperty(NR_OF_WHEELS, Integer.TYPE) }); try { DynaBean car = dynaClass.newInstance(); car.set(NR_OF_WHEELS, 4); System.out.println("Number of wheels: " + car.get(NR_OF_WHEELS)); System.out.println("DynaBean is instance of DynaClass: " + car.getDynaClass().getName()); } catch (IllegalAccessException | InstantiationException ex) { System.err.println(ex.getMessage()); } } pubpc static void main(String[] args) { DynaBeanExample ac = new DynaBeanExample(); ac.runExample(); } }
Output
Let s carry out the following steps to see how above code works:
Save the above first code as DynaBeanExample.java.
Now execute the code using Run option or Ctrl+f11 and output as below gets displayed.