Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Discuss the architecture of Swing. Write a GUI application using Swing that accepts user details through text fields and displays them in a dialog box.

Swing Architecture

Swing is a part of Java Foundation Classes (JFC) built on top of AWT. Unlike AWT (which uses heavyweight, native peer components), Swing components are lightweight — they are drawn entirely in Java without depending on the native windowing system. Swing follows a Model-View-Controller (MVC) design:

  • Model — holds the data/state of the component (e.g. ListModel, ButtonModel).
  • View — renders the component on screen (handled by the UI delegate).
  • Controller — handles user input / events.

In Swing, the View and Controller are combined into a single UI delegate (the Pluggable Look and Feel, e.g. BasicButtonUI), giving a separable model architecture. This allows the look-and-feel to be changed at runtime (Metal, Nimbus, Windows, etc.).

Key features: lightweight components, pluggable look-and-feel, all components inherit from javax.swing.JComponent (except top-level containers JFrame, JDialog, JApplet, JWindow), and it is built around the AWT event model.

GUI Program: Accept User Details and Show in a Dialog Box

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class UserDetailsForm extends JFrame {
    private JTextField nameField, emailField;

    public UserDetailsForm() {
        setTitle("User Details");
        setLayout(new GridLayout(3, 2, 5, 5));

        add(new JLabel("Name:"));
        nameField = new JTextField(20);
        add(nameField);

        add(new JLabel("Email:"));
        emailField = new JTextField(20);
        add(emailField);

        JButton submit = new JButton("Submit");
        add(submit);

        submit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String msg = "Name: " + nameField.getText()
                           + "\nEmail: " + emailField.getText();
                JOptionPane.showMessageDialog(UserDetailsForm.this, msg,
                        "Submitted Details", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        setSize(350, 150);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(UserDetailsForm::new);
    }
}

When the user fills the text fields and clicks Submit, the entered details are displayed in a dialog box using JOptionPane.showMessageDialog().

swinggui
2long10 marks

Explain RMI in detail. Describe the steps to develop an RMI application and write a program to implement a remote calculator.

Remote Method Invocation (RMI)

RMI allows an object running in one Java Virtual Machine (JVM) to invoke methods of an object running in another JVM, possibly on a different host — i.e. it enables distributed computing in Java. The caller works as if the remote object were local; RMI handles the network communication, marshalling, and unmarshalling.

RMI Architecture

  • Stub — client-side proxy of the remote object; marshals the arguments and sends the request.
  • Skeleton — server-side proxy (merged into the runtime since Java 1.2) that unmarshals arguments and invokes the actual method.
  • Remote Reference Layer — manages references and connection to remote objects.
  • Transport Layer — handles the actual TCP/IP communication.
  • RMI Registry — a naming service where remote objects are bound and looked up.

Steps to Develop an RMI Application

  1. Define a remote interface that extends java.rmi.Remote; each method throws RemoteException.
  2. Implement the interface in a server class (usually extending UnicastRemoteObject).
  3. Create and start the RMI registry (rmiregistry or LocateRegistry.createRegistry).
  4. Bind the remote object to the registry using Naming.rebind().
  5. Write the client that does a Naming.lookup() and calls the remote methods.
  6. Compile and run the server, then the client.

Program: Remote Calculator

Remote interface

import java.rmi.*;
public interface Calculator extends Remote {
    int add(int a, int b) throws RemoteException;
    int sub(int a, int b) throws RemoteException;
}

Implementation (server object)

import java.rmi.*;
import java.rmi.server.*;
public class CalculatorImpl extends UnicastRemoteObject implements Calculator {
    public CalculatorImpl() throws RemoteException { super(); }
    public int add(int a, int b) { return a + b; }
    public int sub(int a, int b) { return a - b; }
}

Server

import java.rmi.*;
import java.rmi.registry.*;
public class CalcServer {
    public static void main(String[] args) throws Exception {
        LocateRegistry.createRegistry(1099);
        Naming.rebind("rmi://localhost/CalcService", new CalculatorImpl());
        System.out.println("Calculator server ready.");
    }
}

Client

import java.rmi.*;
public class CalcClient {
    public static void main(String[] args) throws Exception {
        Calculator c = (Calculator) Naming.lookup("rmi://localhost/CalcService");
        System.out.println("7 + 3 = " + c.add(7, 3));
        System.out.println("7 - 3 = " + c.sub(7, 3));
    }
}

The client transparently invokes add() and sub() on the remote CalculatorImpl object running in the server JVM.

rmi
3long10 marks

What is JDBC? Explain different JDBC driver types with their advantages and disadvantages. Write a program demonstrating a transaction in JDBC.

JDBC

JDBC (Java Database Connectivity) is a Java API that allows Java programs to connect to and interact with relational databases in a database-independent manner. It provides classes and interfaces (DriverManager, Connection, Statement, PreparedStatement, ResultSet, etc.) to execute SQL statements and process results.

JDBC Driver Types

TypeNameHow it worksAdvantagesDisadvantages
Type 1JDBC-ODBC BridgeTranslates JDBC calls into ODBC callsEasy to use; connects to any ODBC sourceSlow; ODBC driver/native code needed on client; platform dependent; removed in Java 8
Type 2Native-API (partly Java)JDBC calls converted to native DB client library callsFaster than Type 1Native client library must be installed; platform dependent
Type 3Network Protocol (pure Java, middleware)JDBC calls sent to a middleware server which talks to the DBPure Java; no client library; can connect to many DBsNeeds a separate middleware server; extra network layer
Type 4Thin / Native Protocol (pure Java)Converts JDBC calls directly into the DB's network protocolPure Java, platform independent, fastest, no client installDatabase-specific driver needed for each DB

Type 4 (thin) drivers are most commonly used today.

Program: Transaction in JDBC

A transaction groups several SQL operations so that either all succeed (commit) or none do (rollback). We disable auto-commit and control commit/rollback manually.

import java.sql.*;
public class TransferDemo {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/bank";
        try (Connection con = DriverManager.getConnection(url, "root", "pass")) {
            con.setAutoCommit(false);          // begin transaction
            try (PreparedStatement debit  = con.prepareStatement(
                     "UPDATE accounts SET balance = balance - ? WHERE id = ?");
                 PreparedStatement credit = con.prepareStatement(
                     "UPDATE accounts SET balance = balance + ? WHERE id = ?")) {

                debit.setInt(1, 1000); debit.setInt(2, 1); debit.executeUpdate();
                credit.setInt(1, 1000); credit.setInt(2, 2); credit.executeUpdate();

                con.commit();                  // both succeed -> commit
                System.out.println("Transaction committed.");
            } catch (SQLException ex) {
                con.rollback();                // any failure -> rollback
                System.out.println("Transaction rolled back: " + ex.getMessage());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Here money is transferred from account 1 to account 2. If either update fails, rollback() restores the database to its prior consistent state.

jdbc
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Discuss any three event listener interfaces in Java.

Event listener interfaces define callback methods that are invoked when a particular event occurs on a source component. Three common ones:

  1. ActionListener — handles action events such as a button click, menu selection, or pressing Enter in a text field. Method: void actionPerformed(ActionEvent e).
  2. MouseListener — handles mouse events. Methods: mouseClicked(), mousePressed(), mouseReleased(), mouseEntered(), mouseExited() (all take a MouseEvent).
  3. KeyListener — handles keyboard events. Methods: keyPressed(), keyReleased(), keyTyped() (all take a KeyEvent).

Other examples include ItemListener, WindowListener, FocusListener, and MouseMotionListener. A listener is attached to a component using methods like addActionListener().

event-handling
5short5 marks

What is the difference between a container and a component in Swing?

Component vs Container in Swing:

  • A component is a basic visual GUI element that the user interacts with — e.g. JButton, JLabel, JTextField, JCheckBox. In Swing most components extend javax.swing.JComponent (which itself extends java.awt.Container).
  • A container is a special component that can hold and arrange other components inside it — e.g. JPanel, JFrame, JDialog, JApplet. Components are added to a container using add(), and their positions/sizes are controlled by the container's layout manager.
AspectComponentContainer
PurposeAn individual UI elementHolds/groups other components
Can contain others?No (leaf)Yes
Layout managerNot applicableHas one (e.g. FlowLayout)
ExamplesJButton, JLabelJPanel, JFrame

In short: every container is a component, but not every component is a container.

swing
6short5 marks

Explain the CardLayout manager with an example.

CardLayout Manager

CardLayout (in java.awt) arranges components as a stack of cards, where only one card (component) is visible at a time — like a deck of cards. Each card usually is a panel. The layout provides methods to flip between cards: first(), last(), next(), previous(), and show(parent, name) to display a card by name. It is useful for wizard-style screens or tabbed-like navigation.

Example

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CardDemo {
    public static void main(String[] args) {
        JFrame f = new JFrame("CardLayout Demo");
        CardLayout card = new CardLayout();
        JPanel cards = new JPanel(card);

        cards.add(new JLabel("This is Card 1", JLabel.CENTER), "one");
        cards.add(new JLabel("This is Card 2", JLabel.CENTER), "two");

        JButton next = new JButton("Next");
        next.addActionListener(e -> card.next(cards));

        f.add(cards, BorderLayout.CENTER);
        f.add(next, BorderLayout.SOUTH);
        f.setSize(300, 150);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}

Clicking Next calls card.next(cards), which flips from "Card 1" to "Card 2".

layout
7short5 marks

What is a servlet context? Explain its uses.

Servlet Context

ServletContext is an object (one per web application) that defines a set of methods used by a servlet to communicate with its servlet container and to share information across the whole application. It is obtained via getServletContext(). There is exactly one ServletContext per web application (per JVM), shared by all servlets and JSPs in that application.

Uses

  1. Application-wide attributes — store and retrieve shared objects available to all servlets: setAttribute(), getAttribute(), removeAttribute().
  2. Initialization parameters — read application-level <context-param> values from web.xml using getInitParameter().
  3. Logging — write to the application log with context.log().
  4. Resource access — locate files/resources within the web app using getResourceAsStream() and getRealPath().
  5. Request dispatching — obtain a RequestDispatcher to forward/include resources.
  6. Server information — obtain container details via getServerInfo() and getMajorVersion().

Unlike ServletConfig (one per servlet), ServletContext is global to the entire application, making it ideal for sharing data among servlets.

servlet
8short5 marks

Differentiate between forward and redirect in servlets.

forward vs redirect (sendRedirect)

AspectForward (RequestDispatcher.forward)Redirect (response.sendRedirect)
Where it happensOn the server sideClient/browser is told to make a new request
Number of requestsSingle requestTwo requests (original + new)
URL in browserUnchanged (URL of original resource)Changes to the new URL
Request dataSame request object is passed; request attributes preservedNew request; attributes lost (data must go via URL/session)
TargetResource within the same applicationAny resource, even a different server/site
SpeedFaster (no extra round trip)Slower (extra round trip)
Examplerequest.getRequestDispatcher("next.jsp").forward(request, response);response.sendRedirect("next.jsp");

Summary: Use forward when the navigation is internal and you want to keep request data; use redirect when you want the browser to load a new URL (e.g. after a POST, or to an external site).

servlet
9short5 marks

What is multithreading? How is it implemented in Java?

Multithreading

Multithreading is the ability of a program to execute multiple threads (independent paths of execution) concurrently within a single process. Threads share the same memory/resources but run independently, enabling better CPU utilization, responsiveness, and parallelism.

Implementing Threads in Java

There are two standard ways:

1. Extending the Thread class — override run() and call start():

class MyThread extends Thread {
    public void run() { System.out.println("Running: " + getName()); }
}
new MyThread().start();

2. Implementing the Runnable interface — implement run() and pass the object to a Thread:

class Task implements Runnable {
    public void run() { System.out.println("Task running"); }
}
Thread t = new Thread(new Task());
t.start();

start() creates a new call stack and invokes run() on a separate thread (calling run() directly would not start a new thread). The Runnable approach is preferred because the class can still extend another class. Thread states include New, Runnable, Running, Blocked/Waiting, and Terminated.

multithreading
10short5 marks

Explain JSP implicit objects.

JSP Implicit Objects

JSP provides 9 implicit objects that the container makes available automatically inside scriptlets and expressions — no declaration needed:

ObjectTypeDescription
requestHttpServletRequestThe current client request; read parameters, headers
responseHttpServletResponseThe response to the client; set headers, redirect
outJspWriterWrites output to the response body
sessionHttpSessionPer-user session for storing attributes
applicationServletContextApplication-wide shared data (one per web app)
configServletConfigConfiguration of the JSP/servlet
pageContextPageContextAccess to all scopes (page, request, session, application)
pageObject (this)Reference to the current JSP page instance
exceptionThrowableAvailable only in error pages (isErrorPage="true")

Example:

<%= request.getParameter("name") %>
<% out.println("Welcome!"); %>

These objects save the developer from manually creating common servlet objects.

jsp
11short5 marks

What is the role of DriverManager in JDBC?

Role of DriverManager in JDBC

java.sql.DriverManager is the basic service for managing JDBC drivers. Its main roles are:

  1. Driver registration — keeps a list of registered Driver implementations (drivers register themselves via DriverManager.registerDriver() or, automatically, when the driver class is loaded).
  2. Establishing connections — when DriverManager.getConnection(url, user, password) is called, it iterates through the registered drivers, finds one that recognizes the given JDBC URL, and returns a Connection object from it.
  3. Driver selection — chooses the appropriate driver for the database URL among all registered drivers.
  4. Login timeout / logging — manages setLoginTimeout() and the log stream for tracing.

Example:

Connection con = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/test", "root", "pass");

In short, DriverManager acts as the bridge between the application and the JDBC driver, supplying the Connection used for all database operations.

jdbc
12short5 marks

Write short notes on datagram sockets.

Datagram Sockets

A datagram socket is the Java endpoint for sending and receiving UDP (User Datagram Protocol) packets. UDP is a connectionless, unreliable transport protocol — packets (datagrams) are sent independently with no guarantee of delivery, ordering, or duplicate protection, but with low overhead and high speed (no handshake).

Key Classes (java.net)

  • DatagramSocket — the socket used to send and receive datagram packets.
  • DatagramPacket — represents a packet: holds the data (byte array), length, destination InetAddress, and port.

Sending and Receiving

// Sender
DatagramSocket socket = new DatagramSocket();
byte[] data = "Hello".getBytes();
DatagramPacket packet = new DatagramPacket(
        data, data.length, InetAddress.getByName("localhost"), 9999);
socket.send(packet);

// Receiver
DatagramSocket recv = new DatagramSocket(9999);
byte[] buf = new byte[1024];
DatagramPacket p = new DatagramPacket(buf, buf.length);
recv.receive(p);                       // blocks until a packet arrives
String msg = new String(p.getData(), 0, p.getLength());

Uses: real-time/streaming applications, online games, DNS, and broadcasting, where speed matters more than guaranteed delivery. Unlike Socket (TCP), datagram sockets do not establish a dedicated connection.

socket

Frequently asked questions

Where can I find the BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) question paper 2078?
The full BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2078 (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) 2078 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) 2078 paper?
The BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2078 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.