Servlets Java Technical Interview Questions
Categories: Programming
Q.1. What are the differences between Get and Post methods?
Ans.
Get |
Post |
(i) Limited amount of data can be sent because data is sent in header. |
(i) Large amount of data can be sent because data is sent in body. |
(ii) Not Secured because data is exposed in URL bar. |
(ii) Secured because data is not exposed in URL bar. |
(iii) Can be bookmarked |
(iii) Cannot be bookmarked |
(iv) Idempotent |
(iv) Non-Idempotent |
(v) It is more efficient and used than Post |
(v) It is less efficient and used |
Q.2. What are the different methods of session management in servlets?
Ans. Session is a conversational state between client and server and it can consists of multiple request and response between client and server. Since HTTP and Web Server both are stateless, the only way to maintain a session is when some unique information about the session (session id) is passed between server and client in every request and response.
Some of the common ways of session management in servlets are:
(i) User Authentication
(ii) HTML Hidden Field
(iii) Cookies
(iv) URL Rewriting
(v) Session Management API
(vi) JDBC – Java Basic Interview Questions
Q.3. What is JDBC Driver?
Ans. JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:
(i) JDBC-ODBC bridge driver
(ii) Native-API driver (partially java driver)
(iii) Network Protocol driver (fully java driver)
(iv) Thin driver (fully java driver)
Q.4. What are the steps to connect to a database in java?
Ans.
(i) Registering the driver class
(ii) Creating connection
(iii) Creating statement
(iv) Executing queries
(v) Closing connection
Q.5. What are the JDBC API components?
Ans. The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
(i) Connection
(ii) Statement
(iii) PreparedStatement
(iv) ResultSet
(v) ResultSetMetaData
(vi) DatabaseMetaData
(vii) CallableStatement etc.
Classes:
(i) DriverManager
(ii) Blob
(iii) Clob
(iv) Types
(v) SQLException etc.
Q.6. What is the role of JDBC DriverManager class?
Ans. The DriverManager class manages the registered drivers. It can be used to register and unregister drivers. It provides factory method that returns the instance of Connection.
Q.7. What is JDBC Connection interface?
Ans. The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that returns the instance of Statement, PreparedStatement, CallableStatement and DatabaseMetaData.
Q.8. What is the purpose of JDBC ResultSet interface?
Ans. The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database.
Q.9. What is JDBC ResultSetMetaData interface?
Ans. The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc.
Q.10. What is JDBC DatabaseMetaData interface?
Ans. The DatabaseMetaData interface returns the information of the database such as username, driver name, driver version, number of tables, number of views etc.