Advance Java Interview Questions and Answers
Advance Java Interview Questions and Answers
Table of Contents
1 JDBC ....................................................................................................................... 1
2 Networking: ............................................................................................................. 5
3 Servlets: .................................................................................................................. 6
4 JSP ....................................................................................................................... 11
1 JDBC
1. What is JDBC?
Java Database Connectivity (JDBC) is a standard Java API to interact with relational databases
from Java. JDBC has a set of classes and interfaces which can use from Java application and talk
to the database without learning RDBMS details and using Database Specific JDBC Drivers
4. What is DriverManager?
DriverManager is a static class. It manages a list of database drivers. Matches connection requests
from the java application with the proper database driver using the communication sub-protocol.
The first driver that recognizes a certain subprotocol under JDBC will be used to establish a
database connection.
5. What is a Driver?
The JDBC API defines the Java interfaces and classes that programmers use to connect to
databases and send queries. A JDBC driver implements these interfaces and classes for a particular
DBMS vendor.database communications link, handling all communication with the database.
Normally, once the driver is loaded, the developer need not call it explicitly.
1/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
2/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
20. What are the standard isolation levels defined by the JDBC?
The standard isolation levels are:
TRANSACTION_NONE
TRANSACTION_READ_COMMITTED
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_SERIALIZABLE
3/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
2 Networking:
30. What is multiprogramming?
Multiprogramming is a rapid switching of the CPU back and forth between processes.
5/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
What is accept()?
It waits for an incoming client. This method blocks until either a client connects to the server on
the specified port or the socket times out, assuming that the time-out value has been set using
the setSoTimeout() method. Otherwise, this method blocks indefinitely.
3 Servlets:
45. What is servlet?
A servlet is a Java programming language class that is used to extend the capabilities of servers
that host applications accessed using a request-response programming model. Before the servlet,
CGI scripting language was used as a server-side programming language.
7/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
The GenericServlet does not include protocol-specific methods for handling request
parameters, cookies, sessions and setting response headers. The HttpServlet subclass
passes generic service method requests to the relevant doGet () or doPost () method.
GenericServlet is not specific to any protocol. HttpServlet only supports HTTP and
HTTPS protocol.
57. What is the difference between the doGet () and doPost ()?
The difference is:
In doGet() the parameters are appended to the URL and sent along with header information.
In doPost(), send the information through a socket back to the webserver and it won't show
up in the URL bar.
The amount of information you can send back using a GET is restricted as URLs can only be
1024 characters. You can send much more information to the server by using post and it's not
restricted to textual data either. It is possible to send files and even binary data such as
serialized Java objects!
DoGet() is a request for information.It does not change anything on the server.
(doGet () should be idempotent). doPost () provides information (such as placing an order
for merchandise) that the server is expected to remember.
59. How do I support both doGet () and doPost () from the same servlet?
The easy way is, just support POST, then have your doGet method call your doPost method.
8/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
9/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
The information provided by a deployment descriptor is declarative and therefore it can be
modified without changing the source code of a bean.
73. How do I use cookies to store the session state on the client?
In a servlet, the HttpServletResponse and HttpServletRequest objects passed to method
HttpServlet. Service () can be used to create cookies on the client and use cookie information
transmitted during client requests. JSPs can also use cookies, in scriptlet code or, preferably,
from within custom tag code.
To set a cookie on the client, use the addCookie() method in class HttpServletResponse.
Multiple cookies may be set for the same request, and a single cookie name may have multiple
values.
To get all of the cookies associated with a single HTTP request, use the getCookies() method
of class HttpServletRequest
10/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
4 JSP
80. What are the advantages of jsp over servlet?
The advantage of JSP is that they are document-centric. Servlets, on the other hand, look and act
like programs. A Java Server Page can contain Java program fragments that instantiate and
execute Java classes, but these occur inside an HTML template file and are primarily used to
generate dynamic content. Some of the JSP functionality can be achieved on the client, using
JavaScript. The power of JSP is that it is server-based and provides a framework for Web
application development.
11/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
12/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
98. What is the difference between include directive and include action?
The difference is:
Include directive, includes the content of the specified file during the translation phase–when
the page is converted to a servlet. Include action, includes the response generated by
executing the specified page (a JSP page or a servlet) during the request processing phase–
when the page is requested by a user.
Include directive is used to statically insert the contents of a resource into the current JSP.
Include standard action enables the current JSP page to include a static or a dynamic resource
at runtime.
14/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
112. What is the difference between a variable declared inside the declaration
tag and variable declared in scriptlet?
Variable declared inside declaration part is treated as an instance variable and will be placed
directly at class level in the generated servlet. Variable declared in a scriptlet will be placed inside
_jspService () method of generated servlet. It acts like a local variable.
118. Is there a way to reference the “this” variable within the jsp?
Yes, there is. The page implicit object is equivalent to "this", and returns a reference to the
generated servlet.
119. Can you make the use of servletOutputStream object within jsp?
Yes. By using getOutputStream () method on response implicit object we can get it.
16/17
ADF Essentials Training by Deepak Bhagat
Advance Java Questions and Answers
Session: After sendRedirect also you will get the session scope data. All data stored in the
session is available to end-users until the session closed or browser closed.
Application: Data will be available throughout the application. One user can store data in
application scope and others can get the data from application scope.
124. In which situation we can use the static include and dynamic include?
If the target resource won’t change frequently, then it is recommended to use include directives.
If the target resource will change frequently, then it is recommended to use include action.
17/17
ADF Essentials Training by Deepak Bhagat