0% found this document useful (0 votes)
13 views57 pages

Java

This document outlines the practical record for the Master of Science in Computer Science program at Vivekanandha Arts and Science College for Women for the academic year 2024-2025. It includes various advanced Java lab programs, such as creating servlets, JSP applications, and handling data with JDBC. Each section provides the aim, algorithm, program code, and results for the practical exercises conducted by the students.

Uploaded by

priyacs104
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views57 pages

Java

This document outlines the practical record for the Master of Science in Computer Science program at Vivekanandha Arts and Science College for Women for the academic year 2024-2025. It includes various advanced Java lab programs, such as creating servlets, JSP applications, and handling data with JDBC. Each section provides the aim, algorithm, program code, and results for the practical exercises conducted by the students.

Uploaded by

priyacs104
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VIVEKANANDHA

ARTS AND SCIENCE COLLEGE FOR WOMEN


( AFFILIATED TO PERIYAR UNIVERSITY, SALEM)

VEERACHIPALAYAM, SANKARI WEAST, SANKARI-637303

MASTER OF SCIENCE IN COMPUTER SCIENCE

PRACTICAL RECORD

NAME: __________________________

[Link]: __________________________

FIRST YEAR (II-SEMESTER)

PRACTICAL - (23PCSCP04)

ADVANCED JAVA LAB PROGRAMING

2024-2025
VIVEKANANDHA
ARTS AND SCIENCE COLLEGE FOR WOMEN
(AFFILIATED TO PERIYAR UNIVERSITY, SALEM)

VEERACHIPALAYAM, SANKARI EAST, SANKARI-637303

MASTER OF SCIENCE IN COMPUTER SCIENCE

Certified that this is a bonafide record of practical work done by


Miss _______________________in the computer laboratory during
the year 2024 -2025 in VIVEKANANDHA ARTS AND SCIENCE
COLLEGE FOR WOMEN, SANKARI.

Staff In-Charge Head of the Department

Submitted for the University Practical Examination held


on____/___/_______ at Computer Science and Computer
Application Department, Vivekanandha Arts And Science College
for Women, Sankari.

INTERNAL EXTERNAL
INDEX

[Link] DATE NAME OF THE PROGRAM [Link]

1 WELCOME MESSAGE USING SERVLET 2

2 PURCHASE ORDER 6

3 STUDENT MARKS 11

4 PURCHASE ORDER USING JSP 16

5 EMPLOYEE PAY SLIP USING JSP 20

JDBC FOR CREATING A TABLE


6 INSERTING,DELETING RECORDS 25

7 HANDLE FORM DATA 29

8 CREATE A TABLE 34

9 SESSION OBJECT USING JSP 37

BUILD A SIMPLE CLIENT SERVER APPLICATION


10 41
USING RMI

11 CALCULATOR APPLICATION USING APPLET 46

SEND AND RECEIVE A MESSAGE ONE SYSTEM


52
12 TO ANOTHER SYSTEM USING SOCKET
PROGRAMMING

1
[Link]: 01
WELCOME MESSAGE USING SERVLET

DATE:

AIM:
To display a welcome message using Servlet.

ALGORITHM:
STEP 1: Create a new web project in NetBeans, File-> New project->
Java Web-> Web application.
STEP 2: Create a HTML file as Named [Link] and write a code.
STEP 3: Create a Servlet as file named [Link] Create a package
and class.
STEP 4: Configuring Servelt using Servlet Mapping.
STEP 5: Start NetBeans GlashFish server and deploy project.
STEP 6: Run the project.

2
PROGRAM:
SERVLET CODING ([Link])
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet(urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try (PrintWriter out = [Link]()) {
[Link]("<h1> WELCOME TO SERVLET </h1>");
[Link]("<h1> WELCOME TO COMPUTER SCIENCE DEPARTMENT </h1>");
}
}
}

3
HTML CODING ([Link])

<html>

<head>

<meta charset="UTF-8">

<title>First servlet page</title>

</head>

<body>Welcome to servlet world <br><br>

<form action="NewServlet" method= "get">

<input type="submit name=="ss" value="CLICK ME">

</form>

</body>

</html>

4
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

5
[Link]: 02
PURCHASE ORDER USING SERVLET

DATE:

