0% found this document useful (0 votes)
4 views

Java lab-I M.Sc CS (1)

The document outlines the practical work record for M.Sc Computer Science students at Chikkanna Government Arts College, focusing on Advanced Java Programming Lab. It includes various servlet and JSP programs, such as a welcome servlet, purchase order form, employee payroll preparation, and student mark list generation. Each section details the HTML forms and corresponding Java code, along with successful execution results.

Uploaded by

varanyogesh789
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Java lab-I M.Sc CS (1)

The document outlines the practical work record for M.Sc Computer Science students at Chikkanna Government Arts College, focusing on Advanced Java Programming Lab. It includes various servlet and JSP programs, such as a welcome servlet, purchase order form, employee payroll preparation, and student mark list generation. Each section details the HTML forms and corresponding Java code, along with successful execution results.

Uploaded by

varanyogesh789
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

CHIKKANNA GOVT.

ARTS COLLEGE
TIRUPUR-641602

(Affiliated to Bharathiyar University,Coimbatore)


ADVANCED JAVA PROGRAMMING LAB

Reg. No :
Name :

M.Sc – Computer Science

SEMESTER –ll

PG & RESEARCH
DEPARTMENT OF COMPUTER SCIENCE
CHIKKANNA GOVERNMENT ARTS COLLEGE
TIRUPUR -641602

(Affiliated to Bharathiyar University)

Name :

Reg. No :

Class : I - M.Sc [ComputerScience]

This is to certified that it is a bonafide record of the practical work done by the above
student of the M.Sc(COMPUTER SCIENCE) Degree Examinations Core Practical
ADVNCED JAVA PROGRAMMING LAB during the Academic year 20 -20 .

Staff In-charge Head of the Department

Submitted for the University Practical Examination held on................20 .


SL.NO DATE CONTENT PG.NO SIGNATURE

1 WELCOME SERVLET

2 PURCHASE ORDER FORM


USING SERVLET

3 MARK LIST PREPARATION


USING JSP

4 PURCHASE ORDER FORM


USING JSP

5 EMPLOYEE PAYROLL
PREPARATION USING JSP

6 CREATE TABLE USING


JDBC

7 FORM DATA HANDLING


USING SERVLET

8 CREATE TABLE USING


SERVLET

9 CREATE SESSION OBJECT


USING JSP

10 CLIENT SERVER
APPLICATION USING RMI

11 CREATE CALCULATOR
USING APPLET
CREATE MESSAGE
12 PASSING PROGRAM USING
SOCKET PROGRAMMING
INDEX.HTML
<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>

<center>

<div>Servlet Programs</div>

<form action="HelloServlet">

<table border="1">

<tbody>

<tr>

<td>Name:</td>

<td><input type="text" name="name" value="" size="50" /></td>

</tr>

</tbody>

</table>

<input type="submit" value="Enter" name="enter" />

</form>

</center>

</body>

</html>

HELLOSERVLET.JAVA
import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class welcome extends HttpServlet

