Escolar Documentos
Profissional Documentos
Cultura Documentos
1
Implementation of TCP Using Sockets
Date :
Aim :
Write a Java program to Implementation of TCP Sockets
Program:
tcpclient.java
import java.io.*;
import java.net.*;
class tcpclient
{
public static void main(String s[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5000);
OutputStream os=soc.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
InputStream is=soc.getInputStream();
DataInputStream dis=new DataInputStream(is);
while(true)
{
System.out.println("Send : ");
4
dos.writeUTF(br.readLine());
System.out.println("Received: "+dis.readUTF(dis));
}
}
}
tcpserver.java
import java.io.*;
import java.net.*;
class tcpserver
{
public static void main(String s[]) throws Exception
{
ServerSocket sersoc=new ServerSocket(5000);
Socket soc=sersoc.accept();
InputStream is=soc.getInputStream();
DataInputStream dis=new DataInputStream(is);
OutputStream os=soc.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
while(true)
{
System.out.println("Received: "+dis.readUTF(dis));
System.out.println("Send : ");
dos.writeUTF(br.readLine());
}}}
5
Output :
tcp server:
tcp client:
Result :
Thus the given java program was executed and output was verified.
6
Ex. No. 2
Implementation of File Transfer
Date :
Aim :
Write a Java program to Implementation of file transfer
Program:
ftpclient.java
import java.io.*;
import java.net.*;
public class ftpc
{
public static int serport=1666;
public static int clientport=1999;
public static DatagramSocket dss;
public static byte buff[]=new byte[1024];
public static byte buff1[]= new byte[5000];
public static DatagramPacket dp,dp1;
7
int c=System.in.read();
switch(c)
{
case '1':
System.out.println("Client quits");
return;
case '\n':
String bye=new String(buff);
InetAddress addr=InetAddress.getByName("localhost");
System.out.println(addr);
while(true)
{
dss.send(new DatagramPacket(buff,pos,addr,serport));
dp1=new DatagramPacket(buff1,buff1.length);
dss.receive(dp1);
System.out.println("File Length is"+dp1.getLength());
if(dp1.getLength()>1)
{
for(int j=0;j<dp1.getLength();j++)
{
msg+=(char)buff1[j];
}
System.out.println(msg);
}
else
System.out.println("\nFile not found...");
pos=0;
8
break;
}
case '\r':
break;
default:
buff[pos++]=(byte)c;
}
}
}
public static void main(String args[]) throws Exception
{
dss=new DatagramSocket(clientport);
client();
}
}
ftpserver.java
import java.io.*;
import java.net.*;
public class ftpserver
{
public static int serport=1666;
public static int clientport=1999;
public static DatagramSocket dss;
public static byte buff[]=new byte[1024];
public static byte buff1[]=new byte[5000];
9
public static DatagramPacket dp,dp1;
public static void server() throws Exception
{
InetAddress addr=InetAddress.getByName("localhost");
System.out.println(addr);
while(true)
{
try
{
DatagramPacket dp=new DatagramPacket (buff,buff.length);
dss.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
if(str.equals("bye"))
{
System.out.println("Server quits");
System.exit(0);
}
System.out.println("Filename server received "+str);
InputStream fis= new FileInputStream(str);
int size=fis.available();
System.out.println(size);
for(int i=0;i<size;i++)
buff[i]=(byte)fis.read();
dss.send(new DatagramPacket(buff1,size,addr,clientport));
}
catch(FileNotFoundException fe)
{
10
System.err.println(fe);
dss.send(new DatagramPacket(buff1,0,addr,clientport));
}
}
}
public static void main(String args[])throws Exception
{
System.out.println("Server started");
dss=new DatagramSocket(serport);
server();
}
}
11
Output :
ftp client:
ftp server:
Result :
Thus the given java program was executed and output was verified.
12
Ex. No. 3
Implementation of Chat Application
Date :
Aim :
Write a Java program to Implementation of chat application
Program:
chat.java
import java.net.*;
import java.io.*;
public class chat
{
public static void main(String args[])throws Exception
{
DatagramSocket ioSocket;
String toName="localhost";
String userIn;
byte sendBuffer[]=new byte[65535];
DatagramPacket sendPacket=new DatagramPacket(sendBuffer,128);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int ioPort=111,receiverPort=ioPort;
if(args.length>0)toName=args[0];
else
toName="localhost";
if(toName.equals("localhost"))
13
receiverPort=222;
try
{
ioSocket=new DatagramSocket(ioPort);
}
catch(Exception e )
{
System.out.println("Exception:"+e);
ioPort=222;
receiverPort=111;
ioSocket=new DatagramSocket(ioPort);
}
System.out.println("chat on port"+ioPort+".Ctrl Z to quit");
new receiver(ioSocket);
while((userIn=in.readLine())!=null)
{
sendBuffer=userIn.getBytes();
sendPacket=new
DatagramPacket(sendBuffer,sendBuffer.length,InetAddress.getByName(toName),rec
eiverPort);
ioSocket.send(sendPacket);
}
System.exit(0);
}
}
14
{
DatagramSocket rsSocket;
receiver(DatagramSocket rsSocket)
{
this.rsSocket=rsSocket;
new Thread(this).start();
}
public void run()
{
System.out.println("Calling run");
byte receiveBuffer[]=new byte[65535];
DatagramPacket receivePacket=new DatagramPacket(receiveBuffer,128);
while(true)
{
try
{
rsSocket.receive(receivePacket);
}
catch(Exception e)
{
}
System.out.println("Received:"+new
String(receivePacket.getData(),0,receivePacket.getLength()));
}
}
}
15
Output :
Port 111:
Port 222:
Result :
Thus the given java program was executed and output was verified.
16
Ex. No. 4
Simulation of Routing Protocols
Date :
Aim :
Write a Java program to Implementation of Routing Protocols
Program:
routing.java
import java.io.*;
import java.lang.*;
class routing
{
public static void main(String args[])throws IOException
{
int n,i,j,k;
int[][] b=new int[100][100];
int[][] a=new int[100][100];
String n1;
String s1;
System.out.println("enter the number of nodes\n");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
n1=br.readLine();
n=Integer.parseInt(n1);
17
InputStreamReader isr1=new InputStreamReader(System.in);
BufferedReader br1=new BufferedReader(isr);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.println("\n Enter the distance between the host "+(i+1)+" "+(j+1)+":");
s1=br1.readLine();
a[i][j]=Integer.parseInt(s1);
}
System.out.println("\n\n");
}
for(i=0;i<n;i++)
{
System.out.println("\n");
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
}
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
18
{
for(j=0;j<n;j++)
{
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[i][j];
if(i==j)
b[i][j]=0;
}
}
19
}
}
}
Output :
20
Enter the distance between the host 2 3 : 12
2 4 6
8 10 12
14 16 18
0 4 6
8 0 12
14 16 0
Result :
21
Thus the given java program was executed and output was verified.
Ex. No. 5
Study of All SQL Commands
Date :
Aim :
Study of all SQL Commands
Codings:
CREATE TABLE:
SQL>
create table msec_student_inf
(
s_roll_no varchar2(15) primary key , student_name varchar2(100) not null,
course_id number(4) , batch_inf varchar2(10) , address_inf varchar2(100) ,
contact_inf varchar2(100) , remark varchar2(100));
Table created.
SQL>
create table msec_course_inf ( course_id number(4) primary key,
course_name varchar2(30) not null , course_duration varchar2(30),
univ_regulation varchar2(100) , remark varchar2(100));
22
Table created.
CREATE INDEX:
Index created.
DROP INDEX:
Index dropped.
CREATE VIEW:
View created
ALTER TABLE:
Table altered.
23
DESC COMMAND:
INSERT COMMAND:
1 row created.
24
COMMIT/SAVEPOINT/ROLLBACK TRANSACTION COMMAND:
SQL>COMMIT;
SQL>SAVEPOINT SP5;
SELECT CLAUSE:
25
----------- -------- ------------------------ ------------------------------
5 M.B.A. 2010-2012
ORDER BY CLAUSE:
26
SQL>SELECT * FROM emp WHERE job = 'SALESMAN' ORDER BY comm
DESC;
SQL> SELECT deptno, MIN(sal), MAX (sal) FROM emp WHERE job = 'CLERK'
GROUP BY deptno HAVING MIN(sal) < 1000;
JOIN CONDITION:
27
SQL>SELECT ename, job, dept.deptno, dname FROM emp, dept
WHERE emp.deptno (+) = dept.deptno;
15 rows selected.
UPDATE RECORD:
28
SQL>update msec_course_inf set univ_regulation='ANNA UNIVERSITY -
TIRUCHIRAPPALLI' where course_id=5
1 row updated.
DELETE CLAUSE:
1 rows deleted.
29
Result :
Thus the given SQL commands were studied and output was verified.
Ex. No. 6
Implementing The Concept of Normalization
Date :
Aim :
Implement the concept of Normalization (1NF,2NF and 3NF), From the given
data elements for customer Invoices.
Normalization:
30
Here if we analyze the spread sheet, rows 2,3 and 4 are representing the data for
invoice no=125, which has the data redundancy for customer information. By
implement the normalization, we can identify the required tables from the given set
of data elements by which we can implement coding.
Thus the above data elements can be represented as follows, using 1NF.
INVOICES
31
INVOICE_NO
(PK)
INVOICE_DATE
CUST_ID
CUST_NAME
CUST_ADDR
CUST_CITY
CUST_STATE
ITEM_ID (PK)
ITEM_DESC
ITEM_QTY
ITEM_PRICE
TOTAL_PRICE
PHASE-I:
Invoice Information And Invoice Item Information Can Be Seperated Into Tables
32
PHASE –II:
Invoice- Item Table Can Be Further Seperated As Item Information And Put Into
Separate Table
33
Codings:
TABLE CREATED.
34
SQL> CREATE TABLE INVOICE_ITEM
2 (
3 ITEM_ID NUMBER(6) PRIMARY KEY,
4 INVOICE_NO NUMBER(6),
5 ITEM_DESC VARCHAR2(50) UNIQUE,
6* ITEM_PRICE NUMBER(10,2));
TABLE CREATED.
35
TABLE CREATED.
TABLE CREATED.
Result :
Thus the given normalization concepts was executed and output was
verified.
Ex. No. 7
Develop A Package To Maintain Its Customer Details
Date :
Aim :
Develop a Package for Bank to maintain its Customers detail
Business Rules:
36
Savings bank a/c Rs.5000
Current a/c Rs.1000
Recurring depositRs.100
NRE a/c Rs.25000
3. Set current bal = opening balance at the opening time
4. All other deposits through transaction only
Transaction Table:
Table Creation :
Customer Information :
37
open_bal number(15,2),
current_bal number(15,2),
open_date varchar2(10));
When-tabpage-changed:
IF :SYSTEM.TAB_NEW_PAGE='CUST' THEN
GO_BLOCK('BANK_CUST_INF');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='TRANS' THEN
GO_BLOCK('BANK_CUST_INF1');
EXECUTE_QUERY;
38
END IF;
declare
n number;
begin
select count(*) into n from BANK_CUST_INF;
if n>0 then
select max(CUST_ACNO)+1 into :BANK_CUST_INF.CUST_ACNO from
BANK_CUST_INF;
else
:BANK_CUST_INF.CUST_ACNO:=1001;
end if;
insert_record;
end;
BEGIN
SELECT CURRENT_BAL INTO :BANK_TRANS.AVL_BAL FROM
BANK_CUST_INF
WHERE CUST_ACNO=:BANK_CUST_INF1.CUST_ACNO;
IF :BANK_TRANS.TRANS_TYPE=1 THEN
:
BANK_TRANS.NEW_BAL:=:BANK_TRANS.AVL_BAL+:BANK_TRANS.TRA
NS_AMT;
39
ELSIF :BANK_TRANS.TRANS_TYPE=2 THEN
:BANK_TRANS.NEW_BAL:=:BANK_TRANS.AVL_BAL -
:BANK_TRANS.TRANS_AMT;
UPDATE BANK_CUST_INF
SET CURRENT_BAL = :BANK_TRANS.NEW_BAL
WHERE CUST_ACNO=:BANK_CUST_INF1.CUST_ACNO;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
WHEN OTHERS THEN NULL;
END;
if :bank_cust_inf1.account_type=1 then
:bank_cust_inf1.DSP_AC_TYPE:='Savings Bank Account';
elsif :bank_cust_inf1.account_type=2 then
40
:bank_cust_inf1.DSP_AC_TYPE:='Current Account';
elsif :bank_cust_inf1.account_type=3 then
:bank_cust_inf1.DSP_AC_TYPE:='Recurring Deposit';
elsif :bank_cust_inf1.account_type=4 then
:bank_cust_inf1.DSP_AC_TYPE:='NRE/NRO Savings Account';
end if;
41
Customer Account Transaction Screen:
Result :
Thus the given package was executed and output was verified.
Ex. No. 8
42
Date : Develop A Package For The Payroll of A Company
Aim :
Develop a package for the Pay-Roll of a Company
Employee Detail:
Table creation:
Employee information:
SQL>
create table employee_inf
(
empno number(5) primary key,
empname varchar2(100) not null,
join_date varchar2(10) not null,
job_title_id number(2),
deptno number(2),
basic_sal number(10,2),
over_time number(9,2),
bonus number(9,2),
deduction number(9,2),
43
net_salary number(9,2),
remark varchar2(100)
);
Table created.
Table created.
Table created.
44
SQL>
create table emp_overtime
(
empno number(5),
ot_date varchar2(10),
ot_hrs number(2),
ot_pay number(10,2),
ot_amt number(10,2)
);
Table created.
SQL>
SQL> INSERT INTO emp_job_title
2 VALUES (1,'MANAGER');
1 row created.
1 row created.
45
Form level triggers – WHEN-NEW-FORM-INSTANCE:
set_window_property(forms_mdi_window,window_state,MAXIMIZE);
set_window_property('MAIN',window_state,MAXIMIZE);
declare
n number;
begin
n:=POPULATE_GROUP('RG_EMP');
POPULATE_LIST('EMPLOYEE_INF.EMPNO','RG_EMP');
n:=POPULATE_GROUP('RG_DEPT');
POPULATE_LIST('EMPLOYEE_INF.DEPTNO','RG_DEPT');
n:=POPULATE_GROUP('RG_TITLE');
POPULATE_LIST('EMPLOYEE_INF.JOB_TITLE_ID','RG_TITLE');
END;
WHEN-TAB-PAGE-CHANGED:
IF :SYSTEM.TAB_NEW_PAGE='EMP' THEN
GO_BLOCK('EMPLOYEE_INF');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='DEPT' THEN
GO_BLOCK('EMP_DEPT');
EXECUTE_QUERY;
46
ELSIF :SYSTEM.TAB_NEW_PAGE='OT' THEN
GO_BLOCK('EMPLOYEE_INF1');
EXECUTE_QUERY;
END IF;
declare
n number;
begin
select count(*) into n from EMPLOYEE_INF;
if n>0 then
select max(EMPNO)+1 into :EMPLOYEE_INF.EMPNO from employee_inf;
else
:EMPLOYEE_INF.EMPNO:=1001;
end if;
end
insert_record;
:EMPLOYEE_INF.NET_SALARY:=
(NVL(:EMPLOYEE_INF.basic_sal,0)+
NVL(:EMPLOYEE_INF.over_time,0)+NVL(:EMPLOYEE_INF.bonus,0))-
(NVL(:EMPLOYEE_INF.deduction,0));
47
:EMP_OVERTIME.ot_pay:=
ROUND((((:EMPLOYEE_INF1.basic_sal*:EMP_OVERTIME.ot_hrs)/208)*1.5),2);
:
EMP_OVERTIME.ot_amt:=:EMP_OVERTIME.ot_hrs*:EMP_OVERTIME.ot_pay;
Screen Shot:
48
Search Module :
Overtime Calculation :
49
Monthly Pay-Roll Preperation :
Result :
Thus the given package was executed and output was verified.
50
Ex. No. 9
Implement The Inventory Control System With A
Date : Reorder Level
Aim :
Implement the Inventory Control System with Re-order level
Inventory Master:
Business Rules:
Inventory Transaction:
51
Create table:
Master Information:
Transaction Information
52
Design time Codings:
set_window_property(forms_mdi_window,window_state,MAXIMIZE);
set_window_property('MAIN',window_state,MAXIMIZE);
declare
n number;
begin
n:=POPULATE_GROUP('RG_ITEM');
POPULATE_LIST('INVENTORY_TRANS.ITEM_CODE','RG_ITEM');
END;
IF :SYSTEM.MODE='NORMAL' THEN
:INVENTORY_MASTER.MIN_QTY:=10;
:INVENTORY_MASTER.MAX_QTY:=100;
END IF;
IF :SYSTEM.TAB_NEW_PAGE='MASTER' THEN
GO_BLOCK('INVENTORY_MASTER');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='TRANS' THEN
GO_BLOCK('INVENTORY_TRANS');
EXECUTE_QUERY;
END IF;
53
On Insert trigger on inventory master (item code):
declare
n number;
begin
select count(*) into n from inventory_master;
if n>0 then
select max(item_code)+1 into :inventory_master.item_code from inventory_master;
else
:inventory_master.item_code:=1;
end if;
insert_record;
end;
begin
select unit_price,avl_qty into :inventory_trans.dsp_up,:inventory_trans.dsp_avl from
inventory_master
where item_code=:inventory_trans.item_code;
exception when no_data_found then null;
when others then null;
end;
:inventory_trans.trans_amt:=:inventory_trans.trans_qty*:inventory_trans.dsp_up;
54
On delete entry
UPDATE INVENTORY_MASTER
SET AVL_QTY=AVL_QTY+:INVENTORY_TRANS.TRANS_QTY
WHERE ITEM_CODE=:INVENTORY_TRANS.ITEM_CODE;
delete_record;
Post insert:
UPDATE INVENTORY_MASTER
SET AVL_QTY=AVL_QTY-:INVENTORY_TRANS.TRANS_QTY
WHERE ITEM_CODE=:INVENTORY_TRANS.ITEM_CODE;
Post Query:
begin
select unit_price,avl_Qty
into :inventory_trans.dsp_up, :inventory_trans.dsp_avl
from inventory_master where item_code = :inventory_trans.item_code;
exception
when no_data_found then null;
when others then null;
end;
55
Runtime Screen Shot(s):
Result :
56
Thus the given package was executed and output was verified.
57