A session bean uses several configurable constants. The constants are all defined as String types in JNDI. This cannot be changed because existing code is using the same JNDI information. One of the constant is a date, represented in string format. This date constant is used in multiple business methods of this session bean, actually as a Date object. Converting strings to dates is an expensive operation: therefore, the developer wants to do as little converting as possible.
Which two scenarios can be used to prevent converting from String to Date in every business method?
The model answers are :
c: Load the date string in an instance String variable by annotation of this instance variable and convert it to a Date type object in @PostConstruct annotated method.
d: Load the date string in an instance Date type variable by annotation of a setter method that takes a string and which carries out conversion and assigns the value to the instance variable.
But I think the answer is only c.
Reason why I think d is not correct:
if the bean is a stateless bean, its instance variable should not store any variable specific for a client. Consider this scenario:
1. a client first calls the setter method of the stateless bean instance which assigns a
string value to an instance variable.
2. a client calls another business method of the bean and the instance is different from step 1 , the instance variable is not set in this new instance.