AIM:
To design a Purchase Order form using Html form and Servlet.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application
STEP 2: Create a HTML file as Named [Link] and write a code.
STEP 3: Create a Servlet as file named [Link] Create a package
and class.
STEP 4: Configuring Servelt using Servlet Mapping.
STEP 5: Start NetBeans GlashFish server and deploy project.
STEP 6: Run the project.

6
PROGRAM:
SERVLET CODING ([Link])

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class NewServlet extends HttpServlet

public void service(ServletRequest request,ServletResponse response)

throws ServletException,IOException

String productno= [Link]("productno");

String productname=[Link]("productname");

String address=[Link]("address");

String phoneno=[Link]("phoneno");

String JeanType=[Link]("JeanType");

String od=[Link]("od");

int amt=[Link]([Link]("amt"));

[Link]("text/html");

PrintWriter pw=[Link]();

[Link]("<h2>Following data received successfully...</h2><br>");

7
[Link]("<h2>Product no:"+productno+"</h2><br>");

[Link]("<h2>Product name:"+productname+"</h2><br>");

[Link]("<h2>Address:"+address+"</h2><br>");

[Link]("<h2>Phone no:"+phoneno+"</h2><br>");

[Link]("<h2>JeanType:"+JeanType+"</h2><br>");

[Link]("<h2>Order date:"+od+"</h2><br>");

[Link]("<h2>Amount:"+amt+"</h2><br>");

8
HTML CODING ([Link])

<html>
<head>
<title>Purchase order</title>
</head>
<body>
<h1>Please tell about product</h1>
<form action=”NewServlet”>
Purchase Order No:<input type=”text” name=”productno”>
Product Name : <input type=”text” name=”productname”>
Address:<input type=”text” name=”address”><br>
Phone no:<input type=”text” name=”phoneno”><br>
<p> Items to be ordered: <select name=”JeanType”>
<option value=”Lenin”>Lenin</option>
<option value=”Otto”>OTTO</option>
<option value=”V-Star”>V-Star</option>
<option value=”Peter”>Peter</option>
<option value=”Pantaloon”>Pantaloon</option>
</select>
<br>
Ordered Date:<input type=”date” name=”od”>
Amount:<input type=”number” name=”amt”>
<input type="submit" value="Submit Query">
</form>
</body>
</html>

9
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

10
[Link]: 03
STUDENT MARK LIST USING JSP

DATE:

AIM:
To develop a program for calculating the percentage of marks of a student
using JSP.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a HTML file as Named [Link] and Get student
rollno, name, Marks using input tag.
STEP 3: Then Create a JSP file as named [Link] and Perform a
calculation Opeartion and display student data.
STEP 4: Start NetBeans GlashFish server and deploy project.
STEP 5: Run the project.

11
PROGRAM:

JSP CODING ([Link])


<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%

int java=[Link]([Link]("java"));

int dm=[Link]([Link]("dm"));

int aos=[Link]([Link]("aos"));

int iot=[Link]([Link]("iot"));

int hr=[Link]([Link]("hr"));

float avg;

int c=java+dm+aos+iot+hr;

[Link]("Your total is "+c);


avg=c/5;
if(avg > 90 )
{
[Link]( "your grade is A \n");
}
else if (avg>= 80)

12
{

[Link]("your grade is B \n");


}
else if (avg>= 70)
{
[Link]("your grade is C \n");
}
else if (avg>= 60)
{
[Link]("your grade is D \n");
}
else
{
[Link]("your grade is E\n");
}
%>
</body>
</html>

13
HTML CODING ([Link])
<html>
<head>
<title>student data</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<left> <h1>Student CIA - I marks Feb-2024 </h1>
<form action="[Link]" method="get">
<b>Enter Advanced Java Programming Marks : <input type="text" name="java"> </b> <br>
<b>Enter Data Mining Marks : <input type="text" name="dm"></b><br>
<b>Enter Advanced Operating Systems Marks : <input type="text" name="aos"> </b><br>
<b>Enter Internet of Thinks Marks :<input type="text" name="iot"> </b> <br>
<b>Enter Human Rights Marks :<input type="text" name="hr"></b><br>
<b><input type="submit"></b>
</form>
</left>
</body>
</html>

14
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

15
[Link]: 04
PURCHASE ORDER USING JSP

DATE:

