Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Explain event-driven programming in Java. Discuss the event delegation model and write a program demonstrating handling of mouse events.

Event-Driven Programming in Java

In event-driven programming, the flow of the program is determined by events such as mouse clicks, key presses, button actions, or window operations. Instead of executing top-to-bottom, the program waits in an event loop and responds when a user (or the system) generates an event. This model is the foundation of GUI programming in AWT and Swing.

The Event Delegation Model

Java (since JDK 1.1) uses the Delegation Event Model, which has three participants:

  1. Event Source — the component that generates the event (e.g., a Button, Frame, or Panel).
  2. Event Object — encapsulates information about the event (e.g., MouseEvent, ActionEvent), a subclass of java.util.EventObject.
  3. Event Listener — an object that registers with the source and contains handler methods (e.g., MouseListener).

How it works:

  • A listener registers with a source using an addXxxListener() method (e.g., addMouseListener()).
  • When an event occurs, the source creates an event object and delegates it by calling the appropriate method of every registered listener.
  • Only registered listeners are notified, which keeps the design efficient and decoupled.

Program: Handling Mouse Events

import java.awt.*;
import java.awt.event.*;

public class MouseDemo extends Frame implements MouseListener {
    Label status;

    public MouseDemo() {
        status = new Label("Perform a mouse action...");
        setLayout(new FlowLayout());
        add(status);
        addMouseListener(this);   // register this frame as the listener
        setSize(400, 200);
        setVisible(true);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) { System.exit(0); }
        });
    }

    public void mouseClicked(MouseEvent e) {
        status.setText("Clicked at (" + e.getX() + ", " + e.getY() + ")");
    }
    public void mousePressed(MouseEvent e)  { status.setText("Mouse Pressed");  }
    public void mouseReleased(MouseEvent e) { status.setText("Mouse Released"); }
    public void mouseEntered(MouseEvent e)  { status.setText("Mouse Entered");  }
    public void mouseExited(MouseEvent e)   { status.setText("Mouse Exited");   }

    public static void main(String[] args) {
        new MouseDemo();
    }
}

Here the Frame is the source, MouseEvent is the event object, and the class itself is the listener (it implements MouseListener and is registered via addMouseListener(this)). When the mouse is clicked, AWT delegates a MouseEvent to mouseClicked(), which displays the coordinates.

event-handling
2long10 marks

What is JDBC? Explain the architecture of JDBC. Write a program to retrieve and display all records from a table using a ResultSet.

What is JDBC?

JDBC (Java Database Connectivity) is a standard Java API (in java.sql and javax.sql) that lets Java programs connect to and execute SQL statements against relational databases in a database-independent way. It defines interfaces such as Driver, Connection, Statement, PreparedStatement, and ResultSet, and database vendors supply drivers that implement them.

JDBC Architecture

JDBC follows a two-layer architecture:

  1. JDBC API layer — provides the application-to-JDBC Manager connection (the interfaces used by programmers).
  2. JDBC Driver layer — provides the JDBC Manager-to-Driver connection that talks to the actual database.

At its center is the DriverManager, which manages the list of registered drivers and returns a Connection for a given URL.

Driver types:

  • Type 1 – JDBC-ODBC bridge driver.
  • Type 2 – Native-API (partly Java) driver.
  • Type 3 – Network-protocol (pure Java) driver via middleware.
  • Type 4 – Thin (pure Java) driver that talks the database's native protocol directly (most common today, e.g., MySQL Connector/J).

Typical flow: Application → DriverManager → Driver → Database, and results return through a ResultSet.

Program: Retrieve and Display Records

import java.sql.*;

public class DisplayRecords {
    public static void main(String[] args) {
        String url  = "jdbc:mysql://localhost:3306/college";
        String user = "root", pass = "password";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");          // load driver
            Connection con = DriverManager.getConnection(url, user, pass);
            Statement st  = con.createStatement();
            ResultSet rs  = st.executeQuery("SELECT id, name, marks FROM student");

            System.out.println("ID\tName\tMarks");
            while (rs.next()) {                                  // iterate rows
                System.out.println(rs.getInt("id") + "\t"
                        + rs.getString("name") + "\t"
                        + rs.getInt("marks"));
            }
            rs.close(); st.close(); con.close();                // release resources
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The ResultSet acts as a cursor; rs.next() advances row by row and the getXxx() methods read each column's value.

jdbcdatabase
3long10 marks

Explain the Servlet API. Describe the methods of the Servlet interface and demonstrate inter-servlet communication.

The Servlet API

A servlet is a server-side Java component that handles client (usually HTTP) requests and generates dynamic responses within a web container such as Tomcat. The Servlet API is provided by two packages:

  • javax.servlet — protocol-independent classes/interfaces.
  • javax.servlet.http — HTTP-specific support (HttpServlet, HttpServletRequest, HttpServletResponse).

The core hierarchy is Servlet (interface) → GenericServlet (abstract) → HttpServlet (abstract). Most servlets extend HttpServlet and override doGet() / doPost().

Methods of the Servlet Interface

The Servlet interface declares five methods, three of which form the life-cycle methods:

MethodPurpose
init(ServletConfig config)Called once when the servlet is loaded; used for one-time initialization.
service(ServletRequest req, ServletResponse res)Called for every request; dispatches the request (to doGet/doPost in HttpServlet).
destroy()Called once before the servlet is unloaded; releases resources.
getServletConfig()Returns the ServletConfig (initialization parameters).
getServletInfo()Returns a string with author/version information.

Inter-Servlet Communication

Servlets can collaborate using the RequestDispatcher (and shared ServletContext). One servlet can forward the request to or include another servlet's output.

// ServletA.java
public class ServletA extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        req.setAttribute("msg", "Data from ServletA");
        RequestDispatcher rd = req.getRequestDispatcher("ServletB");
        rd.forward(req, res);                    // delegate to ServletB
    }
}