{
protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();


try

String name=request.getParameter("name");

out.println("<h3>Welcome "+name+".You Have able to run servlet programs</h3>");

catch(Exception e)

OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<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>

<center>

<div><h4>Fruits land<h4></div>

<form action="display">

<table border="1">

<tbody>

<tr>

<td>name:</td>

<td><input type="text" name="cname" value="" size="50" /></td>

</tr>

<tr>

<td>Fruit Name:</td>

<td><input type="text" name="fname" value="" size="50" /></td>

</tr>

<tr>

<td>Fruit Rate:</td>

<td><input type="text" name="frate" value="" size="50" /></td>

</tr>

<tr>

<td>Quantity:</td>

<td><input type="text" name="quantity" value="" size="30" /><select name="type"width="20">

<option>Kg</option>

<option>Nos</option>

</select></td>

</tr>

</tbody>

</table>
<input type="submit" value="Submit" name="submit" />

<input type="reset" value="Clear" name="clear" />

</form>

</center>

</body>

</html>

DISPLAY.JAVA
package com;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class display extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

response.setContentType("text/html");
PrintWriter out = response.getWriter();

try

String name=request.getParameter("cname");

String fname=request.getParameter("fname");
String frate=request.getParameter("frate");

String quantity=request.getParameter("quantity");

int frate1=Integer.parseInt(frate);

int quantity1=Integer.parseInt(quantity);

int trate=frate1*quantity1;

out.println("<center><table border=1");

out.println("<h1>Fruits Land</h1>");

out.println("<h3>Your Ordered details</h3>");

out.println("<tr><td>Name:"+name+"</tr></td>");
out.println("<tr><td>Fruit Name:"+fname+"</tr></td>");

out.println("<tr><td>Fruit rate:"+frate+"</tr></td>");

out.println("<tr><td>Quantity:"+quantity+"<td>"+request.getParameter("type")+"</tr></td></td>");

out.println("<tr><td>Total Price:"+trate+"</tr></td>");
out.println("</center></table>");

catch(Exception e)

OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<html>

<head>

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

<title>Student Mark List</title>

</head>

<center>

<body>

<h1>Student Mark List</h1>

<form action="display.jsp" method="POST">

<table border="1">

<tbody>

<tr>

<td>Register No:</td>

<td><input type="text" name="register" value="" size="40" /></td>

</tr>

<tr>

<td>Name:</td>

<td><input type="text" name="name" value="" size="40" /></td>

</tr>

<tr>

<td>Subject1:</td>

<td><input type="text" name="s1" value="" size="40" /></td>

</tr>

<tr>

<td>Subject2:</td>

<td><input type="text" name="s2" value="" size="40" /></td>

</tr>

<tr>

<td>Subject3:</td>

<td><input type="text" name="s3" value="" size="40" /></td>

</tr>

</tbody>

</table>
<input type="submit" value="Submit" name="SUBMIT" />

<input type="reset" value="reset" name="RESET" />

</form>

</body>

</center>

</html>

DISPLAY.JSP
<html>

<head>

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

<title>Student Mark List</title>

</head>

<body>

<center>

<h1>Student Mark List</h1>

<%

String reg=(request.getParameter("register"));

Stringname=(request.getParameter("name"));

String s1=(request.getParameter("s1"));
String s2=(request.getParameter("s2"));

String s3=(request.getParameter("s3"));

if(!(s1==null||s1.isEmpty()))

int s1m=Integer.parseInt(s1);

int s2m=Integer.parseInt(s2);

int s3m=Integer.parseInt(s3);

if(s1m<40||s2m<40||s3m<40)

out.println("<table border=5 width=500 height=5><center>");

out.println("<tr><td>Register No:<td>"+reg+"</tr></td>");

out.println("<tr><td>Name:<td>"+name+"</tr></td>");

out.println("<tr><td>Total:<td>Not To Evoluate</tr></td>");

out.println("<tr><td>Percentage:<td>Not To Evoluate</tr></td>");
out.println("<tr><td>Grade:<td>Not To Evoluate</tr></td>");

else

int t=s1m+s2m+s3m;
int p=t/3;

String grade="";

if(p>=40&&p<=60){grade="Good";}

else if(p>=61&&p<=80){grade="Very Good";}

else if(p>=81&&p<=100){grade="Excellent";}
out.println("<table border=5 width=500 height=5><center>");

out.println("<tr><td>Register No:<td>"+reg+"</tr></td>");

out.println("<tr><td>Name:<td>"+name+"</tr></td>");

out.println("<tr><td>Total:<td>"+t+"</tr></td>");

out.println("<tr><td>Percentage:<td>"+p+"</tr></td>");

out.println("<tr><td>Grade:<td>"+grade+"</tr></td>");

%>

</center>

</body>

</html>
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<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>

<center>

<div>PURCHASE ORDER FORM</div>

<form action="display.jsp" method="POST">

<table border="1">

<tbody>

<tr>

<td>Name:</td>

<td><input type="text" name="name" value="" size="50" /></td>

</tr>

<tr>

<td>Product Id:</td>

<td><input type="text" name="pid" value="" size="50" /></td>

</tr>

<tr>

<td>Product name:</td>

<td><select name="pname">

<option>Veg Pizza</option>

<option>Cheese and chicken pizza</option>

<option>chicken pizza</option>

<option>Egg roll Chicken pizza</option>

</select></td>

</tr>

<tr>

<td>Quantity:</td>

<td><input type="text" name="quantity" value="" size="50" /></td>

</tr>
<tr>

<td>Drink ID:</td>

<td><input type="text" name="did" value="" size="50" /></td>

</tr>

<tr>

<td>Drink Name:</td>

<td><select name="dname">

<option>Cocacola</option>

<option>pepsi</option>

<option>Mirenda</option>

<option>Thumpsup</option>

</select></td>

</tr>

<tr>

<td>Quantity:</td>

<td><input type="text" name="dquan" value="" size="50" /></td>

</tr>

<tr>

<td><input type="submit" value="Submit" name="submit" /></td>

<td><input type="reset" value="Clear" name="clear" /></td>

</tr>

</tbody>

</table>

</form>

</center>

</body>

</html>
DISPLAY.JSP
<%@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>

<center>

<h1>Domino's pizza</h1>

<%

Stringname=request.getParameter("name");

Stringpid=request.getParameter("pid");

String pname=request.getParameter("pname");

Stringquantity=request.getParameter("quantity");

Stringdid=request.getParameter("did");

Stringdname=request.getParameter("dname");

String dquan=request.getParameter("dquan");

if(!(quantity==null||quantity.isEmpty()))

int pquan=Integer.parseInt(quantity);

int dquan1=Integer.parseInt(dquan);

int pprice=50*pquan;

int dprice=60*dquan1;

if(pname.equals("Veg Pizza"))

pprice=50*pquan;

else if(pname.equals("Cheese and chicken pizza"))

pprice=75*pquan;

else if(pname.equals("chicken pizza"))


{

pprice=60*pquan;

else if(pname.equals("Egg roll Chicken pizza"))

pprice=100*pquan;

if(dname.equals("Cocacola"))

dprice=20*dquan1;

else if(dname.equals("pepsi"))

dprice=60*dquan1;

else if(dname.equals("Mirenda"))

dprice=10*dquan1;

else if(dname.equals("Thumpsup"))

dprice=30*dquan1;

int tprice=pprice+dprice;

out.println("<center><table border=1>");
out.println("<tr><td>Name:<td>"+name+"</tr></td>");

out.println("<tr><td>Product Name:<td>"+pname+"</tr></td>");

out.println("<tr><td>Product Price:<td>"+pprice+"</tr></td>");

out.println("<tr><td>Drink Name:<td>"+dname+"</tr></td>");
out.println("<tr><td>Drink Price:<td>"+dprice+"</tr></td>");

out.println("<tr><td>Total Price:<td>"+tprice+"</tr></td>");

%>

</center></body></html>
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<html>

<head>

<title>EMPLOYEE PAYROLL PREPARATION</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<center>

<div>EMPLOYEE PAYROLL PREPARATION</div>

<form action="display.jsp" method="POST">

<table border="1">

<tbody>

<tr>

<td>EMPLOYEE ID:</td>

<td><input type="text" name="EID" value="" size="50" /></td>

</tr>

<tr>

<td>EMPLOYEE NAME:</td>

<td><input type="text" name="ENAME" value="" size="50" /></td>

</tr>

<tr>

<td>WORKING HOURS:</td>

<td><input type="text" name="EHRS" value="" size="50" /></td>

</tr>

<tr>

<td>RATE PER HOUR:</td>

<td><input type="text" name="RPH" value="" size="50" /></td>

</tr>

</tbody>

</table>

<input type="submit" value="SUBMIT" name="SUBMIT" />

<input type="reset" value="CLEAR" name="CLEAR" />


</form>

</center>

</body>

</html>

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

<!DOCTYPE html>

<html>

<head>

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

<title>EMPLOYEE PAYROLL PREPARATION</title>

</head>

<body>

<h1>EMPLOYEE PAYROLL PREPARATION</h1>

<%

String id=(request.getParameter("EID"));

String name=(request.getParameter("ENAME"));

String whrs=(request.getParameter("EHRS"));

String rate=(request.getParameter("RPH"));
if(!(whrs==null||whrs.isEmpty()))

int whrs1=Integer.parseInt(whrs);

int rate1=Integer.parseInt(rate);

int bp=whrs1*rate1;

int da=bp*5/100;

int ta=bp*2/100;

int hra=bp*3/100;

int pf=bp*2/100;

int lic=bp*5/100;

int tax=bp*3/100;

int gp=bp+da+ta+hra;
int np=gp-pf-lic-tax;

out.println("<table border=5 width=500 height=5><center>");


out.println("<tr><td>Employee ID:<td>"+id+"</tr></td>");

out.println("<tr><td>Employee Name:<td>"+name+"</tr></td>");

out.println("<tr><td>Basic Salary:<td>"+bp+"</tr></td>");

out.println("<tr><td>DA:<td>"+da+"</tr></td>");

out.println("<tr><td>TA:<td>"+ta+"</tr></td>");

out.println("<tr><td>HRA:<td>"+hra+"</tr></td>");

out.println("<tr><td>PF:<td>"+pf+"</tr></td>");

out.println("<tr><td>LIC:<td>"+lic+"</tr></td>");

out.println("<tr><td>TAX:<td>"+tax+"</tr></td>");

out.println("<tr><td>Gross Salary:<td>"+gp+"</tr></td>");

out.println("<tr><td>Net Salary:<td>"+np+"</tr></td>");
}

%>

</body>

</html>

OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
DATABASE.JAVA
package database;

import java.sql.SQLException;

public class Database

public static void main(String[] args) throws SQLException

abc dr=new abc();

ABC.JAVA
package database;

import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.PreparedStatement;

import java.sql.SQLException;

class abc

public abc() throws SQLException

Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/student", "santhosh",


"santhosh");