AIM:
To design Purchase Order form using HTML form and jsp.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a HTML file as Named [Link] for Get Customer
Name, Product Name, Product Rate, Product Quantity.
STEP 3: Then Create a JSP file as named [Link] for display data.
STEP 4: Start NetBeans GlashFish server and deploy project.
STEP 5: Run the project.

16
PROGRAM:
JSP CODING ([Link])
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
String pid = [Link]("pid");
String cname = [Link]("cname");
String cadd = [Link]("cadd");
String cl = [Link]("cl");
String JeanType = [Link]("JeanType");
String od= [Link]("od");
int amt = [Link]([Link]("amt"));
%>
<%-- Print out the variables. --%>
<h1>Hello, <%=pid%><%=cname%><%=cadd%>!</h1> I ordered following items
<%=JeanType%>. From <%=cl%>. I expect your response as soon as possible
</body>
</html>

17
HTML CODING ([Link])
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Please Fill your Purchase Order!!!!!</h1>
<form action="[Link]" method="get">
Purchase order no: <input type="text" name="pid"> <br> <br>
Company Name: <input type="text" name="cname"> <br> <br>
Company Address: <input type="text" name="cadd"> <br> <br>
<br>Company Location: <input type="radio" checked name="cl" value="Chennai"> Chennai
<input type="radio" name="cl" value="Madurai">Madurai
<input type="radio" name="cl" value="Bangalore">Bangalore
<p>Items to be ordered:
<select name="JeanType">
<option value="Lenin">Lenin</option>
<option value="Otto">Otto</option>
<option value="V-Star">V-Star</option>
<option value="Peter">Peter</option>
<option value="Pantaloon">Pantaloon</option></select>
<br> <br>
Ordered Date: <input type="date" name="od"> <br> <br>
Amount: <input type="number" name="amt"> <br> <br>
<input type="submit">
</form>
</body>
</html>

18
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

19
[Link]: 05
EMPLOYEE PAY SLIP USING JSP

DATE:

AIM:
To prepare an Employee pay slip using JSP.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a HTML file as Named [Link] for Get the
following data from
The user (Emp name, department, Designation, Basic salary,
TA, DA, HRA, PF, LIC).
STEP 3: Then Create a JSP file as named [Link].
STEP 4: Write a code for Calculate the Gross salary and Net salary.
STEP 5: Then write a jsp code for displaying Employee data.
STEP 6: Start NetBeans GlashFish server and deploy project.
STEP 7: Run the project.

20
PROGRAM:
JSP CODING ([Link])

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head><%@ page import="[Link].*" %></head>
<body bgcolor="blue">
<%
String ename=[Link]("ename");
String dept=[Link]("dept");
String des=[Link]("des");
double bsal=[Link]([Link]("bsal"));
double ta=[Link]([Link]("ta"));
double ta2=bsal*ta/100;
double da=[Link]([Link]("da"));
double da2=bsal*da/100;
double hra=[Link]([Link]("hra"));
double hra2=bsal*hra/100;
double pf=[Link]([Link]("pf"));
double pf2=bsal*pf/100;
double lic=[Link]([Link]("lic"));
double lic2=bsal*lic/100;
double allowance;
double deduction;
double gsal;
double netsal;
allowance = (bsal*ta)/100 + (bsal*da)/100 + (bsal*hra)/100;
deduction = (bsal*pf)/100 + (bsal*lic)/100;

21
gsal = bsal + allowance;
netsal = gsal - deduction;
%>
<CENTER>
<table border=5 bgcolor="biege" height=600 width=400 >
<caption><h2><fontcolor="blue">Priya & Co Ltd.,<br>
SALARY STATEMENT</font></h2></caption>
<tr><td>Employee Name</td><td colspan=2><%=ename%></td></tr>
<tr><td>Department</td><td colspan=2><%=dept%></td></tr>
<tr><td>Designation</td><td colspan=2><%=des%></td></tr>
<tr><td>Basic Salary</td><td colspan=2><%=bsal%></td></tr>
<tr><th>Allowances</th><th>Percentage</th><th>Amount</th></tr>
<tr align=center><td>TA</td><td><%=ta%></td><td><%=ta2%></td></tr>
<tr align=center><td>DA</td><td><%=da%></td><td><%=da2%></td></tr>
<tr align=center><td>HRA</td><td><%=hra%></td><td><%=hra2%></td></tr>
<tr><th>Total Allowance:</th><td colspan=2><%=allowance%></td><tr>
<tr><th>Deductions</th><th>Percentage</th><th>Amount</th></tr>
<tr align=center><td>PF</td><td><%=pf%></td><td><%=pf2%></td></tr>
<tr align=center><td>LIC</td><td><%=lic%></td><td><%=lic2%></td></tr>
<tr><th>Total Deduction:</th><td colspan=2><%=deduction%></td></tr>
<tr><td>Gross Salary</td><td colspan=2><%=gsal%></td></tr>
<tr><td>Net Salary</td><td colspan=2><%=netsal%></td></tr>
</table>
</CENTER>
</body>
</html>

