BSc CSIT (TU) Science Advanced Java Programming (BSc CSIT, CSC409) Question Paper 2079 Nepal
This is the official BSc CSIT (TU) (Science stream) Advanced Java Programming (BSc CSIT, CSC409) question paper for 2079, 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 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
Explain the delegation event model. Write a Swing program that demonstrates handling of action events and item events on multiple components.
Delegation Event Model
The delegation event model is the approach used in Java (AWT/Swing) to handle events. In this model, an event source (a GUI component) generates an event object, and delegates the responsibility of handling it to one or more registered event listeners.
Three key participants:
- Event Source – the component (button, checkbox, etc.) that generates the event.
- Event Object – an object (e.g.
ActionEvent,ItemEvent) encapsulating information about what happened. - Event Listener – an object that implements a listener interface (e.g.
ActionListener,ItemListener) and contains the handler methods.
Working: A listener registers itself with a source using a addXxxListener() method (e.g. button.addActionListener(this)). When the user interacts, the source creates an event object and invokes the appropriate callback method on every registered listener. This decouples the GUI component from the handling logic.
Swing Program: Action + Item Events
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class EventDemo extends JFrame
implements ActionListener, ItemListener {
JButton btn;
JCheckBox chk;
JLabel label;
public EventDemo() {
setLayout(new FlowLayout());
btn = new JButton("Click Me");
chk = new JCheckBox("Enable");
label = new JLabel("Status: ready");
// Register this object as listener (delegation)
btn.addActionListener(this);
chk.addItemListener(this);
add(btn); add(chk); add(label);
setSize(300, 150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
// Handles ActionEvent from the button
public void actionPerformed(ActionEvent e) {
label.setText("Button clicked!");
}
// Handles ItemEvent from the checkbox
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)
label.setText("Checkbox selected");
else
label.setText("Checkbox deselected");
}
public static void main(String[] args) {
new EventDemo();
}
}
Here the JButton is the source of an ActionEvent (handled by actionPerformed) and the JCheckBox is the source of an ItemEvent (handled by itemStateChanged), demonstrating the delegation model with multiple components.
What is JSP? Compare JSP with Servlet. Develop a JSP application that connects to a database and displays records in a table.
What is JSP?
JSP (JavaServer Pages) is a server-side technology that lets developers embed Java code inside HTML pages using special tags. JSP pages are automatically translated into servlets by the web container (e.g. Tomcat) and compiled at first request. JSP simplifies the creation of dynamic web content by separating presentation (HTML) from business logic.
JSP vs Servlet
| Aspect | JSP | Servlet |
|---|---|---|
| Nature | HTML with embedded Java | Pure Java class |
| Best for | Presentation / view layer | Processing / controller layer |
| Coding | Less code, HTML-centric | More code, Java-centric |
| Modification | No recompilation needed; container retranslates | Must recompile and redeploy |
| MVC role | View | Controller |
| Implicit objects | Available (request, out, session...) | Must be obtained manually |
Internally a JSP is a servlet — the container translates the .jsp into .java, compiles it, and runs it.
JSP + JDBC Application (display records in a table)
<%@ page import="java.sql.*" %>
<html>
<head><title>Student Records</title></head>
<body>
<h2>Student List</h2>
<table border="1">
<tr><th>ID</th><th>Name</th><th>Marks</th></tr>
<%
Connection con = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/college", "root", "password");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT id, name, marks FROM student");
while (rs.next()) {
%>
<tr>
<td><%= rs.getInt("id") %></td>
<td><%= rs.getString("name") %></td>
<td><%= rs.getInt("marks") %></td>
</tr>
<%
}
rs.close(); st.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
} finally {
if (con != null) con.close();
}
%>
</table>
</body>
</html>
This page loads the JDBC driver, opens a connection, executes a query, and iterates the ResultSet to render each row inside an HTML <table>.
Explain socket programming. Write a multithreaded TCP server program in Java that can handle multiple clients simultaneously.
Socket Programming
A socket is one endpoint of a two-way communication link between two programs running on a network. Socket programming uses these endpoints (identified by an IP address and a port number) to exchange data over TCP or UDP. Java provides socket classes in the java.net package:
ServerSocket– used by a server to listen on a port andaccept()incoming client connections.Socket– represents a connection between client and server; providesgetInputStream()andgetOutputStream()for I/O.
For TCP (connection-oriented), the server creates a ServerSocket, calls accept() (which blocks until a client connects and returns a Socket), and then reads/writes through the streams. A single-threaded server can serve only one client at a time, so we use multithreading to handle many clients concurrently.
Multithreaded TCP Server
import java.io.*;
import java.net.*;
public class MultiThreadServer {
public static void main(String[] args) throws IOException {
ServerSocket server = new ServerSocket(5000);
System.out.println("Server listening on port 5000...");
while (true) {
Socket client = server.accept(); // wait for a client
System.out.println("Connected: " + client.getInetAddress());
new ClientHandler(client).start(); // one thread per client
}
}
}
class ClientHandler extends Thread {
private Socket socket;
ClientHandler(Socket s) { this.socket = s; }
public void run() {
try (
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true)
) {
String line;
while ((line = in.readLine()) != null) {
System.out.println("Client says: " + line);
out.println("Echo: " + line); // reply to client
if (line.equalsIgnoreCase("bye")) break;
}
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try { socket.close(); } catch (IOException ignored) {}
}
}
}
The main loop continuously accepts connections; for each accepted Socket it spawns a new ClientHandler thread, so multiple clients are served simultaneously and independently.
Section B: Short Answer Questions
Attempt any EIGHT questions.
What is an event source and an event listener?
Event source: An object (typically a GUI component such as a JButton, JTextField or JCheckBox) that generates an event when the user interacts with it. The source creates an event object and notifies all registered listeners. Listeners register with a source via methods like addActionListener().
Event listener: An object that listens for and responds to events from a source. It implements a listener interface (e.g. ActionListener, ItemListener) and provides the callback method (e.g. actionPerformed()) that the source invokes when the event occurs.
In short, the source produces the event and the listener consumes/handles it.
Explain the JScrollPane and JTabbedPane components.
JScrollPane: A Swing container that provides a scrollable view of another (usually larger) component such as a JTextArea, JTable or JList. When the content is bigger than the visible area, JScrollPane automatically adds horizontal and/or vertical scroll bars. Scrollbar policy can be set with setHorizontalScrollBarPolicy() / setVerticalScrollBarPolicy().
JTextArea ta = new JTextArea(20, 30);
JScrollPane sp = new JScrollPane(ta);
frame.add(sp);
JTabbedPane: A Swing component that lets you group several components into a set of tabs, of which only one is visible at a time. Clicking a tab brings the corresponding panel to the front, saving screen space. Tabs are added with addTab(title, component).
JTabbedPane tp = new JTabbedPane();
tp.addTab("Home", homePanel);
tp.addTab("Settings", settingsPanel);
frame.add(tp);
Thus JScrollPane adds scrolling to a single component, while JTabbedPane switches between multiple panels using tabs.
What are the advantages of PreparedStatement over Statement?
Advantages of PreparedStatement over Statement:
- Precompilation / performance: A
PreparedStatementis compiled (parsed and optimized) once by the database and can be executed many times with different parameter values, making it faster for repeated queries. - Prevents SQL injection: Parameters are supplied with
setXxx()methods and are properly escaped, so user input cannot alter the query structure — unlike string concatenation used withStatement. - Cleaner, type-safe parameter handling: Values are bound by type (
setInt,setString,setDate...) using?placeholders, avoiding manual quoting and formatting errors. - Reusability / readability: The same statement object can be reused with new parameter values, and the code is easier to read and maintain.
PreparedStatement ps = con.prepareStatement(
"INSERT INTO student(id,name) VALUES(?,?)");
ps.setInt(1, 101);
ps.setString(2, "Ram");
ps.executeUpdate();
Statement is suitable for simple, one-off static queries, whereas PreparedStatement is preferred for parameterized and repeated queries.
Explain session tracking using URL rewriting.
Session Tracking using URL Rewriting
HTTP is stateless, so a server needs a mechanism to recognize requests belonging to the same user. URL rewriting is one such session-tracking technique.
Concept: The session identifier (and optionally other data) is appended to the URL of every link/redirect that the response sends back to the client. When the client clicks the link, the appended data returns to the server, which uses it to identify the session. It is typically appended as a path parameter, e.g.:
http://host/app/page?sessionid=ABC123
In servlets, the container does this automatically through response.encodeURL():
String url = response.encodeURL("servlet2?user=" + name);
out.println("<a href='" + url + "'>Next</a>");
If the browser supports cookies the id is kept in a cookie; otherwise encodeURL() appends ;jsessionid=... to the URL.
Advantages: Works even when cookies are disabled in the browser.
Disadvantages: Only small amounts of data can be carried, the data is visible in the URL (insecure), every URL must be rewritten, and it works only with dynamically generated links.
What is the difference between a stateless and stateful session?
Stateless vs Stateful Session
| Aspect | Stateless Session | Stateful Session |
|---|---|---|
| Conversational state | Does not maintain client-specific state between method calls | Maintains the client's state across multiple requests |
| Client binding | Any instance can serve any client; instances are pooled and shared | Dedicated to a single client for the whole conversation |
| Memory | Lightweight, low memory overhead | Heavier, holds per-client data in memory |
| Use case | Independent, self-contained operations (e.g. tax calculation, currency conversion) | Multi-step workflows (e.g. shopping cart, multi-page form) |
| Scalability | Highly scalable | Less scalable (state must be kept) |
Stateless session: Each request is independent; the server keeps no memory of previous interactions with that client. Example: a stateless EJB or a REST endpoint that simply computes and returns a result.
Stateful session: The server remembers data across several requests from the same client (the "conversation"), such as items added to a cart over multiple pages. State is preserved until the session ends or times out.
Describe the layers of RMI architecture.
Layers of RMI Architecture
Java RMI (Remote Method Invocation) lets an object running in one JVM invoke methods on an object in another JVM. Its architecture has three main layers between the client and server:
-
Stub and Skeleton Layer (Proxy layer):
- The stub resides on the client side and acts as a proxy for the remote object. It marshals (packs) the method name and arguments and forwards the call.
- The skeleton resides on the server side; it unmarshals the request, invokes the actual method on the remote object, and sends back the result. (In modern Java the skeleton is generated dynamically.)
-
Remote Reference Layer (RRL):
- Handles the semantics of the invocation and how clients connect to remote objects — managing references, connection setup, and invocation type (e.g. unicast point-to-point). It links the stub/skeleton layer to the transport layer.
-
Transport Layer:
- Responsible for the actual network communication (typically over TCP/IP) — setting up connections, managing them, listening for incoming calls, and transmitting the marshalled data between the two JVMs.
A separate component, the RMI Registry, lets the server bind remote objects by name and lets clients look them up to obtain a stub.
What are JSP actions? Explain any two standard actions.
JSP Actions
JSP action tags are XML-style tags (<jsp:...>) that control the runtime behaviour of the JSP engine — for example, including pages, forwarding requests, or working with JavaBeans. They are executed when the page is requested (at request time), unlike directives which act at translation time.
Two standard actions:
-
<jsp:include>– Includes the output of another resource (JSP/HTML/servlet) into the current page at request time (dynamic include). The included page is processed separately and its response is merged.<jsp:include page="header.jsp" /> -
<jsp:forward>– Forwards the current request to another resource (page/servlet). Control does not return to the original page; the target generates the response.<jsp:forward page="login.jsp" />
Other standard actions include <jsp:useBean>, <jsp:setProperty>, <jsp:getProperty>, and <jsp:param>.
How is database connection pooling done? Explain briefly.
Database Connection Pooling
Connection pooling is a technique to reuse a set of pre-created database connections instead of opening and closing a new connection for every request. Because creating a JDBC connection is expensive (network handshake, authentication), a pool dramatically improves performance and scalability.
How it works:
- At startup, the pool (managed by a
DataSource) creates a fixed number of physical connections and keeps them in a pool. - When the application needs a connection it borrows one from the pool via
dataSource.getConnection(). - After use, calling
connection.close()does not physically close it — it returns the connection to the pool for reuse. - The pool manages limits such as minimum/maximum size, idle timeout, and validation of stale connections.
Implementation: Typically done with a connection-pool library / DataSource such as Apache DBCP, HikariCP, c3p0, or a JNDI DataSource configured in the application server (e.g. Tomcat).
BasicDataSource ds = new BasicDataSource();
ds.setUrl("jdbc:mysql://localhost/test");
ds.setUsername("root");
ds.setPassword("pwd");
ds.setInitialSize(5);
ds.setMaxTotal(20);
Connection con = ds.getConnection(); // borrowed from pool
Benefits: Reduced connection-creation overhead, better response time, controlled number of connections, and improved scalability under load.
Write short notes on the InetAddress class.
InetAddress Class
The java.net.InetAddress class represents an IP address (both IPv4 and IPv6) and provides methods to perform name/address resolution between a host name and its IP address (DNS lookup).
Key points:
- It has no public constructor; objects are obtained through static factory methods.
- It encapsulates both the host name and the corresponding numeric IP address.
Common methods:
| Method | Purpose |
|---|---|
getByName(String host) | Returns an InetAddress for the given host name |
getLocalHost() | Returns the InetAddress of the local machine |
getAllByName(String host) | Returns all IP addresses associated with a host |
getHostName() | Returns the host name |
getHostAddress() | Returns the IP address as a string |
Example:
import java.net.*;
public class Demo {
public static void main(String[] a) throws Exception {
InetAddress ip = InetAddress.getByName("www.google.com");
System.out.println("Host: " + ip.getHostName());
System.out.println("IP: " + ip.getHostAddress());
InetAddress local = InetAddress.getLocalHost();
System.out.println("Local: " + local);
}
}
It is widely used in socket programming to resolve and identify hosts.
Frequently asked questions
- Where can I find the BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) question paper 2079?
- The full BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2079 (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) 2079 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) 2079 paper?
- The BSc CSIT (TU) Advanced Java Programming (BSc CSIT, CSC409) 2079 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.