“Java Spring Interview Questions and Answers for freshers on “User Locales and Locale-Sensitive Text Messages”.
1. Interface implemented by locale resolver.
a) localeResolver
b) tiles
c) front controller
d) none of the mentioned
Answer: a
Clarification: In a Spring MVC application, a user’s locale is identified by a locale resolver, which has to implement the LocaleResolver interface.
2. You can define a locale resolver by registering a bean of type LocaleResolver in the web application context.
a) True
b) False
Answer: a
Clarification: You must set the bean name of the locale resolver to localeResolver for DispatcherServlet to auto-detect.
3. Default localeResolver used by Spring.
a) AcceptHeaderLocale
b) AcceptHeader
c) AcceptHeaderLocaleResolver
d) AcceptLocaleResolver
Answer: c
Clarification: The default locale resolver used by Spring is AcceptHeaderLocaleResolver.
4. AcceptHeaderLocaleResolver esolves locales by inspecting the accept-language header of an HTTP request.
a) True
b) False
Answer: a
Clarification: This header is set by a user’s web browser according to the locale setting of the underlying operating system.
5. Alternative way to resolve locales.
a) AcceptHeaderLocale
b) AcceptHeader
c) AcceptHeaderLocaleResolver
d) SessionLocaleResolver
Answer: d
Clarification: Another option of resolving locales is by SessionLocaleResolver.
6. Property which indicates how many seconds this cookie should be persisted.
a) cookieMaxAge
b) cookieName
c) cookieAge
d) none of the mentioned
Answer: a
Clarification: The cookieMaxAge property indicates how many seconds this cookie should be persisted.
7. Method used to change user’s locale.
a) set
b) setLocale
c) locale
d) set_locale
Answer: b
Clarification: Changing a user’s locale by calling LocaleResolver.setLocale() explicitly.
8. Property of LocaleChangeInterceptor used to customize parameter name.
a) localeResolver.setLocale
b) paramName
c) locale.parm
d) none of the mentioned
Answer: b
Clarification: Changing a user’s locale by calling LocaleResolver.setLocale() explicitly.
9. LocaleChangeInterceptor can only detect the parameter for the handler mappings that enable it.
a) True
b) False
Answer: a
Clarification: So, if you have more than one handler mapping configured in your web application context, you have to register this interceptor to allow users to change their locales in any of the URLs.
10. Parameter which can change user’s locale by any URL.
a) locale
b) languageURL
c) language
d) none of the mentioned
Answer: c
Clarification: Now a user’s locale can be changed by any URLs with the language parameter.
11. Interface used to resolve text messages.
a) Message
b) Message_Source
c) Language
d) MessageSource
Answer: d
Clarification: Spring is able to resolve text messages for you by using a message source, which has to implement the MessageSource interface.
12. Tag used by view to resolve text messages.
a) spring:message
b) spring:language
c) spring:title
d) none of the mentioned
Answer: a
Clarification: Then your JSP files can use the spring:message tag, defined in Spring tag library, to resolve a message given the code.
13. The ResourceBundleMessageSource implementation resolves messages for different locales.
a) True
b) False
Answer: a
Clarification: The ResourceBundleMessageSource implementation resolves messages from different resource bundles for different locales.
14. cookieName is used by localeResolver to customize the cookie used.
a) True
b) False
Answer: a
Clarification: The cookie used by this locale resolver can be customized by setting the cookieName and cookieMaxAge properties.
15. The cookieMaxAge value when browser is closed.
a) 0
b) 1
c) -1
d) true
Answer: c
Clarification: The value -1 indicates that this cookie will be invalid after the browser is closed.
Java Spring for interviews,