22
HTML CODING ([Link])

<html>
<head>
<title>Employee Salary Statement</title></head>
<body>
<h3>Enter Employee Details:</h3>
<form action="[Link]" method="POST" >
<table>
<tr><td>Employee Name:</td><td><input type="text" name="ename" autofocus></td></tr>
<tr><td>Employee Number:</td><td><input type=”text” number=”eno”></td></tr>
<tr><td>Department:</td><td><input type="text" name="dept"></td></tr>
<tr><td>Designation:</td><td><input type="text" name="des"></td></tr>
<tr><td>Basic Salary:</td><td><input type="text" name="bsal"></td></tr>
<tr><td>TA(%):</td><td><input type="text" name="ta"></td></tr>
<tr><td>DA(%):</td><td><input type="text" name="da"></td></tr>
<tr><td>HRA(%):</td><td><input type="text" name="hra"></td></tr>
<tr><td>PF(%):</td><td><input type="text" name="pf"></td></tr>
<tr><td>LIC(%):</td><td><input type="text" name="lic"></td></tr>
<tr><td><input type="submit" value="Evaluate"></td>
<td><input type="reset" value="Reset"></td></tr>
</table>
</form>
</body>
</html>

23
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

24
[Link]: 06
JDBC WITH ORACLE

DATE:

AIM:
To write a program using JDBC for creating a table, Inserting records and
list out the records.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a Servlet file and write a code.
STEP 3: Create a tables in Database.
STEP 4: Then write a code for make ODBC Connection between
Servlet and Database.
STEP 5: Start NetBeans GlashFish server and deploy project.
STEP 6: Run the project.

25
PROGRAM:
JAVA CODING ([Link])
package pro4;
import [Link];
import [Link];
import [Link];
import [Link];
public class Pro4 {
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/test","root","123456");
PreparedStatement stmt=[Link]("create table viaas(id int,cname
varchar(23))");
[Link]();
[Link]("success");
[Link]();
add();

}
public static void add()
{
try
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/test","root","123456");
PreparedStatement stmt=[Link]("insert into viaas values(1,'priya')");
[Link]();

26
[Link]("success");
[Link]();
}
catch(Exception e)
{

}
}
}

27
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

28
[Link]: 07
HANDLING FORM DATA USING SERVLET

DATE:

AIM:
To write a program using Java servlet to handle form data.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a HTML file as Named [Link].
STEP 3: Then create a simple Form for Getting student profile
information (name, class, blood group).
STEP 4: Create a Servlet file as Named [Link].
STEP 5: Write a code for displaying the data.
STEP 6: Start NetBeans GlashFish server and deploy project.
STEP 7: Run the project.

29
PROGRAM:
SERVLET CODING ([Link])

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet(urlPatterns = {"/data"})
public class data extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try (PrintWriter out = [Link]()) {
/* TODO output your page here. You may use following sample code. */
String un=[Link]("uname");
String pa=[Link]("pass");
String em=[Link]("email");
String ge=[Link]("gender");
String[] co=[Link]("course");
[Link]("text/html");
PrintWriter pw=[Link]();
[Link]("<h2>Data received successfully</h2><br>");
[Link]("<h3>User name: "+un+"</h3>");
[Link]("<h3>Password: "+pa+"</h3>");
[Link]("<h3>email: "+em+"</h3>");

30
[Link]("<h3>Gender: "+ge+"</h3>");
[Link]("<h3>Course: ");
for(String c:co)
{
[Link](c+" ");
}
[Link]("</h3>");
}
}

