YouTube Icon

Interview Questions.

Top 31 Java Bean Utils Interview Questions - Jul 26, 2022

fluid

Top 31 Java Bean Utils Interview Questions

Q1. What Is Beantopropertyvaluetrformer?

Trformer that outputs a assets cost.

Q2. What Is Beanutilsbean2?

BeanUtilsBean implementation that creates a ConvertUtilsBean2 and delegates conversion to ConvertUtilsBean.Convert(Object, Class).

Q3. How Can I Correctly Convert Locale-unique Input?

If your code is directly calling conversion-associated methods on ConvertUtils/ConvertUtilsBean to do information conversion, then you could truely exchange to the use of LocaleBeanUtils/LocaleBeanUtilsBean/LocaleConvertUtils/LocaleConvertUtilsBean as a substitute. The Locale-conscious training will routinely discover the locale of the host device and set up appropriate converters for that locale. Alternatively you can explicitly create LocaleConvertUtilsBean instances supplying a specific locale.

If your code is calling the belongings-related strategies on BeanUtils/BeanUtilsBean methods, and you want the automatic kind conversion centers used to be locale-aware then you definately may want to study using the equivalent techniques on the LocaleBeanUtils or LocaleBeanUtilsBean lessons. However due to the fact the belongings-associated strategies on those instructions are not used nearly as regularly as the belongings methods on the same old (non-locale-aware) training, they may not be as nicely debugged and a few features can be lacking.

A more secure opportunity to both of the above is to check in custom locale-aware converters with ConvertUtils or ConvertUtilsBean:

  LongLocaleConverter  longLocaleConverter = new LongLocaleConverter(Locale.GERMAN);

  ConvertUtils.Check in(longLocaleConverter, Long.Magnificence);

  // now any call to any approach at the BeanUtils or ConvertUtils training which involves 

  // changing a string to a Long object will use a LongLocaleConverter that is customised 

  // to deal with the German locale.

Of direction the above will alter the default behaviour across the whole cutting-edge application (or the modern-day webapp if the code is going for walks in a box surroundings; see the javadoc for technique BeanUtils.GetInstance for greater records).

If you do no longer just like the idea of changing the ConvertUtils/BeanUtils behaviour so extensively, then of route you can usually create a BeanUtilsBean example and customise handiest the behaviour of that instance:

  ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();

  // here, customize the convertUtilsBean as required by using registering custom converters

  PropertyUtilsBean propertyUtilsBean = new propertyUtilsBean();

  BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean, propertyUtilsBean);

  // now techniques on the beanUtilsBean object will use the custom converters registered

  // on the associated ConvertUtilsBean example.

Q4. What Is Dynabean?

A DynaBean is a Java object that supports homes whose names and facts kinds, as well as values, may be dynamically modified.

Q5. How Do I Set The Beancomparator Order To Be Ascending/descending?

BeanComparator relies on an inner Comparator to carry out the real comparisions. By default, org.Apache.Commons.Collections.Comparators.ComparableComparator is used which imposes a herbal order. If you need to alternate the order, then a custom Comparator must be created and surpassed into an appropriate constructor.

For instance:

     import org.Apache.Commons.Collections.Comparators.ComparableComparator;

     import org.Apache.Commons.Collections.Comparators.ReverseComparator;

     import org.Apache.Commons.Beanutils.BeanComparator;

     ...

     BeanComparator reversedNaturalOrderBeanComparator

         = new BeanComparator("propertyName", new ReverseComparator(new ComparableComparator()));

     Collections.Kind(myList, reversedNaturalOrderBeanComparator);

Q6. Why Isn't String -> Date Conversion Provided By Default?

Simply because extraordinary regions of the arena use exclusive date layouts. There isn't always any date layout that is a reasonable built-in default.

USA: mm-dd-yyyy, mm/dd/yyyy

Europe/Pacific: dd-mm-yyyy

Other popular formats: yyyy-mm-dd, yyyymmdd

If you want BeanUtils to do implicit String->Date conversions for you, then you definitely just need to sign up a suitable converter for the date codecs you expect to come upon on your enter.

Q7. What Is Basicdynabean?

Minimal implementation of the DynaBean interface.

Q8. What Is Beanintrospector?

Definition of an interface for additives which can carry out introspection on bean lessons.

Q9. Why Do I Get Classcastexception When Accessing Nested Maps?

Say you have a map which includes a nested map ala: nestedmap.Placed ("key2", "somevalue"); map.Put ("key1", nestedmap);

If you operate the following syntax: String val = PropertyUtils.GetProperty(bean, "map(key1)(key2)");

It will honestly go back "map(key1)", so one can be a Map, now not a String.

BeanUtils uses '.' as a belongings separator, and the second one assets need to truely used mapped syntax, considering that it's far at once gaining access to a map now, accordingly the precise usage must be: String val = PropertyUtils.GetProperty(bean, "map(key1).Key2");

Q10. Do You Know That The Version Number In The Manifest.Mf For Release 1.7 Is Wrong?

Yes, we realize. It says 1.@So does launch 1.6.1.

Now the build gadget has moved to Maven that may not show up once more.

Q11. What Is Beanutilsbean?

JavaBean belongings populace techniques.

Q12. What Is Dynaclass?

A DynaClass is a simulation of the functionality of java.Lang.Class for training implementing the DynaBean interface.

