Top 10+ Advanced Java Interview Questions and Answers

  • By Pooja Nandode-Bhavsar
  • April 3, 2024
  • JAVA Programming
Top 10+ Advanced Java Interview Questions and Answers

Top 10+ Advanced Java Interview Questions and Answers

Explore top-notch Top 10+ Advanced Java Interview Questions and Answers to tackle complex scenarios, and ace your interviews with confidence.

Q.1 What is the difference between the Statement and PreparedStatement interface?

Top 10+ Advanced Java Interview Questions and Answers

Q.2 Define ResultSet, ResultSetMetaData, DatabaseMetaData

=> 1.ResultSet is an inbuilt interface comes under java.sql package used to access/fetch data from database into java application

  1. Metadata means data/information about data

ResultSetMetaData is an inbuilt interface comes under java.sql package used to access/get metadata/information about table like number of columns present in the table,accessing column present on given index position,accessing/getting column type present on given index position and it is used to access table name

  1. DatabaseMetadata is an inbuilt interface comes under java.sql package used to access/get metadata/information about database like DriverName,DriverVersion, UserName, DatabaseProductName,DatabaseProductVersion

 

Q.3 Define Transaction Management in JDBC

=>Transaction Management in JDBC is the process of combining all related operations into a single unit and executing on the rule “either all or none”, is called Transaction Management in JDBC

 

For Free, Demo classes Call: 020-71173125

Registration Link: Click Here!

 

Q.4 Explain ACID property of Transaction Management in JDBC?

=>The ACID properties describe the transaction management well. ACID stands for Atomicity, Consistency, Isolation and Durability.

1. Atomicity means either all successful or none.

2. Consistency ensures bringing the database from one consistent state to another consistent state.

(that is at the end of the transaction both databases contain equal transactional data)

3. Isolation ensures that multiple transaction gets executed parallelly(at the same time) 

but that transactions don’t get affect each other

4. Durability means once a transaction has been committed,

 it will remain so, even in the event of errors, power loss etc.

 

Q.5 Explain JDBC connectivity steps?

=> there are in total 5 steps we need to follow to perform JDBC connectivity.

1.load(means add drivers in project) & Register(means add drivers in memory) the driver/connector class

2.Create/establish the connection object

3.Create the Statement object

4.Execute the query

5.Close the connection object  

 

Q.6 What is the difference between get and post request?

Top 10+ Advanced Java Interview Questions and Answers

Q.7 What is the difference between RequestDispatcher and SendRedirect?

Top 10+ Advanced Java Interview Questions and Answers

Q.8 What is the use of Deployment Descriptor File(web.xml) in servlet programming?

=> In the web.xml file, we can decide for which request(HTML page) which servlet(.java file) should be called If you have multiple servlets in Tomcat then you have to mention which servlet which request should be called.

 

Q.9 Explain the life cycle of servlets.

=> Basically, there are three states in the servlet life cycle: new(init()), ready(service()) and end(init). 

 

   i.The servlet is in new state if servlet instance/object is created by the web server in eb container

   ii.After calling the init() method, Servlet comes in the ready state. In the ready state, the servlet performs all the tasks. 

   iii.When the web container calls the destroy() method, it shifts to the end or destroys the state.

 

Q.10 Explain how JSP differs from Servlet.

=> 

JSP is an extension to the servlet

JSP consists of all the features of Java servlet, In addition to JSP provides features like implicit objects, expression language, JSTL tag library

 

Easy to managed

JSP is easy to manage because in the JSP file we can easily separate business and presentation logic. But in servlet, we mix both business logic with the presentation logic.

 

Enables fast development process

If the JSP page changed, we don’t need to recompile and redeploy the project on the server. Whereas the Servlet code needs to be updated and recompiled if we have to change the look and feel of the application.

 

Need to write Less code than Servlet

In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that reduce the code.

 

For Free, Demo classes Call: 020-71173125

Registration Link: Java Training in Pune!

 

Q.11 Explain Scripting Elements in JSP.

=> There are 3 types of Scripting elements in JSP that allow us to embed Java code in a JSP file.

 

1.scriptlet tag  <% out.println(“ggg”); %>

 

<% %> this tag is called as scriptlet tag and inside this tag we can put any code of java 

E.g

 <% 

      int a=2,b=5;

      out.println(“<h2>addition of 2 nos = “+(a+b)+”</h2>”);  //here we dont have to create out object bcz,it is implicitely available in jsp 

    %>

 

2.declaration tag 

It is used to declare variables and methods

 

e.g

 <%! int a,int b;

             <%!

         int math=70,sci=40,eng=50;

       

          

           int avg()

            {

             int a  =(math+sci+eng)/3;

             return a;

            }

           

          double areaOfCircle(int r)

          {

           double pi=3.14;

           double area   = pi*r*r;

           

         return area; 

         }

          %>

   

3.expression tag 

 

   <!–  Expression tag used for printing statements on the browser –>

    <!– In an Expression tag, we don’t need to use out.print, and also the statements written inside expression tag should not be terminate with semicolon –>

   

      <%=

            “<h2>avg of marks = “+avg()+”</h2>”

              

        %>

      

      <%=

       “<h2>area of circle = “+areaOfCircle(4)+”</h2>”

      %>

   

      %>

 

Q.12 Explain JSTL core tags.

=>  1.<set> tag

Used to set/declare a variable in jsp file and specify the initial value of the declared variable

 

   2.<out> tag

Used to print the value of the variable

      

   3. remove tag

    

removes a particular variable from a given scope

 

   4.<if>

    Used to check the conditional logic of the code

 

  1. choose,when, otherwise

 The <c: choose> works like a Java switch statement in that it lets you choose between a number of alternatives/cases. Where the switch statement has case statements, the <c: choose> tag has <c: when> tags. Just as a switch statement has the default clause to specify a default action, <c: choose> has <c: otherwise> as the default clause.

 

6.forEach tag

        =>JSTL forEach tag allows you to iterate/ traverse or loop array, Array List, or any other collection without using any type of Java code.

  1. redirect(alternative for response.sendRedirect)

       =>redirects the browser to an alternate URL provided by a programmer

 

Do watch our Channel to learn more: Click Here

Author:-

Pooja Nandode-Bhavsar
Call the Trainer and Book your free demo class for Java now!!!

© Copyright 2020 | SevenMentor Pvt Ltd.

Submit Comment

Your email address will not be published. Required fields are marked *

*
*