Beruflich Dokumente
Kultur Dokumente
SEAT NO :
import java.io.*;
import java.net.*;
class S_Slip1_1
{
public static void main(String a[]) throws Exception
{
ServerSocket ss = new ServerSocket(1000);
System.out.println("Server is waiting for client : ");
Socket s =ss.accept();
System.out.println("Client is connected");
}
}
CLIENT:
import java.io.*;
import java.net.*;
class C_Slip1_1
{
public static void main(String a[]) throws Exception
{
Socket ss = new Socket("localhost",1000);
System.out.println("IP Address = "+ss.getInetAddress());
System.out.println("Client port = "+ss.getPort());
}
}
2. Write a multithreading program in java to display all the vowels from a given
String.(Use Thread Class)
import java.util.*;
import java.io.*;
}
public void run()
{
System.out.println("Vowels are ");
for(int i=0;i<s1.length();i++)
{
char ch=s1.charAt(i);
if(ch=='a'||ch=='e'||
ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
System.out.print(" "+ch);
}
}
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection
Failed....");
System.exit(1);
}
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * From
employee Where dept='computer science'");
System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
while(rs.next())
{
System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+""+r
s.getInt(4));
}
con.close();
rs.close();
stmt.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
4.Write a client server programs which displays the server machines date and time
on the client machine.
/* Server_Slip14_1*/
import java.net.*;
import java.io.*;
import java.util.Date;
/* client_Slip14_1*/
import java.net.*;
import java.io.*;
import java.util.*;
public class Client_Slip14_1
{
public static void main(String args[]) throws Exception
{
Socket s = new Socket("localhost",4444);
DataInputStream dos = new DataInputStream(s.getInputStream());
String time = dos.readUTF();
System.out.println("Current date and time is "+time);
}
}
5. Write a JDBC program to accept the details of customer (CID, CName, Address,
Ph_No) and store it into the database (Use PreparedStatement interface)
import java.sql.*;
import java.io.*;
class Slip6_1
{
public static void main(String a[])
{
PreparedStatement ps;
Connection con;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection
Failed......");
System.exit(1);
}
System.out.println("Connection
Esatablished......");
Statement stmt=con.createStatement();
System.out.println("Customer Details....");
System.out.println("Enter CID");
int cid=Integer.parseInt(br.readLine());
ps.setInt(1,cid);
System.out.println("Enter name");
String name=br.readLine();
ps.setString(2,name);
System.out.println("Enter Address");
String add=br.readLine();
ps.setString(3,add);
System.out.println("Enter Ph_No");
String phno=br.readLine();
ps.setString(4,phno);
int no=ps.executeUpdate();
if(no!=0)
System.out.println("Data inserted
succesfully.....");
else
System.out.println("Data NOT
inserted");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Slip12_1()
{
f = new JFrame();
p = new JPanel();
t = new JTextField(60);
b = new JButton("Start");
t1 = new Thread(this);
b.addActionListener(this);
p.add(t);
p.add(b);
f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
9.Write a JDBC program to count the number of records in table.(Without using
standard method)
import java.sql.*;
class Slip10_1
{
public static void main(String args[])
{
Connection con;
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection
Failed.......");
System.exit(1);
}
System.out.println("Connection
Established......");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from
employee");
int cnt=0;
while(rs.next())
{
cnt++;
}
System.out.println("Number of records in Table
are:"+cnt);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
15. Create a JSP page to accept a number from an user and display it in words:
Example: 123 � One Two Three. The output should be in red color�
HTML FILE :
<!DOCTYPE html>
<html>
<body>
<form method=get action="Slip19.jsp">
Enter Any Number : <input type=text name=num><br><br>
<input type=submit value="Display">
</form>
</body>
</html>
JSP FILE:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<font color=red>
<%! int i,n;
String s1;
%>
<% s1=request.getParameter("num");
n=s1.length();
i=0;
do
{
char ch=s1.charAt(i);
switch(ch)
{
case '0': out.println("Zero ");break;
case '1': out.println("One ");break;
case '2': out.println("Two ");break;
case '3': out.println("Three ");break;
case '4': out.println("Four ");break;
case '5': out.println("Five ");break;
case '6': out.println("Six ");break;
case '7': out.println("Seven ");break;
case '8': out.println("Eight ");break;
case '9': out.println("Nine ");break;
}
i++;
}while(i<n);
%>
</font>
</body>
</html>
16. Write a java program to create a student table with field�s rno, name and per.
Insert values in the table. Display all the details of the student on screen. (Use
PreparedStatement Interface)
import java.awt.event.*;
import javax.swing.*;
class Message implements Runnable
{
JTextField t;
public void run()
{
for(int i =1; i<=100;i++)
{
t.setText(""+i);
try
{
Thread.sleep(50);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
class Slip12_1 implements ActionListener
{
JFrame f;
JPanel p;
JTextField t;
JButton b;
Thread t1;
Slip12_1()
{
f = new JFrame();
p = new JPanel();
t = new JTextField(60);
b = new JButton("Start");
t1 = new Thread(this);
b.addActionListener(this);
p.add(t);
p.add(b);
f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}
17. Write a JSP script to check whether given mail ID is valid or not. (Mail ID
should contain one @ symbol and atleast one Dot(.) symbol)
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<form action="Slip16.jsp" method="post">
Enter Your Name : <input type="text" name="name"><br>
SLIP.jsp:
<%
class PrintDemo
{
public void printCount()
{
try
{
for(int i = 5; i > 0; i--)
{
System.out.println("Counter ---
" + i );
}
}
catch (Exception e)
{
System.out.println("Thread interrupted.");
}
}
T1.start();
T2.start();
Thread t = Thread.currentThread();
S = t.getName();
System.out.println("\n Current Thread name : "+S);
p = t.getPriority();
System.out.println("\n Current thread priority : "+p);
t.setName("My Thread");
S = t.getName();
System.out.println("\nChanged Name : "+S);
t.setPriority(2);
p = t.getPriority();
System.out.println("\nChanged Priority : "+p);
}
}
20.Write a JDBC Program in java to display the names of Employees starting with �S�
character
import java.sql.*;
class Slip21_1
{
public static void main(String args[])
{ Connection con;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection
Failed....");
System.exit(1);
}
System.out.println("Connection
Established...");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from
employee where name like 'S%'");
System.out.println("eno\t"+"ename\t"+"department\t"+"sal");
while(rs.next())
{
System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"
+rs.getInt(4));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}