// ServletB.java
public class ServletB extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        out.println("<h3>Received: " + req.getAttribute("msg") + "</h3>");
    }
}

Here ServletA stores data in the request scope and forwards control to ServletB, which reads the attribute and produces the final response. include() could be used instead to merge ServletB's output into ServletA's response.

servlet
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

What are the benefits of using Swing components?

Benefits of Swing components:

  • Lightweight (pure Java): Swing components are written entirely in Java and do not depend on native peers, so they behave consistently across platforms ("write once, run anywhere").
  • Pluggable Look-and-Feel: The appearance can be changed at runtime (Metal, Nimbus, native, etc.) independent of the underlying OS.
  • Rich component set: Provides advanced widgets not available in AWT — JTable, JTree, JTabbedPane, JSpinner, tooltips, etc.
  • MVC architecture: Separates data (model), presentation (view), and behavior (controller), making components flexible and easy to customize.
  • Double buffering built in, giving smoother, flicker-free rendering.
  • Components are prefixed with J (e.g., JButton, JLabel) and support features like keyboard accelerators, icons, and accessibility.
swing
5short5 marks

Explain the use of the final modifier in Java with a suitable example.

The final modifier restricts modification. It can be applied to variables, methods, and classes:

  • final variable — its value cannot be changed once assigned (it becomes a constant).
  • final method — cannot be overridden by a subclass.
  • final class — cannot be extended (no subclassing), e.g., String.

Example:

final class Vehicle {            // cannot be subclassed
    final int WHEELS = 4;        // constant, cannot be reassigned

    final void start() {         // cannot be overridden
        System.out.println("Vehicle starting with " + WHEELS + " wheels");
    }
}

Attempting WHEELS = 6;, overriding start() in a subclass, or writing class Car extends Vehicle would each cause a compile-time error.

java
6short5 marks

What is a layout manager? Explain GridLayout.

Layout Manager

A layout manager is an object that automatically arranges the components inside a container (such as a JPanel or Frame), controlling their size and position. It frees the programmer from hard-coding pixel coordinates and lets the GUI adapt when the window is resized. Common managers include FlowLayout, BorderLayout, GridLayout, CardLayout, and GridBagLayout.

GridLayout

GridLayout arranges components in a rectangular grid of equal-sized cells with a specified number of rows and columns. Components are added left-to-right, top-to-bottom, and each cell is given the same width and height regardless of the component's preferred size.

Panel p = new Panel();
p.setLayout(new GridLayout(2, 3, 5, 5)); // 2 rows, 3 cols, 5px h/v gaps
for (int i = 1; i <= 6; i++)
    p.add(new Button("B" + i));          // fills a 2x3 grid

If rows is set to 0, the manager creates as many rows as needed for the given number of columns (and vice-versa).

layout
7short5 marks

Differentiate between connected and connectionless socket programming.

Connected vs. Connectionless Socket Programming:

AspectConnected (TCP)Connectionless (UDP)
ProtocolTCPUDP
ConnectionA dedicated connection is established (3-way handshake) before data transferNo connection; each packet sent independently
Java classesSocket, ServerSocketDatagramSocket, DatagramPacket
ReliabilityReliable — guarantees delivery, ordering, and error checkingUnreliable — packets may be lost, duplicated, or arrive out of order
Data unitContinuous byte streamDiscrete datagrams
Overhead / speedMore overhead, slowerLess overhead, faster
Use casesWeb, email, file transferStreaming, DNS, online games, VoIP

In short, connected (TCP) sockets give reliable, ordered, stream-based communication, while connectionless (UDP) sockets give fast, lightweight, best-effort datagram delivery.

socket
8short5 marks

What is RMI registry? Explain its purpose.

RMI Registry

The RMI registry is a simple naming service (a lookup table) that maps human-readable string names to remote object references (stubs) in Java RMI. It allows a client to locate a remote object on a host without knowing its physical reference, using a name instead.

