0% found this document useful (0 votes)
13 views6 pages

Ajp Qs 2

The document provides an overview of Advanced Java concepts, including differences between Core and Advanced Java, features suitable for web applications, and the roles of JDK, JRE, and JVM. It covers JDBC, Servlets, JSP, multithreading, networking, practical scenarios, and general advanced Java concepts, detailing how to connect to databases, manage sessions, and implement web applications. Additionally, it discusses MVC architecture, annotations, JavaBeans, and popular Java frameworks for web development.

Uploaded by

lavanyadalvi22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Ajp Qs 2

The document provides an overview of Advanced Java concepts, including differences between Core and Advanced Java, features suitable for web applications, and the roles of JDK, JRE, and JVM. It covers JDBC, Servlets, JSP, multithreading, networking, practical scenarios, and general advanced Java concepts, detailing how to connect to databases, manage sessions, and implement web applications. Additionally, it discusses MVC architecture, annotations, JavaBeans, and popular Java frameworks for web development.

Uploaded by

lavanyadalvi22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Basic questions

1. General Concepts

1. What is Advanced Java, and how is it different from Core Java?

Advanced Java focuses on developing web-based and enterprise-level applications, including


Servlets, JSP, and JDBC. Core Java covers basics like OOP concepts, strings, arrays, and
threads.

2. What are the features of Java that make it suitable for web applications?

Features: Platform independence (runs anywhere with JVM), built-in security (e.g.,
encryption), scalability (supports large-scale applications), and APIs like JDBC, Servlets, and
JSP for enterprise apps.

3. Explain the role of JDK, JRE, and JVM in Java.

JDK: Includes tools for development (compiler, debugger). JRE: Provides runtime libraries for
executing Java programs. JVM: Converts bytecode to machine code for execution.

4. What are the key differences between Java SE and Java EE?

Java SE is the standard edition for standalone apps, while Java EE extends it for enterprise
needs, adding APIs for web services, Servlets, and EJBs.

2. JDBC (Java Database Connectivity)

5. What is JDBC, and why is it used?

JDBC is an API to connect Java applications to relational databases for executing SQL queries.

6. What are the main steps involved in establishing a database connection using JDBC?

Steps to connect to a database:

• Load the database driver using Class.forName().

• Connect using DriverManager.getConnection().

• Create a Statement or PreparedStatement.

• Execute the query (executeQuery() or executeUpdate()).

• Process results using ResultSet.

• Close connections.
7. What is the difference between Statement and PreparedStatement?

Statement: Executes SQL directly. PreparedStatement: Precompiled SQL with placeholders


(?), making it faster and safer from SQL injection.

8. How can you handle SQL exceptions in JDBC?

Handle SQL errors using try-catch blocks, and log the error messages for debugging.

9. What is a ResultSet in JDBC?

ResultSet: An object used to navigate and retrieve data returned by SQL queries.

3. Servlets

10. What is a Servlet, and why is it used?

Servlets are server-side Java programs that process client requests (like HTTP GET/POST) and
generate responses dynamically (e.g., HTML or JSON).

11. Explain the lifecycle of a Servlet.

• init() initializes the Servlet when first loaded.


• service() handles requests and responses.
• destroy() cleans up resources when the Servlet is taken out of service.

12. What is the difference between doGet() and doPost() methods in Servlets?

doGet() is used to handle data retrieval (e.g., query parameters in URL). doPost() is used for
sending sensitive data (e.g., form submissions) in the request body.

13. How can you forward a request from one Servlet to another?

Use RequestDispatcher.forward(request, response) to forward a request to another resource


(e.g., another Servlet).

14. What are the ways to manage sessions in Servlets?

Manage sessions using cookies, URL rewriting, HttpSession objects, or hidden fields to store
and track user information.
4. JSP (JavaServer Pages)

15. What is JSP, and how does it work?

JSP simplifies web development by embedding Java code into HTML to create dynamic
content.

16. What is the difference between Servlets and JSP?

JSP is mostly used for the view (UI), while Servlets handle logic (backend). JSPs are compiled
into Servlets internally.

17. Explain the use of JSP directives like <%@ page %> and <%@ include %>.

<%@ page %> sets page-level attributes (e.g., import libraries). <%@ include %> includes
static files at translation time.

18. How can you include a static file in a JSP page?

Use <%@ include file="header.html" %> to include static files like headers or footers.

19. What are scriptlets in JSP, and how are they used?

Scriptlets are Java code written within JSP tags (<% %>). Example: <% int x = 10; %>.

5. Multithreading

20. What is a thread in Java?

A thread is a lightweight process that allows concurrent execution within a program.

21. How is a thread created in Java?

Create threads by extending the Thread class or implementing the Runnable interface.

22. What is the difference between the Runnable interface and the Thread class?

Thread class ties thread behavior to the logic; Runnable separates thread creation from the
task logic.

23. What are thread priorities, and how do they affect execution?
Thread priorities (1-10) determine the relative importance of threads; higher priority threads
get preference.

24. What is synchronization in Java, and why is it important?

Synchronization prevents race conditions by allowing only one thread to access a shared
resource at a time.

6. Networking

25. What is a socket in Java?

A socket is an endpoint for two-way communication between devices over a network.

26. How does a simple client-server application work in Java?

A simple client-server app uses ServerSocket (server-side) to accept connections and Socket
(client-side) to connect.

27. What is the difference between TCP and UDP?

TCP: Reliable and connection-oriented (e.g., HTTP). UDP: Faster but connectionless (e.g.,
video streaming).

28. What is the purpose of the InetAddress class?

InetAddress: Represents IP addresses, resolves hostnames using DNS.

29. How does Java handle HTTP requests?

Java handles HTTP requests via HttpURLConnection for GET/POST requests to APIs or
websites.

7. Practical Scenario Questions

30. Write a simple JDBC program to connect to a database.

JDBC program: Write a program to connect to a database, execute a query (e.g., SELECT *),
process the results, and close the connection.

31. How would you write a Servlet to display "Hello, World!"?

Servlet example: Write a doGet() method to display "Hello, World!" in the browser.
32. How do you pass data between a JSP and a Servlet?

Use HttpServletRequest.getParameter("field_name") in Servlets to retrieve form data sent


from a JSP.

33. Explain how to retrieve data from a database and display it in a JSP page.

Fetch database rows via JDBC, loop through the ResultSet, and display data in an HTML
<table> in JSP.

34. How would you implement a login page using JSP and Servlets?

Use JSP for the UI (login form) and a Servlet for backend validation (check credentials in the
database).

8. General Advanced Java Concepts

35. What is a web application, and how is it deployed in Java?

Web application: Software hosted on a server, accessed via browsers using URLs.

36. What is a WAR file, and how is it used?

WAR file: Web Application Archive that packages web apps (JSPs, Servlets, HTML, etc.) for
deployment.

37. Explain the concept of MVC architecture in web development.

MVC: A design pattern that separates business logic (Model), user interface (View), and
control flow (Controller).

38. What is the purpose of annotations in Java (e.g., @Override, @WebServlet)?

Annotations: Metadata for code, like @Override (method overriding) or @WebServlet


(Servlet configuration).

39. What are Java Beans, and how are they used in JSP?

JavaBeans: Classes with properties (getters/setters) used for encapsulating data and sharing
it between JSP and Servlets.

40. What are some commonly used Java frameworks for web development?
Frameworks: Commonly used frameworks are Spring (MVC, DI), Hibernate (ORM), and
Struts (MVC).

You might also like