PROGRAM CODING:
import [Link];
import [Link];
public class ExceptionHandlingWithThrow {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
try {
[Link]("Enter the first number: ");
int num1 = getInput(scanner);
[Link]("Enter the second number: ");
int num2 = getInput(scanner);
if (num2 == 0) {
throw new ArithmeticException("Division by zero is not allowed!");
int result = num1 / num2;
[Link]("The result of " + num1 + " / " + num2 + " is: " + result);
catch (InputMismatchException e) {
[Link]("Error: Invalid input! Please enter valid integers.");
catch (ArithmeticException e) {
[Link]("Error: " + [Link]());
catch (Exception e) {
[Link]("An unexpected error occurred: " + [Link]());
}
finally {
[Link]("Thank you for using the program!");
[Link]();
public static int getInput(Scanner scanner) throws InputMismatchException {
int num = 0;
try {
num = [Link]();
} catch (InputMismatchException e) {
throw new InputMismatchException("You must enter a valid integer.");
return num;
}
OUTPUT:
Enter the first number: 15
Enter the second number: 3
The result of 15 / 3 is: 5
Thank you for using the program!
Enter the first number: 3
Enter the second number: 0
Error: Division by zero is not allowed!
Thank you for using the program!
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class SimpleCalculator {
private JFrame frame;
private JTextField textField;
private double num1, num2, result;
private String operator;
public static void main(String[] args) {
[Link](() -> new SimpleCalculator().initialize());
public void initialize() {
frame = new JFrame("Simple Calculator");
[Link](100, 100, 300, 400);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](new BorderLayout());
textField = new JTextField();
[Link](new Font("Arial", [Link], 24));
[Link](false);
[Link](textField, [Link]);
JPanel panel = new JPanel();
[Link](new GridLayout(4, 4, 5, 5));
String[] buttons = {
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"0", ".", "=", "+"
};
for (String text : buttons) {
JButton button = new JButton(text);
[Link](new Font("Arial", [Link], 24));
[Link](this::buttonClicked);
[Link](button);
[Link](panel, [Link]);
JButton clearButton = new JButton("C");
[Link](new Font("Arial", [Link], 24));
[Link](e -> [Link](""));
[Link](clearButton, [Link]);
[Link](true);
private void buttonClicked(ActionEvent e) {
JButton source = (JButton) [Link]();
String text = [Link]();
if ([Link]("[0-9]") || [Link](".")) {
[Link]([Link]() + text);
} else if ([Link]("=")) {
num2 = [Link]([Link]());
switch (operator) {
case "+" -> result = num1 + num2;
case "-" -> result = num1 - num2;
case "*" -> result = num1 * num2;
case "/" -> result = (num2 != 0) ? num1 / num2 : [Link];
[Link]([Link](result));
operator = ""; // Reset operator after calculation
} else {
if (![Link]().isEmpty()) {
num1 = [Link]([Link]());
operator = text;
[Link]("");
}
OUTPUT:
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
[Link]
import [Link];
import [Link].*;
import [Link].*;
public class MyServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try (PrintWriter out = [Link]()) {
[Link](“<h2>Welcome to my first servlet application in netbeans</h2>”;
finally{
[Link]();
[Link]
!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h4>click here to go to <a href="hello">MyServlet Page</a></h4>
</body>
</html>
[Link]
<?xml version="1.0" encoding="UTF-8"?>
<web-appversion="3.1"xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
<context-param>
<param-name>[Link].PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>[Link]</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/[Link]</welcome-file>
</welcome-file-list>
</web-app>
OUTPUT:
Click here to go to MyServlet page
Welcome to my first servlet application in netbeans
RESULT:
Thus ,the program executed successfully and got the desired output
PROGRAM CODING:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Order Form</title>
</head>
<body>
<h2>Purchase Order Form</h2>
<form action="SubmitPurchaseOrderServlet" method="post">
Order ID: <input type="text" name="orderId"><br><br>
Customer Name: <input type="text" name="customerName"><br><br>
Product: <input type="text" name="product"><br><br>
Quantity: <input type="number" name="quantity"><br><br>
Price: <input type="number" name="price" step="0.01"><br><br>
Shipping Address: <textarea name="shippingAddress"></textarea><br><br>
<input type="submit" value="Submit Order">
</form>
</body>
</html>
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class SubmitPurchaseOrderServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String orderId = [Link]("orderId");
String customerName = [Link]("customerName");
String product = [Link]("product");
int quantity = [Link]([Link]("quantity"));
double price = [Link]([Link]("price"));
double totalCost = quantity * price;
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<html><body>");
[Link]("<h3>Order Summary</h3>");
[Link]("<p>Order ID: " + orderId + "</p>");
[Link]("<p>Customer Name: " + customerName + "</p>");
[Link]("<p>Product: " + product + "</p>");
[Link]("<p>Quantity: " + quantity + "</p>");
[Link]("<p>Total Cost: $" + totalCost + "</p>");
[Link]("<p><a href='[Link]'>Back to form</a></p>");
[Link]("</body></html>");
[Link]
<web-app xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
version="3.0">
<servlet>
<servlet-name>SubmitPurchaseOrderServlet</servlet-name>
<servlet-class>SubmitPurchaseOrderServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SubmitPurchaseOrderServlet</servlet-name>
<url-pattern>/SubmitPurchaseOrderServlet</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
Purchase Order Form -
Order ID: [____________________]
Customer Name: [____________________]
Product: [____________________]
Quantity: [_________]
Price: [_________]
Shipping Address:
[_________________________________________]
[_________________________________________]
[ Submit Order ]
Order Summary
Order ID: PO1321
Customer Name: SARITHA
Product: Laptop
Quantity: 2
Total Cost: $1000
|[ Back to form ]
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
[Link]
<%@ page import="[Link].*" %>
<%@pagelanguage="java"contentType="text/html;charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Calculate Percentage</title>
</head>
<body>
<%
int marks1 = [Link]([Link]("marks1"));
int marks2 = [Link]([Link]("marks2"));
int marks3 = [Link]([Link]("marks3"));
int marks4 = [Link]([Link]("marks4"));
int marks5 = [Link]([Link]("marks5"));
int totalMarks = marks1 + marks2 + marks3 + marks4 + marks5;
double percentage = (totalMarks / 500.0) * 100;
[Link]("totalMarks", totalMarks);
[Link]("percentage", percentage);
%>
<%
RequestDispatcher dispatcher = [Link]("[Link]");
[Link](request, response);
%>
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Student Percentage Calculation</title>
</head>
<body>
<h2>Enter Student Marks</h2>
<form action="[Link]" method="post">
<label for="marks1">Marks in Subject 1:</label>
<input type="number" name="marks1" required /><br><br>
<label for="marks2">Marks in Subject 2:</label>
<input type="number" name="marks2" required /><br><br>
<label for="marks3">Marks in Subject 3:</label>
<input type="number" name="marks3" required /><br><br>
<label for="marks4">Marks in Subject 4:</label>
<input type="number" name="marks4" required /><br><br>
<label for="marks5">Marks in Subject 5:</label>
<input type="number" name="marks5" required /><br><br>
<input type="submit" value="Calculate Percentage" />
</form>
</body>
</html>
[Link]
<%@pagelanguage="java"contentType="text/html;charset=ISO-8859-1pageEncoding="ISO-
8859-1"%><html>
<head>
<title>Result</title>
</head>
<body>
<h2>Student Marks Calculation Result</h2>
<%
int totalMarks = (Integer) [Link]("totalMarks");
double percentage = (Double) [Link]("percentage");
%>
<p>Total Marks: <%= totalMarks %> / 500</p>
<p>Percentage: <%= percentage %> %</p>
<%
String grade;
if (percentage >= 90) {
grade = "A";
} else if (percentage >= 75) {
grade = "B";
} else if (percentage >= 50) {
grade = "C";
} else {
grade = "F";
%>
<p>Grade: <%= grade %></p>
<br><br>
<a href="[Link]">Go Back</a>
</body>
</html>
OUTPUT:
Enter Student Marks
Marks in Subject 1: 89
Marks in Subject 2: 98
Marks in Subject 3: 97
Marks in Subject 4: 86
Marks in Subject 5: 99
CALCULATE PERCENTAGE
Student Marks Calculation Result
Total Marks: 469 / 500
Percentage: 93.8 %
Grade: A
Go Back
RESULT:
Thus ,the program executed successfully and got the desired output
PROGRAM CODING:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Pay Slip Form</title>
</head>
<body>
<h2>Employee Pay Slip Form</h2>
<form action="[Link]" method="post">
Employee ID: <input type="text" name="employeeId"><br><br>
Employee Name: <input type="text" name="employeeName"><br><br>
Basic Salary: <input type="number" name="basicSalary"><br><br>
Bonus: <input type="number" name="bonus"><br><br>
Deductions: <input type="number" name="deductions"><br><br>
<input type="submit" value="Generate Pay Slip">
</form>
</body>
</html>
[Link]
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%
String employeeId = [Link]("employeeId");
String employeeName = [Link]("employeeName");
double basicSalary = [Link]([Link]("basicSalary"));
double bonus = [Link]([Link]("bonus"));
double deductions = [Link]([Link]("deductions"));
double totalSalary = basicSalary + bonus - deductions;
%>
<html>
<head>
<title>Employee Pay Slip</title>
</head>
<body>
<h3>Employee Pay Slip</h3>
<p><b>Employee ID:</b> <%= employeeId %></p>
<p><b>Employee Name:</b> <%= employeeName %></p>
<p><b>Basic Salary:</b> $<%= basicSalary %></p>
<p><b>Bonus:</b> $<%= bonus %></p>
<p><b>Deductions:</b> $<%= deductions %></p>
<p><b>Total Salary:</b> $<%= totalSalary %></p>
</body>
</html>
OUTPUT:
Employee Pay Slip Form
Employee ID: [__________]
Employee Name: [__________]
Basic Salary: [__________]
Bonus: [__________]
Deductions: [__________]
[Submit Pay Slip]
Employee Pay Slip
Employee ID: e031
Employee Name: SARITHA
Basic Salary: $5000.0
Bonus: $500.0
Deductions: $200.0
Total Salary: $5300.0
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
</head>
<body>
<h2>Contact Us</h2>
<form action="handleFormData" method="post">
Name: <input type="text" name="name"><br><br>
Email: <input type="email" name="email"><br><br>
Message: <textarea name="message"></textarea><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class FormDataServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String name = [Link]("name");
String email = [Link]("email");
String message = [Link]("message");
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<html><body>");
[Link]("<h2>Form Data Submitted</h2>");
[Link]("<p><b>Name:</b> " + name + "</p>");
[Link]("<p><b>Email:</b> " + email + "</p>");
[Link]("<p><b>Message:</b> " + message + "</p>");
[Link]("</body></html>");
}
OUTPUT:
Contact Us
Name: [_____________]
Email: [_____________]
Message: [____________________]
[____________________]
[Submit]
Name: SARITHA
Email: sarithap0911@[Link]
Message: "Hello, I need assistance."
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="[Link].*, [Link].*" %>
<%
HttpSession session = [Link]();
String name = [Link]("name");
String email = [Link]("email");
if (name != null && email != null) {
[Link]("userName", name);
[Link]("userEmail", email);
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
</head>
<body>
<h2>Registration Form</h2>
<!-- Form to input name and email -->
<form method="post">
Name: <input type="text" name="name" value="<%= [Link]("userName")
!= null ? [Link]("userName") : "" %>"><br><br>
Email: <input type="email" name="email" value="<%=
[Link]("userEmail") != null ? [Link]("userEmail") : ""
%>"><br><br>
<input type="submit" value="Submit">
</form>
<hr>
<%
String savedName = (String) [Link]("userName");
String savedEmail = (String) [Link]("userAge");
if (savedName != null && savedAge != null) {
[Link]("<h3>Your Submitted Information:</h3>");
[Link]("<p>Name: " + savedName + "</p>");
[Link]("<p>Age: " + savedAge + "</p>");
} else {
[Link]("<p>No data available. Please fill out the form above.</p>");
%>
</body>
</html>
OUTPUT:
Registration Form
Name: SARITHA
Age: 21
[Submit]
Your Submitted Information:
Name: SARITHA
Age:21
RESULT:
Thus ,the program executed successfully and got the desired output.
PROGRAM CODING:
[Link]
import [Link].* ;
public interface Adder extends Remote{
public int add(int n1, int n2)throws RemoteException;
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link] implements adder{
public class server extends UnicastRemoteException{
//super();
@Override
public int add(int n1,int n2) throws RemoteException{
return n1 + n2;
public static void main(String [] args)throws RemoteException{
try{
Registry reg=[Link](9999);
[Link](“hi server”,new server());
[Link](“server is ready”);
catch(Remote Exception e){
[Link](“exception”+e);
}
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
public class client
public static void main(String [] args)throws RemoteException{
client c=new client();
[Link]();
Private void connectRemote() throws RemoteException{
try{
Scanner sc=new Scanner([Link]);
Registry reg=[Link](“localhost”,9999);
adder add=(adder)[Link](“hi server”);
[Link](“Enter Two Number”);
int a=[Link]();
int b=[Link]();
[Link](“Addition is” + [Link](a,b));
catch(Remote Exception e){
[Link](“exception”+e);
}
OUTPUT:
Enter two Numbers
Addition is 11
RESULT:
Thus ,the program executed successfully and got the desired output