31
HTML CODING ([Link])
<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>Welcome to servlet Form handling<br><br>

<form action="NewServlet">

User Name: <input type="text" name="uname"><br>

Password: <input type="password" name="pass"><br>

Email : <input type="text" name="email"><br>

Gender : <input type="radio" name="gender" value="male" checked>

Male <input type="radio" name="gender" value="female">

Female <input type="radio" name="gender" value="other">Other<br>

Course: <input type="checkbox" name="course" value="Java">

Java <input type="checkbox" name="course" value="Dot Net">

Dot Net <input type="checkbox" name="course" value="PHP">

PHP <br><input type="submit" value="Submit">

<input type="reset">

</form>

</body>

</html>

32
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

33
[Link]: 08
TABLE HEADER

DATE:

AIM:

To write a simple Servlet program to create a table of all the headers it


receives along withtheir associated values.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a Servlet file as named NewServlet for getting local
host details .
STEP 3: Configuring Servelt using Servlet Mapping.
STEP 4: Start NetBeans GlashFish server and deploy project.
STEP 5: Run the project.

34
PROGRAM:

SERVLET CODING ([Link])

import [Link].*;

[Link].*;

[Link].*;

[Link].*;

public class NewServlet extends HttpServlet


{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
IOException,ServletException
{
[Link]("text/html");

PrintWriter out = [Link]();

[Link]("HTTP headers sent by your client:");

[Link]("<table border=1 width=50% height=50%>");

Enumeration enume = [Link]();

while ([Link]())

String headerName = (String) [Link]();

String headerValue = [Link](headerName);

[Link]("<tr><td>" + headerName + "</td><td>");

[Link]("<TD>" + [Link](headerName) +"</td>" );

}
[Link]("</TABLE>\n</BODY></HTML>");
}
}
35
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

36
[Link]: 09
SESSION OBJECT USING JSP

DATE:

AIM:
To write a program in JSP by using session object.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java Web-> Web application.
STEP 2: Create a JSP file as named [Link].
STEP 3: write a code for getting session details (id, create time, last
access time, visit count).
STEP 4: Start NetBeans GlashFish server and deploy project.
STEP 5: Run the project.

37
PROGRAM:
CODING 1 ([Link])

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@ page isErrorPage="true" %>
<html>
<head>
<title>Session Management Example</title></head>
<body>
<form method="post" action="[Link]">
<font size=5>Enter your name<input type="text" name="name"></font><br><br>
<font size=5>Enter your password<input type="password"
name="password"></font><br><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

38
CODING 2 ([Link])
<html>
<head>
<title>JSP Page </title></head>
<body>
<%
String name = [Link]("name");
String password = [Link]("password");
if ([Link](name) &&[Link](password))
{
[Link]("username", name);
[Link]("[Link]");
}
else
{
[Link]("[Link]");
}
%>
</body>
</html>

CODING 3 ([Link])
<html>
<head>
<title>Welcome in the program of session</title></head>
<body>
<font size = 5>Hello <%= [Link]("username") %> you are an authorized
person</font>
</body>
</html>

39
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

40
[Link]: 10
CLIENT SERVER APPLICATION USING RMI

DATE:

AIM:
To write a program to build a simple client server application using RMI.

ALGORITHM

STEP 1: Create a new web project in NetBeans, File-> New project-


> Java -> Java Application.
STEP 2: Create a Java Class as file named [Link], [Link],
[Link] Create a Package and Class.
STEP 3: Configuring Servelt using Servlet Mapping.
STEP 4: Start NetBeans GlashFish server and deploy project.
STEP 5: Run the project.

41
PROGRAM:
[Link]

import [Link].*;
public interface Adder extends Remote
{
public int add(int x,int y)throws RemoteException;
}
[Link]

import [Link].*;
import [Link].*;
public class AdderRemote extends UnicastRemoteObject implements Adder
{
AdderRemote() throws RemoteException
{
super();
}

public int add(int x, int y)


{
return x+y;
}
}

[Link]

import [Link].*;
import [Link].*;
public class MyServer
{
public static void main(String args[])
{
try
{
Adder stub=new AdderRemote();
[Link]("rmi://localhost:5000/sonoo",stub);
}
catch(Exception e)
{
42
[Link](e);
}
}
}

[Link]

