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
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
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
Explanation: Cookies are stored at client side. Hence, it is advantageous in some cases where clients disable cookies.
4. Which of the following leads to high network traffic?
a) URL rewriting
b) Hidden form fields
c) SSL sessions
d) Cookies
View Answer
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
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
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
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.
8. How can we invalidate a session?
a) session.discontinue()
b) session.invalidate()
c) session.disconnect()
d) session.falsify()
View Answer
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
Explanation: HTML Hidden field is the simplest way to pass information but it is not secure and a session can be hacked easily.
10. Which object is used by spring for authentication?
a) ContextHolder
b) SecurityHolder
c) AnonymousHolder
d) SecurityContextHolder
View Answer
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.
- Practice Information Technology MCQs
- Apply for Computer Science Internship
- Check Programming Books
- Practice Programming MCQs
- Apply for Java Internship