Advanced Java Questions & Answers – Session Management

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) focuses on “Session Management”.

1. Which of the following is used for session migration?
a) Persisting the session in database
b) URL rewriting
c) Create new database connection
d) Kill session from multiple sessions
View Answer

Answer: a
Explanation: Session migration is done by persisting session in database. It can also be done by storing session in memory on multiple servers.

2. Which of the below is not a session tracking method?
a) URL rewriting
b) History
c) Cookies
d) SSL sessions
View Answer

Answer: b
Explanation: History is not a session tracking type. Cookies, URL rewriting, Hidden form fields and SSL sessions are session tracking methods.

3. Which of the following is stored at client side?
a) URL rewriting
b) Hidden form fields
c) SSL sessions
d) Cookies
View Answer

Answer: d
Explanation: Cookies are stored at client side. Hence, it is advantageous in some cases where clients disable cookies.
advertisement
advertisement

4. Which of the following leads to high network traffic?
a) URL rewriting
b) Hidden form fields
c) SSL sessions
d) Cookies
View Answer

Answer: a
Explanation: WRL rewriting requires large data transfer to and from the server which leads to network traffic and access may be slow.

5. Which of the following is not true about session?
a) All users connect to the same session
b) All users have same session variable
c) Default timeout value for session variable is 20 minutes
d) New session cannot be created for a new user
View Answer

Answer: c
Explanation: Default timeout value for session variable is 20 minutes. This can be changed as per requirement.

6. SessionIDs are stored in cookies.
a) True
b) False
View Answer

Answer: a
Explanation: SessionIDs are stored in cookies, URLs and hidden form fields.

7. What is the maximum size of cookie?
a) 4 KB
b) 4 MB
c) 4 bytes
d) 40 KB
View Answer

Answer: a
Explanation: The 4K is the maximum size for the entire cookie, including name, value, expiry date etc. To support most browsers, it is suggested to keep the name under 4000 bytes, and the overall cookie size under 4093 bytes.
advertisement

8. How can we invalidate a session?
a) session.discontinue()
b) session.invalidate()
c) session.disconnect()
d) session.falsify()
View Answer

Answer: b
Explanation: We can invalidate session by calling session.invalidate() to destroy the session.

9. Which method creates unique fields in the HTML which are not shown to the user?
a) User authentication
b) URL writing
c) HTML Hidden field
d) HTML invisible field
View Answer

Answer: c
Explanation: HTML Hidden field is the simplest way to pass information but it is not secure and a session can be hacked easily.
advertisement

10. Which object is used by spring for authentication?
a) ContextHolder
b) SecurityHolder
c) AnonymousHolder
d) SecurityContextHolder
View Answer

Answer: d
Explanation: The SessionManagementFilter checks the contents of the SecurityContextRepository against the current contents of the SecurityContextHolder to determine whether user has been authenticated during the current request by a non-interactive authentication mechanism, like pre authentication or remember me.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

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.