PreparedStatement st= con.prepareStatement("insert into STUD values(?,?,?)");

st.setInt(1, 11);

st.setString(2, "ram");

st.setDouble(3, 96299);

int a=st.executeUpdate();

if(a>0)

{
System.out.println("Row updated successfully");

}
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<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>

<center>

<div>LoginForm</div>

<formaction="display">

<table border="1">

<tbody>

<tr>

<td>UserName:</td>

<td><input type="text" name="un" value="" size="50" /></td>

</tr>

<tr>

<td>Password:</td>

<td><input type="password" name="pw" value="" size="50" /></td>

</tr>

</tbody>

</table>

<input type="submit" value="Login" name="Login" />

<input type="reset" value="Clear" name="clear" />

</form>

</center>

</body>

</html>
DISPLAY.JAVA
package com;

import java.io.IOException;

import java.io.PrintWriter;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class display extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException

response.setContentType("text/html");

PrintWriter out = response.getWriter();

try

String name=request.getParameter("un");

String pass=request.getParameter("pw");

if(pass.equals("santhoshk"))

out.println("<center>Welcome "+name+". You are valid user</center>");

else

out.println("<center>Welcome "+name+". You are invalid user</center>");

catch(Exception e)

}
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<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>

<center>

<div>Employee Entry files</div>

