BSc CSIT (TU) Science Advanced Java Programming (BSc CSIT, CSC409) Question Paper 2078 Nepal
This is the official BSc CSIT (TU) (Science stream) Advanced Java Programming (BSc CSIT, CSC409) question paper for 2078, as set in the regular annual examination. It carries 60 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Advanced Java Programming (BSc CSIT, CSC409) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) exam or solving previous years' question papers, this 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
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().
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
- Define a remote interface that extends
java.rmi.Remote; each method throwsRemoteException. - Implement the interface in a server class (usually extending
UnicastRemoteObject). - Create and start the RMI registry (
rmiregistryorLocateRegistry.createRegistry). - Bind the remote object to the registry using
Naming.rebind(). - Write the client that does a
Naming.lookup()and calls the remote methods. - 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.
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
| Type | Name | How it works | Advantages | Disadvantages |
|---|---|---|---|---|
| Type 1 | JDBC-ODBC Bridge | Translates JDBC calls into ODBC calls | Easy to use; connects to any ODBC source | Slow; ODBC driver/native code needed on client; platform dependent; removed in Java 8 |
| Type 2 | Native-API (partly Java) | JDBC calls converted to native DB client library calls | Faster than Type 1 | Native client library must be installed; platform dependent |
| Type 3 | Network Protocol (pure Java, middleware) | JDBC calls sent to a middleware server which talks to the DB | Pure Java; no client library; can connect to many DBs | Needs a separate middleware server; extra network layer |
| Type 4 | Thin / Native Protocol (pure Java) | Converts JDBC calls directly into the DB's network protocol | Pure Java, platform independent, fastest, no client install | Database-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.
Section B: Short Answer Questions
Attempt any EIGHT questions.
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:
ActionListener— handles action events such as a button click, menu selection, or pressing Enter in a text field. Method:void actionPerformed(ActionEvent e).MouseListener— handles mouse events. Methods:mouseClicked(),mousePressed(),mouseReleased(),mouseEntered(),mouseExited()(all take aMouseEvent).KeyListener— handles keyboard events. Methods:keyPressed(),keyReleased(),keyTyped()(all take aKeyEvent).
Other examples include ItemListener, WindowListener, FocusListener, and MouseMotionListener. A listener is attached to a component using methods like addActionListener().
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 extendjavax.swing.JComponent(which itself extendsjava.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 usingadd(), and their positions/sizes are controlled by the container's layout manager.
| Aspect | Component | Container |
|---|---|---|
| Purpose | An individual UI element | Holds/groups other components |
| Can contain others? | No (leaf) | Yes |
| Layout manager | Not applicable | Has one (e.g. FlowLayout) |
| Examples | JButton, JLabel | JPanel, JFrame |
In short: every container is a component, but not every component is a container.
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".
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
- Application-wide attributes — store and retrieve shared objects available to all servlets:
setAttribute(),getAttribute(),removeAttribute(). - Initialization parameters — read application-level
<context-param>values fromweb.xmlusinggetInitParameter(). - Logging — write to the application log with
context.log(). - Resource access — locate files/resources within the web app using
getResourceAsStream()andgetRealPath(). - Request dispatching — obtain a
RequestDispatcherto forward/include resources. - Server information — obtain container details via
getServerInfo()andgetMajorVersion().
Unlike ServletConfig (one per servlet), ServletContext is global to the entire application, making it ideal for sharing data among servlets.
Differentiate between forward and redirect in servlets.
forward vs redirect (sendRedirect)
| Aspect | Forward (RequestDispatcher.forward) | Redirect (response.sendRedirect) |
|---|---|---|
| Where it happens | On the server side | Client/browser is told to make a new request |
| Number of requests | Single request | Two requests (original + new) |
| URL in browser | Unchanged (URL of original resource) | Changes to the new URL |
| Request data | Same request object is passed; request attributes preserved | New request; attributes lost (data must go via URL/session) |
| Target | Resource within the same application | Any resource, even a different server/site |
| Speed | Faster (no extra round trip) | Slower (extra round trip) |
| Example | request.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).
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.
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:
| Object | Type | Description |
|---|---|---|
request | HttpServletRequest | The current client request; read parameters, headers |
response | HttpServletResponse | The response to the client; set headers, redirect |
out | JspWriter | Writes output to the response body |
session | HttpSession | Per-user session for storing attributes |
application | ServletContext | Application-wide shared data (one per web app) |
config | ServletConfig | Configuration of the JSP/servlet |
pageContext | PageContext | Access to all scopes (page, request, session, application) |
page | Object (this) | Reference to the current JSP page instance |
exception | Throwable | Available only in error pages (isErrorPage="true") |
Example:
<%= request.getParameter("name") %>
<% out.println("Welcome!"); %>
These objects save the developer from manually creating common servlet objects.
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:
- Driver registration — keeps a list of registered
Driverimplementations (drivers register themselves viaDriverManager.registerDriver()or, automatically, when the driver class is loaded). - 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 aConnectionobject from it. - Driver selection — chooses the appropriate driver for the database URL among all registered drivers.
- 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.
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, destinationInetAddress, 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.
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.