Q13. Why Do I Get Conversionexception When Using Rowsetdynaclass With Oracle?

Oracle's JDBC driver is broken. When a query is administered in opposition to a desk containing a Timestamp column, the end result set's metadata reports the column type (successfully) as javax.Sq..Timestamp. And therefore the DynaClass object created to represent the query has a area of type javax.Square.Timestamp to store the facts for that column in. However calling resultset.GetObject on that column returns an object of type javax.Sq..Date(!), which then of direction can't be assigned to the corresponding area on a DynaBean object with that DynaClass.

This has been pronounced with Oracle10g, driver ojdbc14 model 10.1.Zero.Four.

Possible solutions (untested) are:

subclass RowSetDynaClass and override the replica technique to fudge the conversion.

Subclass BasicDynaBean and override the set method to address the problem, then subclass RowSetDynaClass and override createDynaBean to return times of your custom bean that handles damaged Oracle resultsets.

Q14. What Is Convertingwrapdynabean?

Implementation of DynaBean that wraps a fashionable JavaBean instance, so that DynaBean APIs can be used to get admission to its residences, even though this implementation allows type conversion to occur when homes are set.

Q15. What Is Basicdynaclass?

Minimal implementation of the DynaClass interface.

Q16. What Is Beanpropertyvalueequalspredicate?

Predicate that evaluates a property price towards a unique fee.

Q17. What Is Basedynabeanmapdecorator<k>?

A base class for decorators supplying Map conduct on DynaBe.

Q18. What Is Introspectioncontext?

A context interface used at some stage in introspection for querying and placing belongings descriptors.

Q19. What Is Constructorutils?

Utility reflection strategies focussed on constructors, modelled after MethodUtils.

Q20. What Is Mutabledynaclass?

A specialised extension to DynaClass that permits properties to be brought or eliminated dynamically.

Q21. What Is Beanpropertyvaluechangeclosure?

Closure that units a property.

Q22. What Is Beanpredicate?

Predicate implementation that applies the given Predicate to the result of calling the given assets getter.

Q23. What Is Converter?

General cause information type converter that may be registered and used within the BeanUtils package to manage the conversion of gadgets from one type to another.

Q24. What Is Beanutils?

Utility strategies for populating JavaBe properties via reflection.

Q25. How Can I Customise Conversions From Type X To String?

Sorry, but ConvertUtils is not clearly designed to do this. It is basically approximately mapping strings (from xml enter or net forms, and so on) to objects.

The standard converter to the String kind simply calls toString on its input object, so you can customise the output for objects of any particular magnificence by means of modifying the toString method of that class.

Or you could update the converter for goal type String.Class with a custom converter which inspects the kind of the object and does a big transfer declaration. Or perhaps even appearance up a mapping table of subconverter gadgets primarily based at the sort of the item being transformed.

But in popular if you need to do this, then ConvertUtils might be the wrong tool in your task. You might want to study morph.Sourceforge.Internet, google for options or craft your personal solution.

Q26. How Can I Customise The Conversion?

If you do not like the default way beanutils converts strings to various datatypes, then without a doubt sign in a custom converter.

So as an instance in case you would really like whitespace to be disregarded while changing strings to numeric values, then create your very own converter training and sign up them with ConvertUtils for the datatypes you want to be affected. Note that during this case it might be less complicated to write down a normal "clear out" elegance that wraps the existing converters instead of create new converters training:

  non-public static elegance WhiteSpaceConverterFilter implements Converter 

    Converter delegate;

    public WhiteSpaceConverterFilter(Converter delegate) 

      this.Delegate = delegate;

    

    public Object convert(Class clazz, Object price) 

      if (value instanceof String) 

        go back delegate.Convert(clazz, fee.ToString().Trim());

       else 

        go back delegate.Convert(clazz, price);

      

    

  

  ConvertUtils.Check in(new WhiteSpaceConverterFilter(new IntegerConverter()), Integer.TYPE);

  ConvertUtils.Sign in(new WhiteSpaceConverterFilter(new IntegerConverter(), Integer.Class);

  ConvertUtils.Check in(new WhiteSpaceConverterFilter(new LongConverter()), Long.TYPE);

  ConvertUtils.Register(new WhiteSpaceConverterFilter(new LongConverter()), Long.Elegance);

  ....

Q27. What Is Contextclassloaderlocal<t>?

An instance of this magnificence represents a price that is supplied in keeping with (thread) context classloader.

Q28. What Is Beancomparator<t>?

This comparator compares  be through the specified bean assets.

Q29. What Is Beanmap.Access?

Map entry used by BeanMap.

Q30. What Is Beanmap?

An implementation of Map for JavaBe which makes use of introspection to get and put houses inside the bean.

Q31. Why Can't Beanutils Find My Method?

The BeanUtils package relies on introspection as opposed to mirrored image. This me that it's going to discover most effective JavaBean compliant properties.

There are some subtleties of this specification which could capture out the unwary:

A assets could have simplest one set and one get method. Overloading isn't allowed.

The java.Be.Introspector searches extensively for a custom BeanInfo magnificence. If your class has the identical call as any other with a custom BeanInfo (commonly a java API class) then the Introspector may use that in place of creating via reflection based totally for your class. If this takes place, the best answer is to create your personal BeanInfo.




CFG