<form action="display" method="POST">

<table border="1">

<tbody>

<tr>

<td>Employee ID:</td>

<td><input type="text" name="eid" value="" size="50" /></td>

</tr>

<tr>

<td>Employee Name:</td>

<td><input type="text" name="ename" value="" size="50" /></td>

</tr>

</tbody>

</table>

<input type="submit" value="Submit" name="Submit" />

<input type="reset" value="Clear" name="Clear" />

</form>

</center>

</body>

</html>
DISPLAY.JAVA
import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

importjava.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.util.logging.Level;

importjava.util.logging.Logger;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class display extends HttpServlet {

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException


{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String eid=request.getParameter("eid");

String ename=request.getParameter("ename");

if(eid.isEmpty()||ename.isEmpty())

out.println("Please Enter all requirement fields");

else

out.println("Record inserted successfully");

try

Object newInstance;

newInstance = Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
try(Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/empdb", "santhosh",
"santhosh"))

String query="insert into EMDB(ID,NAME) values(?,?)";

try(PreparedStatement ps = con.prepareStatement(query))

ps.setInt(1, Integer.parseInt(eid));

ps.setString(2, ename);

ps.executeUpdate();

} catch (SQLException ex) {

} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {


Logger.getLogger(display.class.getName()).log(Level.SEVERE, null, ex);

OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

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

<title>Enter your name</title>

</head>

<body>

<h1>Enter Your name</h1>

<form action="session.jsp" method="POST">

<input type="text" name="inputname" value="" size="40" />

<input type="submit" value="Submit" />

</form>

</body>

</html>

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

<!DOCTYPE html>

<html>

<head>

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

<title>Passing the input value to a session variable</title>

</head>

<body>

<h1></h1>

<%

String uname=request.getParameter("inputname");

out.print("Welcome"+uname);

session.setAttribute("sessname",uname);

%>

<a href="output.jsp">Check output here!</a>

</body></html>
OUTPUT.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

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

<title>output page:Fetching the value from session</title>

</head>

<body>

<h1></h1>

<%

String name=(String)session.getAttribute("sessname");

out.print("Hello user:You have Entered the name:"+name);


%>

</body>

</html>

OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
ADDER.JAVA
import java.rmi.*;

public interface adder extends Remote

public int add(int n1,int n2)throws RemoteException;

SERVER.JAVA
import java.rmi.RemoteException;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;

import java.rmi.server.UnicastRemoteObject;
public class server extends UnicastRemoteObject implements adder

public server()throws RemoteException

// super();

public int add(int n1, int n2) throws RemoteException

return n1+n2;

public static void main(String[] args) throws RemoteException

try

Registry reg=LocateRegistry.createRegistry(4444);

reg.rebind("hi_server",new server());

System.out.println("Server is Ready...");

catch(RemoteException e)

System.out.println("Exception:"+e);
}

