InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Is Convertingwrapdynabean? |
|
Answer» Implementation of DynaBean that wraps a standard JAVABEAN instance, so that DynaBean APIs can be used to access its PROPERTIES, though this implementation allows type conversion to occur when properties are SET. Implementation of DynaBean that wraps a standard JavaBean instance, so that DynaBean APIs can be used to access its properties, though this implementation allows type conversion to occur when properties are set. |
|
| 2. |
What Is Contextclassloaderlocal<t>? |
|
Answer» An instance of this CLASS represents a value that is provided PER (THREAD) context classloader. An instance of this class represents a value that is provided per (thread) context classloader. |
|
| 3. |
What Is Constructorutils? |
|
Answer» Utility REFLECTION methods focussed on CONSTRUCTORS, MODELLED after MethodUtils. Utility reflection methods focussed on constructors, modelled after MethodUtils. |
|
| 4. |
What Is Beanutilsbean2? |
|
Answer» BEANUTILSBEAN implementation that CREATES a ConvertUtilsBean2 and delegates CONVERSION to ConvertUtilsBean.convert(OBJECT, Class). BeanUtilsBean implementation that creates a ConvertUtilsBean2 and delegates conversion to ConvertUtilsBean.convert(Object, Class). |
|
| 5. |
What Is Beanutilsbean? |
|
Answer» JAVABEAN PROPERTY POPULATION METHODS. JavaBean property population methods. |
|
| 6. |
What Is Beanutils? |
|
Answer» UTILITY METHODS for POPULATING JAVABEANS properties via reflection. Utility methods for populating JavaBeans properties via reflection. |
|
| 7. |
What Is Beantopropertyvaluetransformer? |
|
Answer» TRANSFORMER that OUTPUTS a PROPERTY VALUE. Transformer that outputs a property value. |
|
| 8. |
What Is Beanpropertyvalueequalspredicate? |
|
Answer» PREDICATE that EVALUATES a PROPERTY VALUE against a SPECIFIED value. Predicate that evaluates a property value against a specified value. |
|
| 9. |
What Is Beanpropertyvaluechangeclosure? |
|
Answer» Closure that sets a property. |
|
| 10. |
What Is Beanpredicate? |
|
Answer» Predicate implementation that APPLIES the given Predicate to the result of CALLING the given PROPERTY GETTER. Predicate implementation that applies the given Predicate to the result of calling the given property getter. |
|
| 12. |
What Is Beanmap? |
|
Answer» An implementation of MAP for JavaBeans which USES introspection to GET and put properties in the BEAN. An implementation of Map for JavaBeans which uses introspection to get and put properties in the bean. |
|
| 13. |
What Is Beancomparator<t>? |
|
Answer» This COMPARATOR compares two BEANS by the SPECIFIED bean PROPERTY. This comparator compares two beans by the specified bean property. |
|
| 14. |
What Is Basicdynaclass? |
|
Answer» MINIMAL IMPLEMENTATION of the DYNACLASS INTERFACE. Minimal implementation of the DynaClass interface. |
|
| 15. |
What Is Basicdynabean? |
|
Answer» MINIMAL IMPLEMENTATION of the DYNABEAN INTERFACE. Minimal implementation of the DynaBean interface. |
|
| 16. |
What Is Basedynabeanmapdecorator<k>? |
|
Answer» A BASE CLASS for DECORATORS PROVIDING MAP behavior on DynaBeans. A base class for decorators providing Map behavior on DynaBeans. |
|
| 17. |
What Is Mutabledynaclass? |
|
Answer» A SPECIALIZED EXTENSION to DynaClass that ALLOWS properties to be added or REMOVED dynamically. A specialized extension to DynaClass that allows properties to be added or removed dynamically. |
|
| 18. |
What Is Introspectioncontext? |
|
Answer» A context INTERFACE used during INTROSPECTION for querying and setting PROPERTY DESCRIPTORS. A context interface used during introspection for querying and setting property descriptors. |
|
| 19. |
What Is Dynaclass? |
|
Answer» A DynaClass is a SIMULATION of the FUNCTIONALITY of java.lang.Class for classes IMPLEMENTING the DynaBean INTERFACE. A DynaClass is a simulation of the functionality of java.lang.Class for classes implementing the DynaBean interface. |
|
| 20. |
What Is Dynabean? |
|
Answer» A DynaBean is a Java OBJECT that supports properties whose NAMES and data types, as well as values, MAY be dynamically MODIFIED. A DynaBean is a Java object that supports properties whose names and data types, as well as values, may be dynamically modified. |
|
| 21. |
What Is Converter? |
|
Answer» GENERAL purpose data type converter that can be registered and used within the BEANUTILS package to manage the CONVERSION of OBJECTS from one type to ANOTHER. General purpose data type converter that can be registered and used within the BeanUtils package to manage the conversion of objects from one type to another. |
|
| 22. |
What Is Beanintrospector? |
|
Answer» DEFINITION of an INTERFACE for components that can perform INTROSPECTION on bean classes. Definition of an interface for components that can perform introspection on bean classes. |
|
| 23. |
How Do I Set The Beancomparator Order To Be Ascending/descending? |
|
Answer» BeanComparator relies on an internal Comparator to perform the ACTUAL comparisions. By default, org.apache.commons.collections.comparators.ComparableComparator is USED which imposes a natural order. If you want to change the order, then a custom Comparator should be created and passed into the appropriate constructor. For example: import org.apache.commons.collections.comparators.ComparableComparator; BeanComparator relies on an internal Comparator to perform the actual comparisions. By default, org.apache.commons.collections.comparators.ComparableComparator is used which imposes a natural order. If you want to change the order, then a custom Comparator should be created and passed into the appropriate constructor. For example: import org.apache.commons.collections.comparators.ComparableComparator; |
|
| 24. |
Why Can't Beanutils Find My Method? |
|
Answer» The BEANUTILS package RELIES on introspection rather than reflection. This means that it will FIND only JavaBean compliant properties. There are some subtleties of this specification that can catch out the unwary:
The BeanUtils package relies on introspection rather than reflection. This means that it will find only JavaBean compliant properties. There are some subtleties of this specification that can catch out the unwary: |
|
| 25. |
Why Do I Get Classcastexception When Accessing Nested Maps? |
|
Answer» SAY you have a map which contains a NESTED map ala: nestedmap.put ("key2", "somevalue"); map.put ("key1", nestedmap); If you use the following syntax: String VAL = PropertyUtils.getProperty(bean, "map(key1)(key2)"); It will actually return "map(key1)", which will be a Map, not a String. BeanUtils uses '.' as a property separator, and the second property should actually USED mapped syntax, since it is directly accessing a map now, thus the correct USAGE should be: String val = PropertyUtils.getProperty(bean, "map(key1).key2"); Say you have a map which contains a nested map ala: nestedmap.put ("key2", "somevalue"); map.put ("key1", nestedmap); If you use the following syntax: String val = PropertyUtils.getProperty(bean, "map(key1)(key2)"); It will actually return "map(key1)", which will be a Map, not a String. BeanUtils uses '.' as a property separator, and the second property should actually used mapped syntax, since it is directly accessing a map now, thus the correct usage should be: String val = PropertyUtils.getProperty(bean, "map(key1).key2"); |
|
| 26. |
Do You Know That The Version Number In The Manifest.mf For Release 1.7 Is Wrong? |
|
Answer» Yes, we know. It says 1.6. So does RELEASE 1.6.1. Now the build system has MOVED to MAVEN that won't happen again. Yes, we know. It says 1.6. So does release 1.6.1. Now the build system has moved to Maven that won't happen again. |
|
| 27. |
Why Do I Get Conversionexception When Using Rowsetdynaclass With Oracle? |
|
Answer» Oracle's JDBC driver is broken. When a query is run against a table containing a Timestamp column, the result set's metadata reports the column TYPE (correctly) as javax.sql.Timestamp. And therefore the DynaClass object created to represent the query has a field of type javax.sql.Timestamp to store the data for that column in. However calling resultset.getObject on that column returns an object of type javax.sql.Date(!), which then of course cannot be assigned to the corresponding field on a DynaBean object with that DynaClass. This has been reported with Oracle10g, driver ojdbc14 version 10.1.0.4. POSSIBLE solutions (untested) are:
Oracle's JDBC driver is broken. When a query is run against a table containing a Timestamp column, the result set's metadata reports the column type (correctly) as javax.sql.Timestamp. And therefore the DynaClass object created to represent the query has a field of type javax.sql.Timestamp to store the data for that column in. However calling resultset.getObject on that column returns an object of type javax.sql.Date(!), which then of course cannot be assigned to the corresponding field on a DynaBean object with that DynaClass. This has been reported with Oracle10g, driver ojdbc14 version 10.1.0.4. Possible solutions (untested) are: |
|
| 28. |
How Can I Customise Conversions From Type X To String? |
|
Answer» Sorry, but ConvertUtils isn't really designed to do that. It is fundamentally about MAPPING strings (from XML input or web forms, etc) to objects. The standard converter to the String type simply calls toString on its input object, so you can customise the output for objects of any PARTICULAR class by modifying the toString method of that class. Or you could replace the converter for target type String.class with a custom converter which inspects the type of the object and does a BIG switch statement. Or maybe even look up a mapping table of subconverter objects BASED on the type of the object being converted. But in general if you need to do this, then ConvertUtils is probably the wrong tool for your job. You might like to look at morph.sourceforge.net, google for alternatives or craft your own solution. Sorry, but ConvertUtils isn't really designed to do that. It is fundamentally about mapping strings (from xml input or web forms, etc) to objects. The standard converter to the String type simply calls toString on its input object, so you can customise the output for objects of any particular class by modifying the toString method of that class. Or you could replace the converter for target type String.class with a custom converter which inspects the type of the object and does a big switch statement. Or maybe even look up a mapping table of subconverter objects based on the type of the object being converted. But in general if you need to do this, then ConvertUtils is probably the wrong tool for your job. You might like to look at morph.sourceforge.net, google for alternatives or craft your own solution. |
|
| 29. |
How Can I Customise The Conversion? |
|
Answer» If you don't like the default way beanutils converts strings to various datatypes, then SIMPLY register a custom converter. So for example if you would like whitespace to be ignored when converting strings to NUMERIC values, then create your own converter classes and register them with ConvertUtils for the datatypes you want to be AFFECTED. Note that in this case it would be easier to write a generic "filter" class that wraps the existing converters rather than create NEW converters classes: private STATIC class WhiteSpaceConverterFilter implements Converter { public Object convert(Class clazz, Object value) { ConvertUtils.register(new WhiteSpaceConverterFilter(new IntegerConverter()), Integer.TYPE); ConvertUtils.register(new WhiteSpaceConverterFilter(new IntegerConverter(), Integer.class); ConvertUtils.register(new WhiteSpaceConverterFilter(new LongConverter()), Long.TYPE); ConvertUtils.register(new WhiteSpaceConverterFilter(new LongConverter()), Long.class); .... If you don't like the default way beanutils converts strings to various datatypes, then simply register a custom converter. So for example if you would like whitespace to be ignored when converting strings to numeric values, then create your own converter classes and register them with ConvertUtils for the datatypes you want to be affected. Note that in this case it would be easier to write a generic "filter" class that wraps the existing converters rather than create new converters classes: private static class WhiteSpaceConverterFilter implements Converter { public Object convert(Class clazz, Object value) { ConvertUtils.register(new WhiteSpaceConverterFilter(new IntegerConverter()), Integer.TYPE); ConvertUtils.register(new WhiteSpaceConverterFilter(new IntegerConverter(), Integer.class); ConvertUtils.register(new WhiteSpaceConverterFilter(new LongConverter()), Long.TYPE); ConvertUtils.register(new WhiteSpaceConverterFilter(new LongConverter()), Long.class); .... |
|
| 30. |
How Can I Correctly Convert Locale-specific Input? |
|
Answer» If your code is directly calling conversion-related methods on ConvertUtils/ConvertUtilsBean to do data conversion, then you can simply change to using LocaleBeanUtils/LocaleBeanUtilsBean/LocaleConvertUtils/LocaleConvertUtilsBean instead. The Locale-aware classes will automatically detect the locale of the host machine and set up appropriate CONVERTERS for that locale. Alternatively you can explicitly create LocaleConvertUtilsBean instances providing a particular locale. If your code is calling the property-related methods on BeanUtils/BeanUtilsBean methods, and you want the automatic type conversion facilities used to be locale-aware then you might want to look at using the equivalent methods on the LocaleBeanUtils or LocaleBeanUtilsBean classes. However because the property-related methods on these classes are not used nearly as often as the property methods on the standard (non-locale-aware) classes, they MAY not be as well debugged and some FEATURES may be missing. A safer alternative to either of the above is to REGISTER custom locale-aware converters with ConvertUtils or ConvertUtilsBean: LongLocaleConverter longLocaleConverter = new LongLocaleConverter(Locale.GERMAN); Of course the above will modify the default behaviour across the entire current application (or the current webapp if the code is running in a container environment; see the javadoc for method BeanUtils.getInstance for more information). If you do not LIKE the idea of changing the ConvertUtils/BeanUtils behaviour so widely, then of course you can always create a BeanUtilsBean instance and customise only the behaviour of that instance: ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); If your code is directly calling conversion-related methods on ConvertUtils/ConvertUtilsBean to do data conversion, then you can simply change to using LocaleBeanUtils/LocaleBeanUtilsBean/LocaleConvertUtils/LocaleConvertUtilsBean instead. The Locale-aware classes will automatically detect the locale of the host machine and set up appropriate converters for that locale. Alternatively you can explicitly create LocaleConvertUtilsBean instances providing a particular locale. If your code is calling the property-related methods on BeanUtils/BeanUtilsBean methods, and you want the automatic type conversion facilities used to be locale-aware then you might want to look at using the equivalent methods on the LocaleBeanUtils or LocaleBeanUtilsBean classes. However because the property-related methods on these classes are not used nearly as often as the property methods on the standard (non-locale-aware) classes, they may not be as well debugged and some features may be missing. A safer alternative to either of the above is to register custom locale-aware converters with ConvertUtils or ConvertUtilsBean: LongLocaleConverter longLocaleConverter = new LongLocaleConverter(Locale.GERMAN); Of course the above will modify the default behaviour across the entire current application (or the current webapp if the code is running in a container environment; see the javadoc for method BeanUtils.getInstance for more information). If you do not like the idea of changing the ConvertUtils/BeanUtils behaviour so widely, then of course you can always create a BeanUtilsBean instance and customise only the behaviour of that instance: ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); |
|
| 31. |
Why Isn't String -> Date Conversion Provided By Default? |
|
Answer» SIMPLY because DIFFERENT regions of the world use different date LAYOUTS. There isn't any date format that is a reasonable built-in default.
If you want BeanUtils to do implicit String->Date conversions for you, then you just need to register a SUITABLE converter for the date formats you expect to encounter in your input. Simply because different regions of the world use different date layouts. There isn't any date format that is a reasonable built-in default. If you want BeanUtils to do implicit String->Date conversions for you, then you just need to register a suitable converter for the date formats you expect to encounter in your input. |
|