37 Advanced Java Interview Questions for Freshers

Related Courses

When preparing for an interview, knowledge of Advanced Java is essential for standing out in today’s competitive IT landscape. Advanced Java goes beyond the basics and delves into enterprise-level development, server-side applications, frameworks like Spring and Hibernate, and more.

In this blog, we'll explore some of the most frequently asked Advanced Java interview questions and their answers to help you confidently approach your next interview.

  1. What is a DataSource in JDBC?

    A Data Source object enables JDBC applications to obtain a DBMS connection from a connection pool. Each Data Source object binds to the JNDI tree and points to a connection pool or MultiPool. Applications look up the Data Source on the JNDI tree and then request a connection from the Data Source.

  2. How many ways can you update a result set?

    The following ways to update a result set

    • updateRow()

    • deleteRow()

    • refreshRow()

    • cancelRowUpdates()

    • insertRow()

  3. How to set the attribute Concurrency in ResultSet?

    CONCUR_READ_ONLY – It is only for reading.
    CONCUR_UPDATABLE − It is for both read and updated.

  4. What are the methods available in HttpServlet class?

    • public void service(ServletRequest req,ServletResponse res)

    • protected void service(HttpServletRequest req, HttpServletResponse res)

    • protected void doGet(HttpServletRequest req, HttpServletResponse res)

    • protected void doPost(HttpServletRequest req, HttpServletResponse res)

    • protected void doHead(HttpServletRequest req, HttpServletResponse res)

    • protected void doOptions(HttpServletRequest req, HttpServletResponse res)

    • protected void doPut(HttpServletRequest req, HttpServletResponse res)

    • protected void doTrace(HttpServletRequest req, HttpServletResponse res)

    • protected void doDelete(HttpServletRequest req, HttpServletResponse res)

    • protected long getLastModified(HttpServletRequest req)

  5. What is HTTPFilter?

    Filters typically run on multithreaded servers,so be aware that a filter must handle concurrentrequests and be careful to synchronize access to shared resources.Shared resources include in-memory data such asinstance or class variables and external objectssuch as files, database connections, and networkconnections.

  6. How servlet filter configuration in web.xml?

    Syntax:
    <filter> 
    <filter-name>...</filter-name> 
    <filter-class>...</filter-class> 
    </filter>



    7.What are the uses of filter in servlet?

    Data compression
    Encryption and decryption
    Input validation.
    Recording all incoming requests
    Logs the IP addresses of the computers from which the requests originate
    Conversion.

  7. What are the methods available in filter interfeace in servlet?

    public void init(FilterConfig config)   
    public void doFilter(HttpServletRequest request,HttpServletResponse response, FilterChain chain)
    public void destroy()

  8. What is the difference between war file and jar file?

    JAR files are used for packaging and distributing standalone Java applications or libraries, where as WAR files are used for packaging and distributing web applications.

  9. How to create war file?

    It needs jar tool of JDK
    Go inside the project directory of your project (outside the WEB-INF), then write the following command
    jar -cvf projectname.war * 
    Here, -c is used to create file, -v to generate the verbose output and -f to specify the arhive file name.
    The * (asterisk) symbol signifies that all the files of this directory.



  10. What is ServletInputStream?

    ServletInputStream is a class which provides to read binary data as image from the request object.
    The getInputStream() method of ServletRequest interface returns the instance of ServletInputStream.
    it is having only one method called as
    int readLine(byte[] b, int off, int len)
    Example:
    ServletInputStream input =request.getInputStream();

  11. What is ServletOutputStream?

    ServletOutputStream is a class used  to write binary data  into the response.
    The getOutputStream() method of ServletResponse interface returns the instance of ServletOutputStream class.
    Example:
    ServletOutputStream out=response.getOutputStream();

  12. What are the methods available in ServletOutputStream class?

    • void print(long l)

    • void print(boolean b)

    • void print(int i)

    • void print(char c)

    • void print(String s)

    • void print(float f)

    • void println(long l)

    • void println

    • void print(double d)

    • void println(boolean b)

    • void println(double d)

    • void println(int i)

    • void println(float f)

    • void println(String s)

    • void println(char c)

  13. Explain SingleThreadModel interface?

    SinglrThreadModel is used to handle single request at a time. If the programmer wants single request at a time must be implementing this interface. It is a marker interface so does not have any methods.
    It is recommended to use other means to resolve these thread safety issues such as synchronized block etc.
    Sample Program:

    public class TestServlet extends HttpServlet implements SingleThreadModel {
       
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentType("text/html"); 
            PrintWriter out = resp.getWriter(); 
            out.print("Welcome to "); 
            try{Thread.sleep(10000);}catch(Exception e){e.printStackTrace();} 
            out.print("Nareh I Technologies"); 
            out.close(); 
        }
    }
    
  14. What are the methods available in ServletContext Interface?

    • public String getInitParameter(String name)

    • public Enumeration getInitParameterNames()

    • public Enumeration getInitParameterNames()

    • public void removeAttribute(String name)

    • public void setAttribute(String name,Object object)

    • public Object getAttribute(String name)

  15. How to get the object of ServletContext interface?

    getServletContext() method used to returns the object of ServletContext.
    Syntax:
    public ServletContext getServletContext() 
    Example:
    ServletContext serv=getServletContext();

  16. What are Techniques of Session Tracking?

    The following techniques are used for session tracking

    • Hidden Form Field

    • URL Rewriting

    • Cookies

    • HttpSession

  17. Explain JDBCURL connection for oracle expression addition using connection class object?

    JDBC URL of Oracle connection is jdbc:oracle:thin:@localhost:1521:xe
    where jdbc is the API, oracle is the database, thin is the driver, localhost is the server name on which oracle is running, we may also use IP address, 1521 is the port number and XE is the Oracle service name.

  18. How to establish connection using connection class Object?

    For establish the connection by using connection class object of oracle expression addition is
    Connection con = DriverManager.getConnection(url,user,password)
    The URL is connection which of database URL example oracle and MYSQL.
    UserName: username of oracle database.
    Password: Password of oracle database related to username

  19. Explain JDBCURL connection for MYSQL expression addition using connection class object?

    The url for MYSQL JDBC connection using connection class object is jdbc:mysql://localhost:3306/test
    where jdbc is the API, mysql is the database, localhost is the server name on which mysql is running, we may also use IP address, 3306 is the port number and test is the database name.

  20. What are the different types of drivers in jdbc?

    Type 1: JDBC-ODBC bridge.
    Type 2: Native-API driver(partial Java driver).
    Type 3: Network Protocol driver(pure Java driver for database middleware).
    Type 4: Thin driver(pure Java driver for direct-to-database).
    Type 5: highly-functional drivers with superior performance.

  21. What is “oracle.jdbc.driver.OracleDriver”?

    This is driver class for oracle database and by using Class.ForName to load the oracle driver first
    For class.ForName
    Class.forName("oracle.jdbc.driver.OracleDriver");

  22. What is “com.mysql.jdbc.Driver”?

    This is driver class for MYSQL database by using Class.ForName to load the MYSQL driver first.
    Class.ForName(“com.mysql.jdbc.Driver”);

  23. Which data types are used for storing the image and file in the database table?

    BLOB: it is a data type is used to store the image in the database. We can also store videos and audio by using the BLOB data type. It stores the binary type of data.
    CLOB: it is a data type is used to store the file in the database. It stores the character type of data.

  24. What is stored procedure? What are the parameter types in stored procedure?

    Stored procedure is a group of SQL queries that are executed as a single logical unit to perform a specific task. Name of the procedure should be unique since each procedure is represented by its name.
    For example, operations on an employee database like obtaining information about an employee could be coded as stored procedures that will be executed by an application.

  25. What is the difference between oracle.jdbc.driver.OracleDriver and oracle.jdbc.OracleDriver?

    For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.

  26. What is JDBC-ODBC bridge driver?

    JDBC bridge is used to access ODBC drivers installed on each client machine and it converts JDBC method calls into the ODBC function calls. This driver does not support from java 8 or later.

  27. What is Native API driver?

    The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java.

  28. What is Network Protocol driver?

    The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol and inotherwords it is three-tier approach is used to access databases. The JDBC clients use standard network sockets to communicate with a middleware application server. It is fully written in java.

    Advantage is No client-side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.

  29. What is thin driver?

    The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language and it is called as pure java-based driver. For this you don't need to install special software on the client or server.

  30. What is ResultSetMetaData interface in jdbc?

    ResultSetMetaData interface provides methods to get metadata from the ResultSet object and count the number of columns, column name, column type etc by using getMetaData() method of ResultSet.
    Syntax:
    public ResultSetMetaData getMetaData()throws SQLException

  31. What are the commonly used methods in ResultSetMetaData?

    • public int getColumnCount()throws SQLException

    • public String getColumnName(int index)throws SQLException

    • public String getColumnTypeName(int index)throws SQLException

    • public String getTableName(int index)throws SQLException

  32. Explain DatabaseMetaData interface?

    DatabaseMetaData is used for database driver name,product version, name of total number of tables, name of total number of views etc.By using getMetaData() method of Connection interface returns the object of DatabaseMetaData.
    Syntax:
    public DatabaseMetaData getMetaData()throws SQLException 

  33. What are the commonly used methods in DatabaseMetaData?

    • public String getDriverName()throws SQLException

    • public String getDriverVersion()throws SQLException

    • public String getUserName()throws SQLException

    • public String getDatabaseProductName()throws SQLException

    • public String getDatabaseProductVersion()throws SQLException

    • public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)throws SQLException

  34. Explain ACID properties of Transaction management in JDBC?

    ACID stands for Atomicity, Consistency, isolation and durability.
    Atomicity means either all successful or none.
    Consistency ensures bringing the database from one consistent state to another consistent state.
    Isolation ensures that transaction is isolated from other transaction.
    Durability means once a transaction has been committed, it will remain so, even in the event of errors, power loss etc.

  35. What is BatchProcessing in JDBC?

    Instead of executing a single query, we can execute a batch (group) of queries and when one statement sends multiple statements of SQL at once to the database, the communication overhead is reduced significantly, as one is not communicating with the database frequently, which in turn results to fast performance.The java.sql.Statement and java.sql.PreparedStatement interfaces provide methods for batch processing.

  36. What are the steps for batch processing in JDBC?

    The following steps used to create batch processing in JDBC

    • Load the driver class

    • Create Connection

    • Create Statement

    • Add query in the batch

    • Execute Batch

    • Close Connection

Boost Your Skills with Naresh IT's Advanced Java Online Training

If you’re aiming to master the intricacies of Advanced Java and be interview-ready, Naresh IT offers the perfect platform. Our comprehensive Advanced Java Online Training provides:

  • Live instructor-led classes by industry experts.
  • Hands-on practical experience with real-time projects.
  • Complete course material covering servlets, JSP, JDBC, Spring, and Hibernate.
  • 24/7 support for clearing doubts and assisting with assignments.
  • Job-oriented training focused on interview preparation and placement assistance.

At Naresh IT, we not only teach you Advanced Java but also help you sharpen your problem-solving skills with interview-focused training sessions.

Stay tuned for the rest of the blog where we dive into more interview questions for all technologies

Ready to upskill? Enroll in Naresh IT's Advanced Java Online Training today and take your career to the next level!

----------------------------------------------------------------------------------------------------

For More Details About Full Stack Courses : Visit Here
Register For Free Demo on UpComing Batches : Click Here