CLIENT.JAVA
import java.rmi.NotBoundException;

import java.rmi.RemoteException;

importjava.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;
importjava.util.Scanner;

public class client

public static void main(String args[]) throws RemoteException

client c = new client();

c.connectRemote();

}
private void connectRemote() throws RemoteException

try

Scanner sc= new Scanner(System.in);

Registry reg = LocateRegistry.getRegistry("LocalHost",4444);

adder ad = (adder)reg.lookup("hi_server");

System.out.println("Enter two values");

int a = sc.nextInt();

int b = sc.nextInt();

System.out.println("Addition is:"+ad.add(a, b));

catch(NotBoundException|RemoteException e)

System.out.println("Exception "+e);

}}
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
CALC.JAVA
package calc;

import java.awt.*;

importjava.applet.*;
public class Calc extends Applet {

Label lab;

boolean firstDigit=true;

float savedValue=0.0f;

String operator= "=";

public void addButtons (Panel p,String labels){

int count=labels.length();

for(int i=0;i<count;i++)

p.add (new Button(labels.substring(i,i+1)));

public void init(){

setLayout (new BorderLayout());

add("North",lab=new Label("0",Label.RIGHT));

Panel p=new Panel();

p.setLayout(new GridLayout(4,4));

addButtons(p,"789/");

addButtons(p,"456*");

addButtons(p,"123-");

addButtons(p,".0=+");

add ("Center",p);

public boolean action(Event e,Object o){

if(e.target instanceof Button){

String s=(String)o;
if("0123456789.".indexOf(s) !=-1){

if(firstDigit){

firstDigit=false;

lab.setText (s);

else{
lab.setText(lab.getText()+s);

}else{

if(!firstDigit){
compute(lab.getText());

firstDigit=true;

operator=s;

return true;

return false;

public void compute(String s){

float sValue=new Float (s).floatValue();

char c=operator.charAt(0);

switch(c){

case '=': savedValue =sValue;

break;

case '+': savedValue+=sValue;

break;

case '-': savedValue-=sValue;


break;

case '*': savedValue*=sValue;

break;
case '/': savedValue/=sValue;

break;

lab.setText(String.valueOf(savedValue));

}
OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.
SERVER.JAVA
import java.net.*;

import java.io.*;

public class server

public static void main(String args[])throws IOException

ServerSocket ss=new ServerSocket(4999);

Socket s=ss.accept();
System.out.println("Client connected");

InputStreamReader in=new InputStreamReader(s.getInputStream());

BufferedReader bf=new BufferedReader(in);

String str=bf.readLine();

System.out.println("Client:"+str);

PrintWriter pr= new PrintWriter(s.getOutputStream());

pr.println("hello");

pr.flush();

CLIENT.JAVA
import java.net.*;

import java.io.*;

public class client

public static void main(String args[])throws IOException

Socket s=new Socket("localhost",4999);

PrintWriter pr= new PrintWriter(s.getOutputStream());

pr.println("hello");

pr.flush();

InputStreamReader in=new InputStreamReader(s.getInputStream());

BufferedReader bf=new BufferedReader(in);

String str=bf.readLine();
System.out.println("Server:"+str);

OUTPUT

RESULT
Thus the above program is executed and the output is verified successfully.

You might also like