Advanced Java Interview Questions – Introduction to Advanced Java

1. [Asked in Cognizant] What is Advanced Java? What are its main components?

Answer:
Advanced Java is a part of Java programming used mainly for web-based and enterprise applications. It primarily includes:

  • Servlets: Java programs running on a web server.
  • JSP (JavaServer Pages): Technology to create dynamic web pages.
  • JDBC (Java Database Connectivity): Used to connect Java applications to databases.

2. [Asked in Infosys] What is a Servlet? Why do we use it?

Answer:
A Servlet is a Java class used to handle requests and generate responses on a web server. Servlets are used for processing web requests, handling form data, session management, and dynamic response generation. They offer efficiency and security in web applications.


3. [Asked in IBM] What is JSP and why is it used?

Answer:
JavaServer Pages (JSP) is a server-side technology that helps create dynamic web content. JSP allows developers to embed Java code directly into HTML pages, making it easier to build dynamic websites with less code. It’s commonly used for view components in MVC architecture.


4. [Asked in TCS] Explain JDBC briefly.

Answer:
Java Database Connectivity (JDBC) is an API that allows Java applications to interact with databases. JDBC helps perform operations like creating, updating, retrieving, and deleting data in databases using SQL queries from Java applications.


5. [Asked in Cognizant] What’s the difference between Servlet and JSP?

Answer:

ServletJSP
Java code with embedded HTML.HTML page with embedded Java code.
Good for complex business logic processing.Good for dynamic webpage presentation.
Requires more coding effort.Easier for web page designing due to HTML-like structure.

6. [Asked in Wipro] Explain JDBC briefly.

Answer:
JDBC (Java Database Connectivity) is an API provided by Java to connect and interact with databases. It enables Java programs to execute SQL queries, retrieve data, and manage databases seamlessly across different database platforms.


7. [Asked in Deloitte] What is the life cycle of a Servlet?

Answer:
Servlet life cycle includes:

  1. Loading and Initialization (init()): Servlet initialized by the container.
  2. Request handling (service()): Handles client requests.
  3. Destroying: Servlet instance is removed from the server.

Methods involved:

  • init()
  • service()
  • destroy()

8. [Asked in Amazon] What are JDBC Drivers? Name the types briefly.

Answer:
JDBC Drivers allow Java applications to communicate with databases. Four JDBC driver types:

  • Type 1 (JDBC-ODBC Bridge Driver): Connects via ODBC, platform-dependent.
  • Type 2 (Native API Driver): Uses native client libraries.
  • Type 3 (Network Protocol Driver): Middleware converts JDBC calls.
  • Type 4 (Thin Driver): Fully Java-based and most widely used.

9. [Asked in Microsoft] How can you maintain user sessions using JSP or Servlets?

Answer:
Sessions in JSP/Servlets are maintained using the HttpSession object:

  • Create Session: HttpSession session = request.getSession();
  • Set Attributes: session.setAttribute("user", userObj);
  • Retrieve Attributes: session.getAttribute("user"); Sessions track user data between multiple requests.

10. [Asked in Wipro] Explain briefly the difference between GET and POST requests in Servlets/JSP.

Answer:

GETPOST
Data sent in URL (visible).Data sent in request body (hidden).
Suitable for less-sensitive data.Suitable for sensitive information (passwords).
Bookmarkable.Not bookmarkable.

11. [Asked in Flipkart] Mention one advantage and one disadvantage of JSP.

Answer:

  • Advantage: Easy to learn and write dynamic web pages combining Java and HTML.
  • Disadvantage: Mixing extensive Java code directly into JSP can make pages complex and harder to maintain, causing readability and maintenance issues.