AnswerkeyProg QP Template CAT3(Updated)
AnswerkeyProg QP Template CAT3(Updated)
Semester :
Branch :
Sub. Code :
QP Code :
[Regulations ]
Part A [6 x 2 = 12 Marks]
4.4 In Java TCP networking, write classes are used for setting up client and server communication A2 CO4
Answer
TCP through classes like Socket and ServerSocket.
4.5 Compare and cons between connection oriented and connectionless protocol A2 CO4
Answer
Use Cases File transfers, web pages, emails Streaming, VoIP, gaming
Error Handling Built-in error checking and recovery No error checking, managed at application level
4.7 a i) Explain about RMI (Remote Method Invocation). Illustrate the process. A2 CO4
Answer B2
Define the Remote Interface: Declare the methods to be invoked remotely.
Implement the Remote Interface: Create the server-side object that implements the remote interface.
Start the RMI Registry: Use rmiregistry to allow clients to look up remote objects.
Bind the Remote Object: Register the remote object in the registry.
Client Lookup: The client retrieves the remote object using the name it was bound to.
Method Invocation: The client invokes methods on the remote object as if it were local.
ii) Demonstrate rmi code that addition and it includes a remote interface, implementation, server, and client.
Answer
1. Remote Interface (Adder.java)
import java.rmi.Remote;
import java.rmi.RemoteException;
@Override
public int add(int a, int b) throws RemoteException {
return a + b;
}
}
3. RMI Server (AdderServer.java)
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
[OR]
b i)Explain in detail about TCP , UDP and its characteristics with its diagram. A2 CO4
Answer B2
Comparison Between TCP and UDP:
1. TCP is best suited for applications where reliability, data integrity, and ordered delivery are critical, even at the cost of
speed.
2. UDP is ideal for real-time or time-sensitive applications where speed is more important than reliability.
ii) Create a program for client-server application using TCP sockets.The client/server application should send a message.
Answer
TCP Server Code
import java.io.*;
import java.net.*;
try {
// Connect to the server
Socket socket = new Socket(hostname, port);
System.out.println("Connected to the server!");
Part A [6 x 2 = 12 Marks]
5.1 Explain the four attributes needed to draw line in the below code B2 CO5
public abstract void drawLine(int x1, int y1, int x2, int y2)
Answer
The x1, y1 pair is the (X, Y) coordinate of the starting point.
The x2, y2 pair is the (X, Y) coordinate of the ending point.
The line is drawn from the point (x1, y1) to the point (x2, y2) on a 2D coordinate plane, where x is the horizontal axis and y is the vertical
axis.
A layout manager that arranges components in a A more flexible layout manager that arranges components in a
Definition uniform grid of rows and columns. Each cell in the grid, allowing them to span multiple rows or columns. Each
grid has the same size. component can have different sizes and weights.
Fixed number of rows and columns is defined upon Uses a grid of cells where components can occupy multiple
Structure creation. Components fill the grid sequentially from left cells and can vary in size. Layout is determined by
to right and top to bottom. constraints specified for each component.
5.7 a (i)Describe the component hierarchy in Swing.Explain the what are the classes used for different components. A2 CO5
Answer B2
The Swing component hierarchy is designed to facilitate the creation and organization of GUI components in Java
applications.
The base classes Component, Container, and JComponent allow for consistent behavior and properties among
components, while the various classes (like JButton, JLabel, JFrame, etc.) provide specialized functionality.
Understanding this hierarchy is crucial for effectively using Swing to build robust and user-friendly applications
ii) Write a Swing program that creates a login page with two text fields (for username and password), two labels (for the username
and password), and a submit button.
Answer
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// Create labels
JLabel usernameLabel = new JLabel("Username:");
JLabel passwordLabel = new JLabel("Password:");
[OR]
b (i)Describe the architecture of Swing which include details about the Model-View-Controller (MVC) design pattern. A2 CO5
Answer B2
The Swing architecture leverages the MVC design pattern to create a flexible, maintainable, and extensible framework
for building GUI applications.
By separating the data, presentation, and user input, developers can create responsive and interactive applications that
are easier to manage and evolve over time.
ii) Write a Swing program that simulates entering a student’s registration number (Register No) and name. Include two text boxes for
input and two labels to display the field names.
Answer
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// Create labels
JLabel registerNoLabel = new JLabel("Register No:");
registerNoLabel.setBounds(20, 20, 100, 30);
JLabel nameLabel = new JLabel("Name:");
nameLabel.setBounds(20, 60, 100, 30);