Java lab-I M.Sc CS (1)
Java lab-I M.Sc CS (1)
ARTS COLLEGE
TIRUPUR-641602
Reg. No :
Name :
SEMESTER –ll
PG & RESEARCH
DEPARTMENT OF COMPUTER SCIENCE
CHIKKANNA GOVERNMENT ARTS COLLEGE
TIRUPUR -641602
Name :
Reg. No :
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 .
1 WELCOME SERVLET
5 EMPLOYEE PAYROLL
PREPARATION 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>
<meta charset="UTF-8">
</head>
<body>
<center>
<div>Servlet Programs</div>
<form action="HelloServlet">
<table border="1">
<tbody>
<tr>
<td>Name:</td>
</tr>
</tbody>
</table>
</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;
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.setContentType("text/html;charset=UTF-8");
String name=request.getParameter("name");
catch(Exception e)
OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<center>
<div><h4>Fruits land<h4></div>
<form action="display">
<table border="1">
<tbody>
<tr>
<td>name:</td>
</tr>
<tr>
<td>Fruit Name:</td>
</tr>
<tr>
<td>Fruit Rate:</td>
</tr>
<tr>
<td>Quantity:</td>
<option>Kg</option>
<option>Nos</option>
</select></td>
</tr>
</tbody>
</table>
<input type="submit" value="Submit" name="submit" />
</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;
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("<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>
</head>
<center>
<body>
<table border="1">
<tbody>
<tr>
<td>Register No:</td>
</tr>
<tr>
<td>Name:</td>
</tr>
<tr>
<td>Subject1:</td>
</tr>
<tr>
<td>Subject2:</td>
</tr>
<tr>
<td>Subject3:</td>
</tr>
</tbody>
</table>
<input type="submit" value="Submit" name="SUBMIT" />
</form>
</body>
</center>
</html>
DISPLAY.JSP
<html>
<head>
</head>
<body>
<center>
<%
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("<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>=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>
<meta charset="UTF-8">
</head>
<body>
<center>
<table border="1">
<tbody>
<tr>
<td>Name:</td>
</tr>
<tr>
<td>Product Id:</td>
</tr>
<tr>
<td>Product name:</td>
<td><select name="pname">
<option>Veg Pizza</option>
<option>chicken pizza</option>
</select></td>
</tr>
<tr>
<td>Quantity:</td>
</tr>
<tr>
<td>Drink ID:</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>
</tr>
<tr>
</tr>
</tbody>
</table>
</form>
</center>
</body>
</html>
DISPLAY.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<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;
pprice=75*pquan;
pprice=60*pquan;
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>
<meta charset="UTF-8">
</head>
<body>
<center>
<table border="1">
<tbody>
<tr>
<td>EMPLOYEE ID:</td>
</tr>
<tr>
<td>EMPLOYEE NAME:</td>
</tr>
<tr>
<td>WORKING HOURS:</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</center>
</body>
</html>
DISPLAY.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<%
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("<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;
ABC.JAVA
package database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
class abc
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>
<meta charset="UTF-8">
</head>
<body>
<center>
<div>LoginForm</div>
<formaction="display">
<table border="1">
<tbody>
<tr>
<td>UserName:</td>
</tr>
<tr>
<td>Password:</td>
</tr>
</tbody>
</table>
</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;
response.setContentType("text/html");
try
String name=request.getParameter("un");
String pass=request.getParameter("pw");
if(pass.equals("santhoshk"))
else
catch(Exception e)
}
OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
INDEX.HTML
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<center>
<table border="1">
<tbody>
<tr>
<td>Employee ID:</td>
</tr>
<tr>
<td>Employee Name:</td>
</tr>
</tbody>
</table>
</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;
@Override
response.setContentType("text/html");
String eid=request.getParameter("eid");
String ename=request.getParameter("ename");
if(eid.isEmpty()||ename.isEmpty())
else
try
Object newInstance;
newInstance = Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
try(Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/empdb", "santhosh",
"santhosh"))
try(PreparedStatement ps = con.prepareStatement(query))
ps.setInt(1, Integer.parseInt(eid));
ps.setString(2, ename);
ps.executeUpdate();
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>
</head>
<body>
</form>
</body>
</html>
SESSION.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1></h1>
<%
String uname=request.getParameter("inputname");
out.print("Welcome"+uname);
session.setAttribute("sessname",uname);
%>
</body></html>
OUTPUT.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1></h1>
<%
String name=(String)session.getAttribute("sessname");
</body>
</html>
OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.
ADDER.JAVA
import java.rmi.*;
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
// super();
return n1+n2;
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;
c.connectRemote();
}
private void connectRemote() throws RemoteException
try
adder ad = (adder)reg.lookup("hi_server");
int a = sc.nextInt();
int b = sc.nextInt();
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;
int count=labels.length();
for(int i=0;i<count;i++)
add("North",lab=new Label("0",Label.RIGHT));
p.setLayout(new GridLayout(4,4));
addButtons(p,"789/");
addButtons(p,"456*");
addButtons(p,"123-");
addButtons(p,".0=+");
add ("Center",p);
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;
char c=operator.charAt(0);
switch(c){
break;
break;
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.*;
Socket s=ss.accept();
System.out.println("Client connected");
String str=bf.readLine();
System.out.println("Client:"+str);
pr.println("hello");
pr.flush();
CLIENT.JAVA
import java.net.*;
import java.io.*;
pr.println("hello");
pr.flush();
String str=bf.readLine();
System.out.println("Server:"+str);
OUTPUT
RESULT
Thus the above program is executed and the output is verified successfully.