Spring Questions and Answers – User Locales and Locale-Sensitive Text Messages

“This set of Java Spring Interview Questions and Answers for freshers focuses 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: The default locale resolver used by Spring is AcceptHeaderLocaleResolver.
advertisement
advertisement

4. AcceptHeaderLocaleResolver esolves locales by inspecting the accept-language header of an HTTP request.
a) True
b) False
View Answer

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: Another option of resolving locales is by SessionLocaleResolver.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Property which indicates how many seconds this cookie should be persisted.
a) cookieMaxAge
b) cookieName
c) cookieAge
d) none of the mentioned
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: Changing a user’s locale by calling LocaleResolver.setLocale() explicitly.
advertisement

8. Property of LocaleChangeInterceptor used to customize parameter name.
a) localeResolver.setLocale
b) paramName
c) locale.parm
d) none of the mentioned
View Answer

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: 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.
advertisement

10. Parameter which can change user’s locale by any URL.
a) locale
b) languageURL
c) language
d) none of the mentioned
View Answer

Answer: c
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: The value -1 indicates that this cookie will be invalid after the browser is closed.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring for interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.