Anda di halaman 1dari 30

TYBCA 15 MARKS 2016

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.*;

class Slip2_1 extends Thread


{
String s1;

NR CLASSES, PUNE [8796064387/90] Page 1


Slip2_1(String s)
{ s1=s;
start();

}
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);
}
}

public static void main(String a[]) throws Exception


{
BufferedReaderbr = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter a string");
String str=br.readLine();
Slip2_1 v=new Slip2_1(str);
}
}

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())

NR CLASSES, PUNE [8796064387/90] Page 2


{

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).

public class Slip4 implements Runnable{

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);
}
}
}

NR CLASSES, PUNE [8796064387/90] Page 3


public static void main(String args[])
{
try
{
int n;

System.out.println("\nEnter Number : ");


BufferedReaderbr = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
n = Integer.parseInt(s);
Thread t = new Thread(new Slip4(n));
t.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

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();

//create a table teacher


String query="create table Teacher"+"(TNoint ,"+"
TNamevarchar(20),"+" salint,"+" desgvarchar(20))";
stmt.executeUpdate(query);
System.out.println("given table created in database");

//insert record into teacher table

NR CLASSES, PUNE [8796064387/90] Page 4


stmt.executeUpdate("insert into Teacher
"+"values(1,'NRC',50000,'MCS')");
stmt.executeUpdate("insert into Teacher
"+"values(2,'ABC',10000,'MCA')");
stmt.executeUpdate("insert into Teacher
"+"values(3,'XYZ',40000,'MCA')");
stmt.executeUpdate("insert into Teacher
"+"values(4,'PQR',20000,'MCS')");
System.out.println("Succesfully inserted in table....");

//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();

NR CLASSES, PUNE [8796064387/90] Page 5


BufferedReaderbr = new BufferedReader(new
InputStreamReader(System.in));
String query="insert into Customer values(?,?,?,?)";
ps=con.prepareStatement(query);

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>

NR CLASSES, PUNE [8796064387/90] Page 6


</form>
</body>
</html>

JSP FILE:

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


<!DOCTYPE html>
<html>
<body>
<%! intn,rem,r; %>
<% n=Integer.parseInt(request.getParameter("num"));
if(n<10)
{
out.println("Sum of first and last digit is ");
%><font size=18 color=red><%= n %></font>
<%
}
else
{
rem=n%10;
do{
r=n%10;
n=n/10;
}while(n>0);
n=rem+r;
out.println("Sum of first and last digit is ");
%><font size=18 color=red><%= n %></font>
<%
}
%>
</body>
</html>

SLIP 8: Write a multithreading program using Runnable interface to blink Text on the frame.

importjava.awt.*;
importjava.awt.event.*;

class Slip8_1 extends Frame implements Runnable


{
Thread t;
Label l1;
int f;
Slip8_1()
{
t=new Thread(this);
t.start();
setLayout(null);
l1=new Label("Hello JAVA");

NR CLASSES, PUNE [8796064387/90] Page 7


l1.setBounds(100,100,100,40);
add(l1);
setSize(300,300);
setVisible(true);
f=0;
}
public void run()
{
try
{
if(f==0)
{
t.sleep(200);
l1.setText("");
f=1;
}
if(f==1)
{
t.sleep(200);
l1.setText("Hello Java");
f=0;
}
}
catch(Exception e)
{
System.out.println(e);
}
run();
}
public static void main(String a[])
{
new Slip8_1();
}
}

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)

NR CLASSES, PUNE [8796064387/90] Page 8


{
System.out.println("Connection Failed....");
System.exit(1);
}
System.out.println("Connection Established...");

stmt=con.createStatement();

int no = stmt.executeUpdate("Delete from employee where name like


'A%'");
if(no!=0)
System.out.println("Delete Data sucessfully.....");
else
System.out.println("Data NOT Deleted");

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;

NR CLASSES, PUNE [8796064387/90] Page 9


while(rs.next())
{
cnt++;
}
System.out.println("Number of records in Table are:"+cnt);
}

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);
}
}

NR CLASSES, PUNE [8796064387/90] Page 10


}

SLIP12:Write a java program to display the number’s between 1 to 100 continuously in a


TextField by clicking on button. (use Runnable Interface)

