Question 1. Why Isn't String -> Date Conversion Provided By Default?
Simply due to the fact special regions of the world use distinctive date layouts. There isn't any date format that may be a reasonable built-in default.
USA: mm-dd-yyyy, mm/dd/yyyy
Other popular formats: yyyy-mm-dd, yyyymmdd
If you need BeanUtils to do implicit String->Date conversions for you, then you definitely simply want to sign in a suitable converter for the date codecs you count on to come upon to your enter.
Question 2. How Can I Correctly Convert Locale-specific Input?
If your code is without delay calling conversion-associated methods on ConvertUtils/ConvertUtilsBean to do records conversion, then you could without a doubt exchange to the usage of LocaleBeanUtils/LocaleBeanUtilsBean/LocaleConvertUtils/LocaleConvertUtilsBean alternatively. The Locale-aware training will mechanically hit upon the locale of the host system and installation suitable converters for that locale. Alternatively you may explicitly create LocaleConvertUtilsBean times supplying a particular locale.
If your code is asking the belongings-related techniques on BeanUtils/BeanUtilsBean techniques, and also you need the automatic kind conversion centers was locale-aware then you might want to take a look at the use of the equal strategies at the LocaleBeanUtils or LocaleBeanUtilsBean lessons. However due to the fact the assets-associated techniques on those training aren't used almost as frequently as the property methods on the usual (non-locale-aware) training, they may not be as nicely debugged and some functions can be missing.
A safer opportunity to either of the above is to check in custom locale-conscious converters with ConvertUtils or ConvertUtilsBean:
LongLocaleConverter longLocaleConverter = new LongLocaleConverter(Locale.GERMAN);
// now any call to any method on the BeanUtils or ConvertUtils training which entails
// converting a string to a Long item will use a LongLocaleConverter which is customised
// to handle the German locale.
Of route the above will alter the default behaviour throughout the entire cutting-edge application (or the current webapp if the code is jogging in a container environment; see the javadoc for method BeanUtils.GetInstance for extra facts).
If you do no longer like the idea of changing the ConvertUtils/BeanUtils behaviour so widely, then of course you may always create a BeanUtilsBean instance and customise handiest the behaviour of that instance:
ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
// right here, customise the convertUtilsBean as required with the aid of registering custom converters
PropertyUtilsBean propertyUtilsBean = new propertyUtilsBean();
BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean, propertyUtilsBean);
// now strategies on the beanUtilsBean object will use the custom converters registered
// on the related ConvertUtilsBean instance.
Adv Java Interview Questions
Question 3. How Can I Customise The Conversion?
If you don't just like the default manner beanutils converts strings to various datatypes, then really sign in a custom converter.
So as an example if you would love whitespace to be disregarded while converting strings to numeric values, then create your personal converter instructions and sign in them with ConvertUtils for the datatypes you need to be affected. Note that during this case it'd be easier to put in writing a popular "filter out" elegance that wraps the existing converters as opposed to create new converters instructions:
private static class WhiteSpaceConverterFilter implements Converter
public WhiteSpaceConverterFilter(Converter delegate)
this.Delegate = delegate;
public Object convert(Class clazz, Object value)
if (fee instanceof String)
return delegate.Convert(clazz, fee.ToString().Trim());
return delegate.Convert(clazz, cost);
ConvertUtils.Sign in(new WhiteSpaceConverterFilter(new IntegerConverter()), Integer.TYPE);
ConvertUtils.Sign in(new WhiteSpaceConverterFilter(new IntegerConverter(), Integer.Elegance);
ConvertUtils.Sign up(new WhiteSpaceConverterFilter(new LongConverter()), Long.TYPE);
ConvertUtils.Sign up(new WhiteSpaceConverterFilter(new LongConverter()), Long.Magnificence);
Question four. How Can I Customise Conversions From Type X To String?
Sorry, however ConvertUtils isn't always definitely designed to do that. It is basically about mapping strings (from xml input or web bureaucracy, and many others) to gadgets.
The preferred converter to the String kind honestly calls toString on its enter item, so that you can personalize the output for items of any precise magnificence by way of modifying the toString method of that magnificence.
Or you can replace the converter for goal kind String.Elegance with a custom converter which inspects the kind of the object and does a big switch statement. Or perhaps even look up a mapping desk of subconverter objects based totally on the form of the item being converted.
But in standard in case you need to do this, then ConvertUtils might be the incorrect device for your process. You would possibly like to take a look at morph.Sourceforge.Net, google for alternatives or craft your own solution.
Adv Java Tutorial
Question five. Why Do I Get Conversionexception When Using Rowsetdynaclass With Oracle?
Oracle's JDBC motive force is broken. When a query is administered towards a table containing a Timestamp column, the result set's metadata reports the column type (efficaciously) as javax.Square.Timestamp. And therefore the DynaClass object created to represent the query has a discipline of kind javax.Square.Timestamp to save the information for that column in. However calling resultset.GetObject on that column returns an item of kind javax.Sq..Date(!), which then of path can not be assigned to the corresponding discipline on a DynaBean item with that DynaClass.
This has been stated with Oracle10g, driver ojdbc14 model 10.1.0.Four.
Possible answers (untested) are:
subclass RowSetDynaClass and override the reproduction technique to fudge the conversion.
Subclass BasicDynaBean and override the set method to handle the trouble, then subclass RowSetDynaClass and override createDynaBean to go back instances of your custom bean that handles broken Oracle resultsets.
J2EE Interview Questions
Question 6. Do You Know That The Version Number In The Manifest.Mf For Release 1.7 Is Wrong?
Yes, we realize. It says 1.6. So does launch 1.6.1.
Now the construct machine has moved to Maven that may not show up once more.
Question 7. Why Do I Get Classcastexception When Accessing Nested Maps?
Say you've got a map which includes a nested map ala: nestedmap.Positioned ("key2", "somevalue"); map.Positioned ("key1", nestedmap);
If you use the subsequent syntax: String val = PropertyUtils.GetProperty(bean, "map(key1)(key2)");
It will truely return "map(key1)", so that it will be a Map, now not a String.
BeanUtils uses '.' as a property separator, and the second assets ought to without a doubt used mapped syntax, given that it's miles directly having access to a map now, therefore the best utilization need to be: String val = PropertyUtils.GetProperty(bean, "map(key1).Key2");
J2EE Tutorial Core Java Interview Questions
Question eight. Why Can't Beanutils Find My Method?
The BeanUtils bundle relies on introspection in preference to reflection. This manner that it'll discover best JavaBean compliant properties.
There are a few subtleties of this specification that may seize out the unwary:
A belongings can have best one set and one get method. Overloading is not allowed.
The java.Beans.Introspector searches widely for a custom BeanInfo elegance. If your elegance has the same call as every other with a custom BeanInfo (usually a java API magnificence) then the Introspector may use that in preference to growing thru reflection based for your class. If this takes place, the best solution is to create your very own BeanInfo.
Question nine. How Do I Set The Beancomparator Order To Be Ascending/descending?
BeanComparator is based 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 want to alternate the order, then a custom Comparator must be created and exceeded into the ideal constructor.
= new BeanComparator("propertyName", new ReverseComparator(new ComparableComparator()));
JSP Interview Questions
Question 10. What Is Beanintrospector?
Definition of an interface for additives that could perform introspection on bean lessons.
Core Java Tutorial
Question eleven. What Is Converter?
General reason information kind converter that can be registered and used in the BeanUtils package deal to control the conversion of gadgets from one kind to another.
Java-Springs Interview Questions
Question 12. What Is Dynabean?
A DynaBean is a Java item that supports properties whose names and facts kinds, as well as values, may be dynamically modified.
Adv Java Interview Questions
Question thirteen. What Is Dynaclass?
A DynaClass is a simulation of the functionality of java.Lang.Class for classes enforcing the DynaBean interface.
Question 14. What Is Introspectioncontext?
A context interface used at some point of introspection for querying and setting belongings descriptors.
Question 15. What Is Mutabledynaclass?
A specialised extension to DynaClass that lets in homes to be introduced or removed dynamically.
JMS(Java Message Service) Interview Questions
Question sixteen. What Is Basedynabeanmapdecorator<k>?
A base class for decorators imparting Map conduct on DynaBeans.
Question 17. What Is Basicdynabean?
Minimal implementation of the DynaBean interface.
Java applet Interview Questions
Question 18. What Is Basicdynaclass?
Minimal implementation of the DynaClass interface.
J2EE Interview Questions
Question 19. What Is Beancomparator<t>?
This comparator compares two beans by means of the required bean assets.
Question 20. What Is Beanmap?
An implementation of Map for JavaBeans which makes use of introspection to get and put residences in the bean.
Java Interview Questions
Question 21. What Is Beanmap.Entry?
Map entry utilized by BeanMap.
Question 22. What Is Beanpredicate?
Predicate implementation that applies the given Predicate to the end result of calling the given assets getter.
JavaMail API Tutorial
Question 23. What Is Beanpropertyvaluechangeclosure?
Closure that sets a belongings.
Remote Method Invocation Interview Questions
Question 24. What Is Beanpropertyvalueequalspredicate?
Predicate that evaluates a property fee in opposition to a distinctive fee.
Core Java Interview Questions
Question 25. What Is Beantopropertyvaluetransformer?
Transformer that outputs a belongings cost.
Java 8 Tutorial
Question 26. What Is Beanutils?
Utility strategies for populating JavaBeans residences through mirrored image.
JavaMail API Interview Questions
Question 27. What Is Beanutilsbean?
JavaBean property population methods.
JSP Interview Questions
Question 28. What Is Beanutilsbean2?
BeanUtilsBean implementation that creates a ConvertUtilsBean2 and delegates conversion to ConvertUtilsBean.Convert(Object, Class).
Question 29. What Is Constructorutils?
Utility reflection methods focussed on constructors, modelled after MethodUtils.
Java eight Interview Questions
Question 30. What Is Contextclassloaderlocal<t>?
An instance of this magnificence represents a value that is provided in keeping with (thread) context classloader.
Question 31. What Is Convertingwrapdynabean?
Implementation of DynaBean that wraps a widespread JavaBean instance, so that DynaBean APIs may be used to access its houses, although this implementation allows type conversion to arise while residences are set.