1. Explain Stubs and Skeletons with Example.
📆 Asked in Dec 2022, Dec 2023, Jun 2022, Jun 2023
Stub:
• The stub is a client-side proxy that represents the remote object.
• It forwards method calls from the client to the server-side object using the
network.
Skeleton:
• The skeleton was the server-side component that received the method calls and
invoked the appropriate method.
• It was used in Java 1.1, and removed in Java 1.2 onwards (now dynamic proxies
are used).
✅ Mini Code Structure:
java
// Interface
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
// Server
Naming.rebind("rmi://localhost/Hello", new HelloImpl());
// Client
Hello stub = (Hello) Naming.lookup("rmi://localhost/Hello");
System.out.println(stub.sayHello());
Conclusion:
Stub and skeleton act like bridges in RMI communication. Today, only stubs are used
(skeleton is obsolete).
Application: Online chat apps, remote calculator, distributed games.
-------------------------------------------------------------------------
2. Discuss any Three HTML Form Elements.
📆 Asked in Dec 2022, Jun 2022, May 2024
HTML forms allow user input to be submitted to a web server.
✅ Three Common Form Elements:
1. Text Box
html
<input type="text" name="username" />
Used to take single-line input from the user.
2. Radio Button
html
<input type="radio" name="gender" value="male" />
Used to select one option among many.
3. Submit Button
html
<input type="submit" value="Submit" />
Used to submit form data to the server.
Conclusion:
Form elements are essential for user interaction on websites.
Application: Login, registration, feedback, search forms.
________________________________________
3. Explain Servlet Life Cycle.
📆 Asked in Jun 2022, Dec 2023
Servlet lifecycle includes 3 key stages managed by the servlet container.
✅ Stages:
1. init()
• Called only once when the servlet is first loaded.
• Used to initialize resources like DB connections.
2. service()
• Called for every request.
• Calls doGet() or doPost() based on request type.
3. destroy()
• Called once before the servlet is removed.
• Used for cleanup activities.
✅ Mini Code:
java
public void init() { }
public void service() { }
public void destroy() { }
Conclusion:
Understanding servlet lifecycle helps manage resource efficiency and request
handling.
Application: Any backend web application like login or shopping cart.
________________________________________
4. Discuss Session Tracking Methods in Servlet.
📆 Asked in Dec 2023, Jun 2023
Session tracking is used to identify returning users or maintain data across pages.
✅ Methods:
1. Cookies – small data stored on client browser
java
Cookie c = new Cookie("user", "Harisha");
response.addCookie(c);
2. URL Rewriting – adds data to URL
java
<a href="cart.jsp?user=Harisha">Cart</a>
3. HttpSession – server-side session
java
HttpSession session = request.getSession();
session.setAttribute("username", "Harisha");
Conclusion:
Session tracking ensures personalized and secure web sessions.
Application: Shopping carts, login sessions, quiz attempts.
________________________________________
5. Short Notes on JAR File in JavaBeans
📆 Dec 2019, May 2024
Definition:
JAR stands for Java ARchive. It is a compressed file format used to bundle multiple
.class files, images, sound files, and other resources into a single archive file.
🔹 Why is it used in JavaBeans?
• To package and distribute reusable components.
• Allows easy deployment and sharing of beans in IDEs like NetBeans or Eclipse.
• Can include a Manifest file (optional) that tells which class contains the
main method or other metadata.
🔹 Example: Creating a JAR for a JavaBean
bash
jar cf StudentBean.jar Student.class
Where:
• c → create
• f → specify file name
• Student.class → compiled bean
🔹 Manifest Example (optional):
css
Main-Class: Student
✅ Conclusion:
JAR files are essential for organizing and deploying JavaBeans and other reusable
components in a clean, compressed format.
Application: Java libraries, JDBC drivers, JavaBeans in JSP/Servlet-based web apps.
________________________________________
6. Explain the Steps to Create a New Java Bean.
📆 Asked in Dec 2021, Jun 2022
✅ Steps:
1. Create a Public Class
o Class should implement Serializable.
2. Define Private Properties
o Properties should be private.
3. Add Getter and Setter Methods
java
public class Student implements Serializable {
private String name;
public void setName(String name) { this.name = name; }
public String getName() { return name; }
}
4. Compile and Package into JAR (optional)
Conclusion:
JavaBeans follow simple conventions, making them ideal for reusable UI and backend
components.
Application: Form components, backend objects in JSP/Servlets.
________________________________________
7. JSP Scripting / Directive Elements
📆 Asked in Dec 2019, Dec 2023, Jun 2022
✅ Scripting Elements:
1. Scriptlet – Java code block
<% int x = 5; %>
2. Expression – Output of Java expression
<%= x * 2 %>
3. Declaration – Declares variables/methods
<%! int count = 0; %>
✅ Directive Elements:
1. Page – page-related settings
<%@ page language="java" %>
2. Include – includes another file
<%@ include file="header.jsp" %>
3. Taglib – custom tag libraries
<%@ taglib uri="..." prefix="c" %>
Conclusion:
JSP scripting/directives add Java logic and configuration inside HTML pages.
Application: Dynamic pages, backend logic in web apps.
________________________________________
8. Write Short Notes on RMI Client.
📆 Asked in Jun 2023, May 2024
RMI Client connects to the remote object and calls methods defined in the remote
interface.
✅ Steps:
1. Look up remote object via RMI Registry.
2. Typecast to the remote interface.
3. Call the remote method.
✅ Mini Code:
java
Hello stub = (Hello) Naming.lookup("rmi://localhost/Hello");
System.out.println(stub.sayHello());
Conclusion:
RMI clients allow calling methods of remote objects as if they are local.
Application: Remote login, file sharing, remote monitoring.
________________________________________
9. Applet to Servlet Communication
📆 Asked in Dec 2022, May 2024
Applets can communicate with servlets using HTTP protocol and URLConnection.
✅ Steps:
1. Applet sends data using URLConnection.
2. Servlet reads using InputStream or parameters.
✅ Applet Code:
java
URL url = new URL("http://localhost:8080/HelloServlet");
URLConnection con = url.openConnection();
con.setDoOutput(true);
✅ Servlet Code:
java
BufferedReader br = request.getReader();
String input = br.readLine();
Conclusion:
Applet-Servlet communication is useful for GUI + backend logic in Java web apps.
Application: Online forms, quizzes, real-time data updates.
________________________________________
10 marks:-
✅ 1. RMI Registry with Example (Simple Code + Full Explanation)
📅 Asked in May 2021, Jun 2023, May 2024
________________________________________
🔷 What is RMI?
**Remote Method Invocation (RMI)** allows Java programs to invoke methods on an
object located in another JVM (usually on a different
machine).________________________________________
🔷 What is RMI Registry?
• The RMI Registry is a naming service provided by Java to register and locate
remote objects.
• It allows clients to look up remote services using a name, like a phone
directory.
________________________________________
🔷 Simple RMI Flow:
1. Create Remote Interface
2. Implement it in a class
3. Register the object in the RMI Registry
4. Client looks up the object and calls methods
________________________________________
✅ Step-by-Step Example
________________________________________
🔹 1. Remote Interface
java
import java.rmi.*;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
________________________________________
🔹 2. Implementation Class
java
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello {
HelloImpl() throws RemoteException { super(); }
public String sayHello() {
return "Hello from Server";
}
}
________________________________________
🔹 3. Server Program
java
import java.rmi.*;
public class Server {
public static void main(String args[]) throws Exception {
HelloImpl obj = new HelloImpl();
Naming.rebind("rmi://localhost:1099/HelloService", obj);
System.out.println("Server is ready...");
}
}
________________________________________
🔹 4. Client Program
java
import java.rmi.*;
public class Client {
public static void main(String args[]) throws Exception {
Hello stub = (Hello) Naming.lookup("rmi://localhost:1099/HelloService");
System.out.println(stub.sayHello());
}
}
________________________________________
🔹 5. Start the RMI Registry (on Command Prompt):
bash
start rmiregistry
Run it from the folder where .class files are present.
________________________________________
✅ Conclusion:
• The RMI Registry is essential for locating remote objects.
• It acts like a directory server that binds names to remote objects.
• It helps in building distributed applications using Java.
________________________________________
🎯 Application Examples:
• Online quiz system (server sends questions)
• Remote file access system
• Server-based chat/messenger
✅ 2. Explain JavaMail Protocols / Components
📅 Dec 2019, Dec 2021, Dec 2023
________________________________________
🔷 What is JavaMail?
JavaMail is a Java API used to send, receive, and read emails using standard email
protocols like SMTP, POP3, and IMAP.
________________________________________
🔷 JavaMail Protocols
Protocol Description
SMTP Used to send emails (Simple Mail Transfer Protocol)
POP3 Downloads emails from the server (Post Office Protocol v3)
IMAP Reads and manages mail on the server without deleting (Internet Mail Access
Protocol)
________________________________________
🔷 JavaMail Components
1. Session – Stores config and authentication info
2. Message – Represents the email
3. Transport – Sends the message
4. Store – Retrieves messages from mail server
________________________________________
✅ Simple Code to Send Email
java
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@gmail.com"));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("to@gmail.com"));
message.setSubject("Test Mail");
message.setText("This is a test email from Java");
Transport.send(message);
________________________________________
✅ Conclusion:
JavaMail allows Java applications to send and manage emails easily using standard
protocols.
📌 Applications:
• Sending OTP
• Contact form emailers
• Registration confirmation
________________________________________
✅ 3. Servlet Chaining with Example
📅 Dec 2022, Dec 2023
________________________________________
🔷 What is Servlet Chaining?
Servlet chaining allows multiple servlets to work together in a sequence, where one
servlet forwards the request/response to another servlet.
________________________________________
🔷 Two Methods:
• RequestDispatcher.forward() → Passes control
• RequestDispatcher.include() → Includes content
________________________________________
✅ Simple Code
🔸 Servlet 1
java
RequestDispatcher rd = request.getRequestDispatcher("SecondServlet");
rd.forward(request, response);
🔸 Servlet 2
java
PrintWriter out = response.getWriter();
out.println("Welcome to Second Servlet");
________________________________________
✅ Conclusion:
Servlet chaining promotes modular and reusable servlet design, where each servlet
does a specific job.
📌 Applications:
• Authentication + dashboard loading
• Pre-processing and logging
• Multi-step form submissions
______________________________________
__
✅ 4. Applet to Servlet Communication
📅 Dec 2021, Dec 2022
________________________________________
🔷 What is it?
Communication between a Java Applet (GUI client) and a Servlet (backend server) is
done via HTTP using URLConnection.
________________________________________
✅ Applet Code
java
URL url = new URL("http://localhost:8080/MyServlet");
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
out.write("name=Harisha");
out.flush();
________________________________________
✅ Servlet Code
java
BufferedReader br = request.getReader();
String input = br.readLine();
PrintWriter out = response.getWriter();
out.println("Received: " + input);
________________________________________
A connection is opened from the applet to the servlet using the URL.
setDoOutput(true) enables sending data to the servlet.
Data (name=Harisha) is written from the applet to the servlet.
The servlet reads the incoming data using request.getReader().
The servlet responds back with a message using response.getWriter().
✅ Conclusion:
Applet–Servlet communication allows GUI-based clients to interact with backend
logic dynamically.
📌 Applications:
• Online quizzes
• Live form submissions
• GUI → server interaction systems
________________________________________
✅ 5. Explain Database Connectivity in Servlet
📅 Dec 2019, Jun 2023
________________________________________
🔷 What is JDBC?
JDBC (Java Database Connectivity) is a Java API used to connect and perform
operations on databases.
________________________________________
✅ Steps in JDBC with Servlet:
1. Load the driver
2. Establish DB connection
3. Create and execute query
4. Display result
5. Close the connection
________________________________________
✅ Simple Code in Servlet
java
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root",
"1234");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM student");
while(rs.next()) {
out.println("Name: " + rs.getString("name"));
}
________________________________________
✅ Conclusion:
Using JDBC in servlets allows dynamic web apps to interact with databases in real
time.
📌 Applications:
• Login authentication
• Displaying records
• Saving feedback, forms
________________________________________
✅ 6. JavaBeans Development Kit (BDK) / Properties
📅 Dec 2023, Jun 2023
________________________________________
🔷 What is JavaBean?
JavaBean is a reusable software component that follows certain design rules like
having private properties and getter/setter methods.
________________________________________
🔷 Properties of a Bean
• Must be public class
• Should have no-arg constructor
• Should be Serializable
• Uses get/set methods
________________________________________
✅ Sample Bean Code
java
public class Student implements Serializable {
private String name;
public void setName(String n) { this.name = n; }
public String getName() { return name; }
}
________________________________________
🔷 What is BDK?
BDK (Bean Development Kit) is a tool from Sun Microsystems used to:
• Test and configure beans
• Visually drag-drop and connect beans
• Package them into JAR
________________________________________
✅ Conclusion:
JavaBeans + BDK help in building modular and reusable components that work in JSP,
IDEs, and even GUIs.
📌 Applications:
• Visual GUI builders
• JSP backend components
• Business logic reusability
________________________________________
✅ 7. Types of EJB / Session Beans with Example
📅 Dec 2020, Dec 2022, May 2024
________________________________________
🔷 What is EJB?
Enterprise Java Beans (EJB) are server-side components used in large-scale
enterprise apps.
________________________________________
🔷 Types of EJB
1. Session Bean
o Business logic
o Types:
Stateless → No memory of client (e.g., calculator)
Stateful → Remembers client session (e.g., cart)
2. Message-Driven Bean
o Listens to JMS messages
o Used in asynchronous systems
________________________________________
✅ Simple Stateless Bean Code
java
@Stateless
public class CalculatorBean {
public int add(int a, int b) {
return a + b;
}
}
________________________________________
✅ Conclusion:
EJB helps build secure, scalable, transactional systems that are easy to manage.
📌 Applications:
• ATM systems
• Shopping carts
• Booking and payment systems
________________________________________
✅ 8. Push Data from RMI Server
📅 Dec 2022, Jun 2022
________________________________________
🔷 Can RMI push data?
Yes! RMI usually pulls, but using callbacks, the server can push data to the
client.
________________________________________
🔷 How?
1. Client implements a remote interface
2. Server gets client’s stub and calls method on it
3. This way, server pushes data
________________________________________
✅ Conceptual Code
Client's Remote Interface:
public interface Notify extends Remote {
void notifyClient(String msg) throws RemoteException;
}
Server calls:
clientStub.notifyClient("You have a new message!");
________________________________________
✅ Conclusion:
Though RMI is typically pull-based, push notifications are possible using callback
mechanism.
📌 Applications:
• Live chat
• Remote alerts
• Stock market ticker apps
________________________________________
2 marks:-
## ✅ **Repeated 2-Marks Questions – Answers**
### 1. **What is Java Bean?**
A **Java Bean** is a reusable software component that follows specific conventions:
* Public no-argument constructor
* Getter and setter methods for accessing properties
* Serializable
* Example:
```java
public class Student implements Serializable {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
```
---
### 2. **What are the types of EJB?**
* **Session Beans** (stateless/stateful)
* **Entity Beans** (deprecated, replaced by JPA)
* **Message-Driven Beans (MDB)**
> Modern EJB focuses mainly on session and message-driven beans.
---
### 3. **What is Introspection in Java Bean?**
Introspection is the process of analyzing a Bean to:
* Discover its properties, events, and methods at runtime
* Done using **java.beans.Introspector** class
---
### 4. **What is JAR file?**
JAR (Java ARchive) is a package file format that bundles:
* Multiple class files, metadata, and resources
* Into a single compressed file
* Example: `MyApp.jar`
---
### 5. **What are the components of RMI?**
* **Remote Interface**
* **Stub and Skeleton** (skeleton deprecated after Java 1.2)
* **RMI Registry**
* **Remote Object Implementation**
* **Client**
---
### 6. **What is RMI Registry?**
A **name server** that allows clients to look up remote objects via logical names.
* Run using: `rmiregistry`
* Objects must be registered using `Naming.rebind()`
---
### 7. **What is JDBC?**
**Java Database Connectivity** is an API for accessing relational databases.
* Interfaces: `Connection`, `Statement`, `ResultSet`
* Example: `DriverManager.getConnection(...)`
---
### 8. **Write the advantages of Java Beans.**
* Platform independent
* Reusable and portable
* Supports property/event management
* Easy to manipulate using builder tools
---
### 9. **What is the usage of RMI over Inter-ORB Protocol (IIOP)?**
Allows Java RMI applications to interact with CORBA systems.
* Enables **interoperability** between Java and other CORBA-compliant languages
* Uses `javax.rmi.PortableRemoteObject`
---
### 10. **What is a bound property?**
A bound property notifies listeners when its value changes.
* JavaBeans use `PropertyChangeSupport` for this.
```java
pcs.firePropertyChange("propertyName", oldVal, newVal);
```
---
### 11. **State any two applications of RMI technology.**
* Distributed banking applications
* Remote file access and editing
* Chat servers or distributed game engines
---