import [Link].*;
public class MyClient
{
public static void main(String args[])
{
try
{
Adder stub=(Adder)[Link]("rmi://localhost:5000/sonoo");
[Link]([Link](34,4));
}
catch(Exception e)
{
}
}
}

43
OUTPUT:
Step1:

Step2:

44
Step 3:

RESULT:
Thus the above program has been run successfully and hence it is verified.
45
[Link]: 11
CALCULATOR USING APPLET

DATE:

AIM:
To create an applet for a calculator application.

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java -> Java Application.
STEP 2: Create a java file as Named [Link].
STEP 3: Then import an applet package.
STEP 4: Then create a class and write a code for perform calculator
basic operations (add, sub, mul, div).
STEP 5: Start NetBeans GlashFish server and deploy project.
STEP 6: Run the project.

46
PROGRAM:
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="CalculatorApplet" width=300 height=300>
</applet>
*/
public class CalculatorApplet extends Applet implements ActionListener{
String msg=" ";
int v1,v2,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init(){
Color k=new Color(120,89,90);
setBackground(k);
t1=new TextField(100);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{
b[i]=new Button(""+i);
}
add=new Button("+");
sub=new Button("-");
mul=new Button("*");
div=new Button("/");

47
mod=new Button("%");
clear=new Button("clear");
EQ=new Button("=");
[Link](this);
add(t1);
for(int i=0;i<10;i++)
{
add(b[i]);
}
add(add);
add(sub);
add(mul);
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent ae)
{
String str=[Link]();

48
char ch=[Link](0);
if ([Link](ch))
[Link]([Link]()+str);
else if([Link]("+"))
{
v1=[Link]([Link]());
OP='+';
[Link]("");
}
else if([Link]("-"))
{
v1=[Link]([Link]());
OP='-';
[Link]("");
}
else if([Link]("*"))
{
v1=[Link]([Link]());
OP='*';
[Link]("");
}
else if([Link]("/"))
{
v1=[Link]([Link]());
OP='/';
[Link]("");
}
else if([Link]("%"))
{
v1=[Link]([Link]());
OP='%';

49
[Link]("");
}
if([Link]("="))
{
v2=[Link]([Link]());
if(OP=='+')
result=v1+v2;
else if(OP=='-')
result=v1-v2;
else if(OP=='*')
result=v1*v2;
else if(OP=='/')
result=v1/v2;
else if(OP=='%')
result=v1%v2;
[Link](""+result);
}
if([Link]("clear"))
{
[Link]("");
}
}
}

50
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

51
[Link]: 12
CLIENT AND SERVER (SOCKET)

DATE:

AIM:
To write a program to send a text message to another system and receive
the text message from the system (use socket programming).

ALGORITHM:

STEP 1: Create a new web project in NetBeans, File-> New project->


Java -> Java Application.
STEP 2: Create a two JAVA file as Named [Link] and [Link].
STEP 3: Then Create a package and class.
STEP 4: Set a port number in socket method.
STEP 5: Write a code for sending message using input stream reader
package.
STEP 6: Then Receive message in Client side machine.
STEP 7: Start NetBeans GlashFish server and deploy project.
STEP 8: Run the project.

52
PROGRAM:
([Link])
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class server
{
public static void main(String[] args)
{
try
{
ServerSocket serverSocket = new ServerSocket(12345);
[Link]("Server started. Waiting for connection...");
Socket clientSocket = [Link]();
[Link]("Client connected.");
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]()));
PrintWriter out = new PrintWriter([Link](), true);
String message = [Link]();
[Link]("Client says: " + message);
[Link]("Message received by the server.");
[Link]();
[Link]();
[Link]();
[Link]();
}
catch (IOException ex)
{
53
[Link]();
}
}
}
([Link])
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class client
{
public static void main(String[] args)
{
try
{
Socket socket = new Socket("localhost", 12345);
BufferedReader in = new BufferedReader(new
InputStreamReader([Link]()));
PrintWriter out = new PrintWriter([Link](), true);
[Link]("Hello from the client!");
String response = [Link]();
[Link]("Server response: " + response);
[Link]();
[Link]();
[Link]();
}
catch (IOException ex)
{
[Link]();
}
} }
54
OUTPUT:

RESULT:
Thus the above program has been run successfully and hence it is verified.

55

You might also like