SLIP 1: Write a java program to display IP Address and Name of client machine.
SERVER:
import java.io.*;
import java.net.*;
class S_Slip1_1
{
public static void main(String a[]) throws Exception
{
ServerSocketss = 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());
}
}
SLIP 2: Write a multithreading program in java to display all the vowels from a given String.
importjava.util.*;
import java.io.*;
}
public void run()
{
System.out.println("Vowels are ");
for(int i=0;i<s1.length();i++)
{
charch=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);
}
}
SLIP 3: Write a JDBC program to display the details of employees (eno, ename, department,
sal) whose department is “Computer Science”.
importjava.sql.*;
public class Slip3_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);
}
Statement stmt=con.createStatement();
ResultSetrs=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)+""+rs.getI
nt(4));
}
con.close();
rs.close();
stmt.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 4:
Write a java program to display “Hello Java” message n times on the screen. (Use Runnable
Interface).
inti,no;
Slip4(int n)
{
no = n;
}
public void run()
{
for(i = 1; i<=no; i++)
{
System.out.println("\nHello Java");
try
{
Thread.sleep(50);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 5 : Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a
record in it.
importjava.sql.*;
class Slip5_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();
//display details
ResultSetrs=stmt.executeQuery("select * From Teacher");
System.out.println("TNo\t"+"TName\t"+"sal\t"+"desg");
while(rs.next())
{
System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getStr
ing(4));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 6: Write a java program to accept the details of customer (CID, CName, Address,
Ph_No) and store it into the database(Use PreparedStatement interface)
importjava.sql.*;
import java.io.*;
class Slip6_1
{
public static void main(String a[])
{
PreparedStatementps;
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");
intcid=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();
}
}
}
SLIP 7: Write a JSP program to calculate sum of first and last digit of a given number.
Display sum in Red Color with font size 18.
HTML FILE
<!DOCTYPE html>
<html>
<body>
<form method=post action="Slip7.jsp">
Enter Any Number : <Input type=text name=num><br><br>
<input type=submit value=Display>
JSP FILE:
SLIP 8: Write a multithreading program using Runnable interface to blink Text on the frame.
importjava.awt.*;
importjava.awt.event.*;
SLIP 9: Write a JDBC program to delete the records of employees whose names are starts
with ‘A’character.
importjava.sql.*;
class Slip9_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)
stmt=con.createStatement();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 10:Write a JDBC program to count the number of records in table.(Without using
standard method)
importjava.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();
ResultSetrs=stmt.executeQuery("select * from employee");
intcnt=0;
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP11:Write a JDBC program to remove “percentage” column from student (rno, sname,
percentage) table. Student table is already created.
importjava.sql.*;
class Slip11
{
public static void main(String a[])
{
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();
int no = stmt.executeUpdate("alter table student drop column per");
if(no!=0)
System.out.println("Drop col sucessfully");
else
System.out.println("NOT Drop col ");
}
catch(Exception e)
{
System.out.println(e);
}
}
importjava.awt.event.*;
importjavax.swing.*;
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);
f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}
SLIP13: Write a java program to create a Mobile (Model_No, Company_Name, Price, Color)
table.
importjava.sql.*;
class Slip13_1
{
public static void main(String a[])
{
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();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
SLIP 14:
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.*;
importjava.util.Date;
/* client_Slip14_1*/
import java.net.*;
import java.io.*;
importjava.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);
}
importjava.sql.*;
import java.io.*;
class Slip15_1
{
public static void main(String args[])
{
Connection con;
Statement stmt;
PreparedStatementps;
String name;
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();
if(no==0)
{
System.out.println("Not updated in table....");
System.out.println("Name Not match"+name);
}
else
{
System.out.println("Succesfully updated in table....");
System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.ge
tString(4));
}
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP16: Write a JSP page, which accepts user name in a text box and greets the user
according to the time on server machine.
SLIP16_FIRST..jsp:
SLIP16.jsp:
<%
SLIP17: Write a java program which will display name and priority of current thread. Change
name of Thread to MyThread and set the priority to 2 and display it on screen.
class Slip17_1
{
public static void main(String a[])
{
String S;
int p;
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();
t.setPriority(2);
p = t.getPriority();
System.out.println("\nChanged Priority : "+p);
}
}
SLIP18 : Write a java program using multithreading to execute the threads sequentially.(Use
Synchronized Method)
classPrintDemo
{
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();
SLIP19: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 :
JSP FILE:
SLIP 20: Write a JSP program to display the details of Hospital (HNo, HName, Address) in
tabular form on browser
<html><body>
<%@ page import="java.sql.*;" %>
<%! inthno;
String hname,address; %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:hospital_data","","");
Statement st=cn.createStatement();
ResultSetrs=st.executeQuery("select * from Hospital");
%>
<table border="1" width="40%">
<tr>
<td>Hospital No</td>
<td>Name</td>
<td>Address</td>
</tr>
<% while(rs.next())
{
%>
<tr><td><%= rs.getInt("hno") %></td>
<td><%= rs.getString("hname") %></td>
<td><%= rs.getString("address") %></td>
</tr>
<%
}
cn.close();
}catch(Exception e)
{
out.println(e);
}
%>
</body></html>
SLIP21: Write a JDBC Program in java to display the names of Employees starting with ‘S’
character.
importjava.sql.*;
class Slip21_1
{
public static void main(String args[])
{ Connection con;
Statement stmt=con.createStatement();
ResultSetrs=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.ge
tInt(4));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 22:Write a java program to display IP Address and Name of client machine.
SERVER:
import java.io.*;
import java.net.*;
class Slip22_1
{
public static void main(String a[]) throws Exception
{
ServerSocketss = new ServerSocket(2000);
System.out.println("Server is waiting for client : ");
Socket s =ss.accept();
System.out.println("Client is connected");
DataInputStreamios=new DataInputStream(s.getInputStream());
String no = (String)ios.readUTF();
}
}
CLIENT:
import java.io.*;
import java.net.*;
class Client_22
{
public static void main(String a[]) throws Exception
{
Socket s = new Socket("localhost",2000);
BufferedReaderbr = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter no ");
String no = br.readLine();
SLIP23 :Write a JSP script to accept the details of Student (RNo, SName, Gender,
Comp_Know ,Class) and display it on the browser. Use appropriate controls for accepting
data.
HTML FILE:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Class :
<select name="Class">
<option value="11">11Th</option>
<option value="12">12Th</option>
<option value="FY">FY</option>
<option value="SY">SY</option>
<option value="TY">TY</option>
</select>
<br><br>
JSP FILE :
intrno = Integer.parseInt(request.getParameter("rno"));
out.println("\nRoll No :"+rno);
out.println("\nName :"+s_name);
out.println("\nGender :"+s_gender);
out.println("\nComp_Know :"+s_know);
out.println("\nClass :"+s_class);
%>
HTML FILE:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
JSP FILE :
boolean v = false;
v = email.matches("^[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\\.[a-zA-Z]{2,4}");
if(v == true)
{
out.println("\nValid Mail");
%>
SLIP 25 : Write a JSP script to accept UserName and his NickName through html page and
thendisplays username when visit count to page is odd and displays nickname when the visit
count to the page is even
HTML FILE:
<!DOCTYPE html>
<html>
<body>
<form method=get action="Slip25.jsp">
Enter User Name : <input type=text name=uname><br><br>
Enter Nick Name : <input type=text name=nname><br><br>
<input type=submit value="visit">
</form>
</body>
</html>
JSP FILE :
SLIP 26: Write a multithreading program in java to display all the alphabets from A to Z after
3 seconds
try
{
Thread.sleep(3000);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
SLIP 27 :Write a JDBC program to delete the details of given employee (ENoEName
Salary). Accept employee ID through command line.
System.out.println("Connection Established...");
rs=ps.executeQuery();
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.ge
tInt(4));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SLIP 28:Write a JSP program to check whether given number is Armstrong or not. (Use
Include directive).
HTML FILE :
JSP FILE:
intnum = Integer.parseInt(request.getParameter("num"));
int n = num;
intrem,no = 0;
while(n!=0)
{
rem = n%10;
no = no+rem*rem*rem;
n = n/10;
}
if(no == num)
{
out.println("\nArmstrong Number");
}
else
{
out.println("Not Armstrong");
}
%>
SLIP 29: Write a JSP program to accept Name and Age of Voter and check whether he is
eligible for voting or not
HTML FILE:
JSP FILE:
if(age >=18)
{
out.println(name + "\nAllowed to vote");
}
else
{
out.println(name + "\nNot allowed to vote");
}
%>
SLIP 30:Write a JSP program to display all the prime numbers between 1 to n in blue Color
HTML FILE:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
JSP FILE :
int n = Integer.parseInt(request.getParameter("num"));
intnum,i,count;
for(num=1;num<=n;num++)
{
count=0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0 &&num!=1)
{
%>
<html>
<body>
<font size ="14" color="blue"><%out.println("\t"+num);%>
</body>
</html>
<%
}
}
%>