0% found this document useful (0 votes)
27 views5 pages

Ajp Qs

The document contains a series of questions and concise answers related to Java programming, covering topics such as Advanced Java, Servlets, JSP, JDBC, multithreading, networking, Java 8 features, design patterns, exception handling, and practical scenarios. It provides a foundational understanding of key concepts and functionalities within Java development. Additionally, it includes practical code snippets for implementing specific tasks in Java applications.

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)
27 views5 pages

Ajp Qs

The document contains a series of questions and concise answers related to Java programming, covering topics such as Advanced Java, Servlets, JSP, JDBC, multithreading, networking, Java 8 features, design patterns, exception handling, and practical scenarios. It provides a foundational understanding of key concepts and functionalities within Java development. Additionally, it includes practical code snippets for implementing specific tasks in Java applications.

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/ 5

General Questions

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

2. What are Servlets, and why are they used in web development?

3. Explain the lifecycle of a Servlet.

4. What is the role of JDBC in Java?

5. What is the difference between Statement, PreparedStatement, and CallableStatement in


JDBC?

Servlets and JSP

6. How do you manage sessions in Servlets?

7. What are the differences between GET and POST methods in HTTP?

8. What is JSP, and how is it related to Servlets?

9. Explain the purpose of JSP directives (<%@ include %> and <%@ page %>).

10. How can you pass data between a JSP and a Servlet?

JDBC (Java Database Connectivity)

11. How do you connect a Java application to a database using JDBC?

12. What are the steps to execute a SQL query in JDBC?

13. What is the purpose of the DriverManager class in JDBC?

14. How do you handle transactions in JDBC?

15. What is the difference between ResultSet TYPE_FORWARD_ONLY and


TYPE_SCROLL_INSENSITIVE?

Multithreading and Concurrency

16. What is a thread in Java?

17. How is a thread created in Java?

18. Explain the difference between Runnable and Thread classes.

19. What are the states in a thread lifecycle?

20. What is synchronization, and why is it important in multithreading?


Networking

21. What are sockets in Java?

22. How do you create a simple client-server application using sockets?

23. Explain the difference between TCP and UDP protocols.

24. What is the purpose of the InetAddress class?

25. How does Java handle HTTP communication?

Java 8 and Beyond

26. What is a Lambda expression, and how is it used?

27. Explain the concept of Streams in Java 8.

28. What is the purpose of the Optional class in Java?

29. How do you use the foreach() method in Java Collections?

30. What is the functional interface in Java?

Miscellaneous

31. What is a design pattern, and can you explain the Singleton pattern?

32. How does Java handle exceptions, and what is the difference between checked and
unchecked exceptions?

33. What are annotations in Java, and how are they used?

34. What is the difference between forward and redirect in Servlets?

35. How is a web application deployed in Java?

Practical/Scenario-Based Questions

36. Write a simple Servlet code to display "Hello, World!" on a browser.

37. How would you create a login system using Servlets and JSP?

38. How would you retrieve data from a database and display it in a JSP table?

39. Write a code snippet to connect to a database using JDBC.

40. How can you handle form data in a Servlet?


Here are concise answers to the questions:

General Questions

1. Advanced Java focuses on enterprise-level development like web and network


programming, whereas Core Java deals with fundamental features of the language.

2. Servlets are Java programs that run on a server and handle requests and responses in a web
application.

3. Servlet lifecycle: init() → service() → destroy().

4. JDBC is an API that connects Java applications to databases.

5. Statement executes simple queries, PreparedStatement handles parameterized queries, and


CallableStatement executes stored procedures.

Servlets and JSP

6. Session management: Cookies, URL rewriting, HttpSession, or hidden form fields.

7. GET sends data via URL; POST sends data in the request body (more secure for sensitive
data).

8. JSP (JavaServer Pages) is used to create dynamic web pages, whereas Servlets handle
backend logic.

9. JSP directives like <%@ page %> configure the JSP, while <%@ include %> includes files at
translation time.

10. Use RequestDispatcher to forward or include data between JSP and Servlet.

JDBC (Java Database Connectivity)

11. Use DriverManager.getConnection() to establish a connection.

12. Steps: Load driver → Establish connection → Create statement → Execute query → Process
results → Close connection.

13. DriverManager manages database drivers and connections.

14. Transactions are handled using Connection.setAutoCommit(false) and commit()/rollback().

15. TYPE_FORWARD_ONLY allows forward movement only; TYPE_SCROLL_INSENSITIVE enables


bidirectional scrolling without reflecting changes in the database.

Multithreading and Concurrency

16. A thread is a lightweight process for multitasking.

17. Threads are created using Thread class or Runnable interface.


18. Runnable separates logic from the Thread class; Thread directly represents a thread.

19. Thread states: New → Runnable → Running → Waiting/Blocked → Terminated.

20. Synchronization ensures thread-safe access to shared resources using synchronized blocks or
methods.

Networking

21. Sockets enable communication between two systems over a network.

22. Use ServerSocket for the server and Socket for the client.

23. TCP is reliable and connection-oriented; UDP is faster but connectionless.

24. InetAddress represents IP addresses and resolves hostnames.

25. Java handles HTTP communication using classes like HttpURLConnection.

Java 8 and Beyond

26. Lambda expressions are concise representations of anonymous functions.

27. Streams process collections of data in a functional style (filter, map, reduce).

28. Optional avoids null checks by providing methods to handle values or defaults.

29. forEach() is used to iterate through collections with a lambda expression.

30. A functional interface has exactly one abstract method (e.g., Runnable).

Miscellaneous

31. Design patterns are reusable solutions to common problems. The Singleton pattern ensures
only one instance of a class exists.

32. Checked exceptions must be handled or declared in the method; unchecked exceptions
occur at runtime and need not be explicitly handled.

33. Annotations provide metadata for the compiler or runtime (e.g., @Override).

34. Forward transfers the request internally; redirect sends a new request to the client.

35. A web application is deployed in a servlet container like Tomcat using a .war file.

Practical/Scenario-Based Questions

36. Hello World Servlet:

public class HelloWorld extends HttpServlet {


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException {

response.getWriter().println("Hello, World!");

37. Login System: Use HttpServletRequest.getParameter() for form data, validate against a
database, and manage sessions.

38. Retrieve Data: Use JDBC to fetch data and iterate through ResultSet to display rows in HTML
<table>.

39. JDBC Connection:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "user",


"password");

40. Form Data in Servlet:

String username = request.getParameter("username");

You might also like