importjava.awt.event.*;
importjavax.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);

NR CLASSES, PUNE [8796064387/90] Page 11


p.add(b);

f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}

public void actionPerformed(ActionEvent e)


{
t1.start();
}
}

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();

String sql="create table


mobile"+"(Model_Noint,"+"Company_Namevarchar(20),"+"price float(6,2),"+"color
varchar(20))";
stmt.executeUpdate(sql);
System.out.println("Table Created sucessfully...");

con.close();

}
catch(Exception e)
{
System.out.println(e);
}

NR CLASSES, PUNE [8796064387/90] Page 12


}
}

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;

public class Server_Slip14_1


{
public static void main(String g[])throws UnknownHostException, IOException
{
ServerSocketss=new ServerSocket(4444);
System.out.println("server started");
Socket s=ss.accept();
System.out.println("Client connected");
Date d=new Date();
int m=d.getMonth();
m=m+1;
int y=d.getYear();
y=y+1900;
String time=""+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+" Date is
"+d.getDate()+"/"+m+"/"+y;
OutputStreamos=s.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
dos.writeUTF(time);
}
}

/* 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);
}

NR CLASSES, PUNE [8796064387/90] Page 13


}

SLIP15: Write a JDBC program in java to update an address of given


customer(cid,cname,address) and display updated details.

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();

String query="Update Customer set address=? where name=?";


ps=con.prepareStatement(query);

BufferedReaderbr = new BufferedReader(new


InputStreamReader(System.in));
System.out.println("Enter Customer name for Update:");
name=br.readLine();

System.out.println("Enter new Address:");


String addr=br.readLine();
ps.setString(1,addr);

NR CLASSES, PUNE [8796064387/90] Page 14


ps.setString(2,name);
int no=ps.executeUpdate();

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....");

ps=con.prepareStatement("select * from Customer where


name=?");
ps.setString(1,name);
ResultSetrs=ps.executeQuery();
System.out.println("cid\t"+"Name\t"+"address\t"+"ph_no");
while(rs.next())
{

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:

<%@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>

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


</form>
</body>

NR CLASSES, PUNE [8796064387/90] Page 15


</html>

SLIP16.jsp:

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


<!DOCTYPE html>

<%

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

Calendar rightnow = Calendar.getInstance();


int time = rightnow.get(Calendar.HOUR_OF_DAY);

if(time > 0 && time <= 12)


{
out.println("Good Morning"+name);
}
else if(time < 12 && time >=16)
{
out.println("Good Afternoon"+name);
}
else
{
out.println("Good Night"+name);
}
%>

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();

NR CLASSES, PUNE [8796064387/90] Page 16


System.out.println("\nChanged Name : "+S);

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.");
}
}

classThreadDemo extends Thread


{
private Thread t;
private String threadName;
PrintDemo PD;

ThreadDemo( String name, PrintDemopd)


{
threadName = name;
PD = pd;
}
public void run()
{
synchronized(PD)
{

NR CLASSES, PUNE [8796064387/90] Page 17


PD.printCount();
}
System.out.println("Thread " + threadName + " exiting.");
}

public void start ()


{
System.out.println("Starting " + threadName );
if (t == null)
{
t = new Thread (this, threadName);
t.start ();
}
}

public class Slip18_1


{
public static void main(String a[])
{

PrintDemo PD = new PrintDemo();

ThreadDemo T1 = new ThreadDemo( "Thread - 1 ", PD );


ThreadDemo T2 = new ThreadDemo( "Thread - 2 ", PD );

T1.start();
T2.start();

// wait for threads to end


try
{
T1.join();
T2.join();
}
catch( Exception e)
{
System.out.println(e);
}
}
}

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 :

NR CLASSES, PUNE [8796064387/90] Page 18


<!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>
<%! inti,n;
String s1;
%>
<% s1=request.getParameter("num");
n=s1.length();
i=0;
do
{
charch=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>

SLIP 20: Write a JSP program to display the details of Hospital (HNo, HName, Address) in
tabular form on browser

NR CLASSES, PUNE [8796064387/90] Page 19


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<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;

NR CLASSES, PUNE [8796064387/90] Page 20


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();
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();

NR CLASSES, PUNE [8796064387/90] Page 21


intnum =Integer.parseInt(no);
int fact = 1;
for(int i=1;i<=num;i++)
fact = fact *i;
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
dos.writeUTF(""+num);

}
}

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();

DataOutputStream dos=new DataOutputStream(s.getOutputStream());


dos.writeUTF(no);

DataInputStream dis=new DataInputStream(s.getInputStream());


String num = (String)dis.readUTF();
System.out.println("Fcatorial of no = "+num);
}
}

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>

NR CLASSES, PUNE [8796064387/90] Page 22


<h1>Enter Information</h1>
<form action="Slip23.jsp" method="post">
Roll No : <input type="text" name="rno"><br><br>

Name : <input type="text" name="name"><br><br>

Gender : <input type="radio" name="gender" value="Male" checked>Male


<input type="radio" name="gender" value="Female">Female
<br><br>

Comp_Know : <input type="radio" name="know" value="Yes" checked>Yes


<input type="radio" name="know" value="No">No
<br><br>

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>

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


</form>
</body>
</html>

JSP FILE :

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


<!DOCTYPE html>
<%

intrno = Integer.parseInt(request.getParameter("rno"));

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

String s_gender = request.getParameter("gender");

String s_know = request.getParameter("know");

String s_class = request.getParameter("Class");

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);
%>

NR CLASSES, PUNE [8796064387/90] Page 23


SLIP 24:Write a JSP script to check whether given mail ID is valid or not. (Mail ID should
contain one @ symbol)

HTML FILE:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

<form action="Slip24.jsp" method="post">


Enter Email Id : <input type="text" name="email"><br><br>

<input type="submit" value="Check">


</form>
</body>
</html>

JSP FILE :

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


<!DOCTYPE html>
<%

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

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");

NR CLASSES, PUNE [8796064387/90] Page 24


}
else
{
out.println("\nInvalid email id");
}

%>

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 :

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


<!DOCTYPE html>
<html>
<body>
<%!
intcnt=0;
String uname,nname;
%>
<%
uname=request.getParameter("uname");
nname=request.getParameter("nname");
cnt++;
if(cnt%2==0)
out.println("Hello "+nname+"......... Visit Count "+cnt);
else
out.println("Hello "+uname+"......... Visit Count "+cnt);
%>

NR CLASSES, PUNE [8796064387/90] Page 25


<br><br>
<a href="Slip25.html">VISIT</a>
</body>
</html>

SLIP 26: Write a multithreading program in java to display all the alphabets from A to Z after
3 seconds

public class Slip26_1 extends Thread


{
char c;

public void run()


{
for(c = 'A'; c<='Z';c++)
{
System.out.println(""+c);

try
{
Thread.sleep(3000);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

public static void main(String args[])


{
Slip26_1 t = new Slip26_1();
t.start();
}
}

SLIP 27 :Write a JDBC program to delete the details of given employee (ENoEName
Salary). Accept employee ID through command line.

NR CLASSES, PUNE [8796064387/90] Page 26


importjava.sql.*;
class Slip27_1
{
public static void main(String a[])
{
Connection con;
PreparedStatementps;
ResultSetrs;
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...");

ps=con.prepareStatement("select * from employee where eid=?");


int id = Integer.parseInt(a[0]);
ps.setInt(1,id);

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 :

NR CLASSES, PUNE [8796064387/90] Page 27


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="Slip28.jsp" method="post">
Enter Number :
<input type="text" name="num"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>

JSP FILE:

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


<!DOCTYPE html>
<%

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:

NR CLASSES, PUNE [8796064387/90] Page 28


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="Slip29.jsp" method="post">
Name : <input type="text" name="name"><br><br>

Age : <input type="text" name="age"><br><br>

<input type="submit" value="Check">


</form>
</body>
</html>

JSP FILE:

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


<!DOCTYPE html>
<%

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

int age = Integer.parseInt(request.getParameter("age"));

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>

NR CLASSES, PUNE [8796064387/90] Page 29


<body>
<form action="Slip30.jsp" method="post">
Enter Number :
<input type="text" name="num">

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


</form>
</body>
</html>

JSP FILE :

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


<!DOCTYPE html>
<%

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>
<%

}
}

%>

NR CLASSES, PUNE [8796064387/90] Page 30

Anda mungkin juga menyukai