Purpose / working:

  • The server creates a remote object and binds it to a name in the registry using Naming.bind("//host/Service", obj) (or Registry.rebind).
  • The registry runs as a separate process, typically on port 1099, started with the rmiregistry tool or programmatically via LocateRegistry.createRegistry(1099).
  • The client performs a lookup with Naming.lookup("//host/Service"), which returns the remote object's stub; the client then invokes methods through that stub.

Thus the RMI registry acts as the bridge that lets clients discover and obtain references to remote objects by name, decoupling clients from the server's actual object references.

rmi
9short5 marks

Explain the life cycle of a JSP page.

Life Cycle of a JSP Page

A JSP page is internally translated into a servlet and managed by the web container. Its life cycle has the following phases:

  1. Translation — The container translates the .jsp file into a Java servlet source file (.java).
  2. Compilation — The generated servlet source is compiled into a .class file. (Translation and compilation happen once, when the page is first requested or if it changes.)
  3. Class Loading & Instantiation — The servlet class is loaded and an instance is created.
  4. InitializationjspInit() is called once to perform setup (e.g., open resources).
  5. Request Processing_jspService(request, response) is invoked for every client request to generate the dynamic response. This method is auto-generated and must not be overridden.
  6. DestructionjspDestroy() is called once before the JSP instance is removed, to release resources.

Thus jspInit() and jspDestroy() run once each, while _jspService() runs once per request.

jsp
10short5 marks

How is form data passed from JSP to a servlet?

Passing Form Data from JSP to a Servlet

Data entered in an HTML/JSP form is sent to a servlet through an HTTP request when the form is submitted:

  1. The JSP defines a form whose action points to the servlet's URL and specifies the HTTP method (GET or POST):
<form action="LoginServlet" method="post">
    Name: <input type="text" name="uname"><br>
    Pass: <input type="password" name="pwd"><br>
    <input type="submit" value="Login">
</form>
  1. On submission the browser sends the field values as request parameters (name=value pairs).
  2. The servlet reads them using the request object's getParameter() method:
protected void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    String name = req.getParameter("uname");   // matches name attribute
    String pwd  = req.getParameter("pwd");
    // ... process name and pwd
}

The parameter name passed to getParameter() must match the name attribute of the form field. (getParameterValues() is used for multi-valued fields such as checkboxes.)

jspservlet
11short5 marks

What is ResultSetMetaData? Explain with an example.

ResultSetMetaData

ResultSetMetaData is a JDBC interface (java.sql.ResultSetMetaData) that provides information about the structure of a ResultSet — that is, metadata about its columns rather than the data itself. It answers questions such as: how many columns are there, what are their names, types, and sizes.

It is obtained by calling getMetaData() on a ResultSet. Common methods:

  • getColumnCount() — number of columns.
  • getColumnName(int i) / getColumnLabel(int i) — column name.
  • getColumnType(int i) / getColumnTypeName(int i) — column data type.

Example:

ResultSet rs = st.executeQuery("SELECT * FROM student");
ResultSetMetaData md = rs.getMetaData();

int cols = md.getColumnCount();
System.out.println("Number of columns: " + cols);
for (int i = 1; i <= cols; i++) {
    System.out.println(md.getColumnName(i) + " : " + md.getColumnTypeName(i));
}

This prints each column's name and type without knowing the table structure in advance, which is useful for writing generic/dynamic database utilities.

jdbc
12short5 marks

Write short notes on Java networking using the URL class.

Java Networking with the URL Class

The java.net.URL class represents a Uniform Resource Locator — the address of a resource on the web (e.g., a web page or file). It abstracts the protocol, host, port, and path, letting a program access network resources easily.

Key points:

  • A URL has the form protocol://host:port/path?query#ref, e.g., http://www.example.com:80/index.html.
  • Useful methods: getProtocol(), getHost(), getPort(), getFile(), getPath(), and openStream() to read the resource's contents.
  • openConnection() returns a URLConnection for more control (headers, output, etc.).

Example — reading a web page:

import java.net.*;
import java.io.*;

public class URLDemo {
    public static void main(String[] args) throws Exception {
        URL url = new URL("https://www.example.com/");
        System.out.println("Host: " + url.getHost());
        System.out.println("Protocol: " + url.getProtocol());

        BufferedReader in = new BufferedReader(
                new InputStreamReader(url.openStream()));
        String line;
        while ((line = in.readLine()) != null)
            System.out.println(line);
        in.close();
    }
}

The URL class thus provides a simple, high-level way to identify and retrieve internet resources in Java networking.

networking

Frequently asked questions

Where can I find the BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) question paper 2077?
The full BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2077 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
Does the Advanced Java Programming (BSc CSIT, CSC409) 2077 paper come with solutions?
Yes. Every question on this Advanced Java Programming (BSc CSIT, CSC409) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2077 paper?
The BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2077 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this Advanced Java Programming (BSc CSIT, CSC409) past paper free?
Yes — reading and attempting this Advanced Java Programming (BSc CSIT, CSC409) past paper on Kekkei is completely free.