Index Prog-advJava1
Index Prog-advJava1
INDEX
1 Write a java program to scroll the text from left to right and vice versa
continuously.
3 Write a java program using applet for bouncing ball, for each bounce color of
ball should change randomly.
13 Write a JSP program to create an online shopping mall. User must be allowed
to do purchase from two pages. Each page should have a page total. The third
page should display a bill, which consists of a page total of whatever the
purchase has been done and print the total. (Use Session)
14 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.
15 Write a JSP program which accept UserName in a TextBox and greets the user
according to the time on server machine.
Solved Programs
[Link]
<html>
<head>
</head>
<body>
Write a java program using applet for if(f1==4)
bouncing ball, for each bounce color of ball [Link]([Link]);
should change randomly. if(f1==5)
[Link]([Link]);
[Link](150,y+10,20,20);
import [Link].*; if(y==400)
import [Link].*; {
f1++; f=1;
/*<applet code="[Link]" height=400 }
width=350></applet>*/ }
public class BounsingBall extends if(f==1) {
[Link] implements Runnable if(f1==1)
{ [Link]([Link]);
Thread t; if(f1==2)
int f,y,f1,f2,f3; [Link]([Link]);
public void init() if(f1==3)
{ [Link]([Link]);
t=new Thread(this); if(f1==4)
[Link](); [Link]([Link]);
f=0; y=0; f1=0; if(f1==5)
} [Link]([Link]);
public void run() [Link](150,y-10,20,20);
{ try{ if(y==0)
if (f==0){ [Link](10); {
y=y+5; f1++; f=0;
repaint(); }
if(f1==6) } }
f1=0; }
}
if(f==1) { [Link](10);
y=y-5;
repaint();
if(f1==6)
f1=0;
}
}catch(Exception e){ }
run();
}
public void paint(Graphics g)
{
if(f==0) {
if(f1==1)
[Link]([Link]);
if(f1==2)
[Link]([Link]);
if(f1==3)
[Link]([Link]);
Write a Java Program to delete details of }
students whose initial character of their name }
is ‘S’. catch(Exception e)
{
import [Link].*; [Link](e);
import [Link].*; }
public class Employee }
{ }
public static void main(String args[]) ******************************************
{
try {
[Link]("[Link]");
Connection
con=[Link]("jdbc:odbc:BC
A");
Statement stmt=[Link]();
ResultSet rs=[Link]("Select *
from Employee");
[Link](" EID "+" Ename "+"
Address "+" Salary ");
while([Link]())
{
[Link]([Link](1)+"\t");
[Link]([Link](2)+"\t");
[Link]([Link](3)+"\t");
[Link]([Link](4)+"\t");
[Link]("\n");
}
String s="delete from Employee where
Ename like 'S%'";
int n=[Link](s);
if(n>0)
{
[Link]("Record is
Deleted...!!!");
}
else {
[Link]("Record is not found
in table...!!!");
}
ResultSet rs1=[Link]("Select *
from Employee");
[Link](" EID "+" Ename "+"
Address "+" Salary ");
while([Link]())
{
[Link]([Link](1)+"\t");
[Link]([Link](2)+"\t");
[Link]([Link](3)+"\t");
[Link]([Link](4)+"\t");
[Link]("\n");
Write a java program in multithreading [Link](100,100,100,100);
using applet for Traffic signal. [Link](100,100,100,100);
import [Link].*; r=0; }
import [Link].*; if (g1==1)
import [Link].*; { [Link]([Link]);
[Link](100,225,100,100);
public class slip3_2 extends [Link] g1=0;
implements Runnable [Link](100,225,100,100);
}
{ int r,g1,y,i; if (y==1) {
[Link]([Link]);
Thread t; [Link](100,350,100,100);
public void init() y=0;
{ [Link](100,350,100,100);
r=0;g1=0;y=0; } }}
t=new Thread(this); <html>
[Link](); <head>
} <body>
public void run() <applet code= "slip3_2.class" height="600"
{ try width="600"></applet>
{
for (i=24;i>=1;i--) public void paint(Graphics g)
{ {
[Link](100); [Link](100,100,100,100);
if (i>=16 && i<24) [Link](100,225,100,100);
{ [Link](100,350,100,100);
g1=1; if (r==1) {
repaint(); [Link]([Link]);
} [Link](100,100,100,100);
if (i>=8 && i<16) [Link](100,100,100,100);
{ r=0;
y=1; }
repaint(); if (g1==1)
} {
if (i>=1 && i<8) [Link]([Link]);
{ [Link](100,225,100,100);
r=1; g1=0;
repaint(); [Link](100,225,100,100);
} }
}
if (i==0) if (y==1)
{
run(); {
} [Link]([Link]);
}catch(Exception e) {} } [Link](100,350,100,100);
public void paint(Graphics g) y=0;
{ [Link](100,350,100,100);
[Link](100,100,100,100); }
[Link](100,225,100,100); }
[Link](100,350,100,100); </body>
if (r==1) { </html>
[Link]([Link]); *****************************************
Write a Multithreading program in java to {
display the number’s between 1 to 100
new Mythread();
continuously in a Text Field by clicking on
button. }
import [Link].*; }
import [Link].*; class Mythread extends Thread
import [Link]; {
import [Link]; Mythread()
public class MultiThread extends JFrame {
implements ActionListener
start();
{
}
Container cc;
public void run()
JButton b1,b2;
{
JTextField t1;
for(int i=1;i<=100;i++)
MultiThread()
{
{
try {
setVisible(true);
[Link](1000);
setSize(1024,768);
}
cc=getContentPane();
catch (InterruptedException e) {
setLayout(null);
}
t1=new JTextField(500);
[Link]([Link]()+""+i+"\n");
[Link](t1);
//[Link]() }
[Link](10,10,1000,30);
}
b1=new JButton("start");
}
[Link](b1);
public static void main(String arg[])
[Link](20,50,100,40);
{
[Link](this);
new MultiThread().show();
}
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
*****************************************
public void actionPerformed(ActionEvent e)
{
if([Link]()==b1)
Write a JDBC Program in java to display the public static void main(String args[])
names of Employees starting with ‘S’ { try { int eno,sal;
character. String name;
BufferedReader br=new
import [Link].*; BufferedReader(new
public class slip21_1
InputStreamReader([Link]));
{
public static void main(String args[ ]) [Link]("[Link]");
{ cn=[Link]("jdbc:odbc:emp
Connection con; ","","");
try{ String str="create table Emp(eno number,name
[Link]("[Link]"); varchar(20),sal number)";
con=[Link]("jdbc:odbc:m ps=[Link](str);
ydsn2"); [Link]();
if(con==null){ [Link]("\nEmployee Table Created");
[Link]("Connection Failed"); [Link]("\n How many Records you
[Link](1);} want to insert?
[Link]("Connection Established"); int n=[Link]([Link]());
Statement stmt=[Link]( );
[Link]("\nEnter "+n+" Records \n");
ResultSet rs=[Link]("select * From
for(int i=0;i<n;i++) {
employee where ename like 'S%' ");
[Link]("eno\t"+"ename\t"+"department [Link]("\nEnter Emp No.");
\t"+"sal\t"); eno=[Link]([Link]());
while([Link]( )) [Link]("Enter Employee name");
{ name=[Link]();
[Link]("\n"+[Link](1)+"\t"+[Link] [Link]("Enter sal");
ng(2)+"\t"+[Link](3)+"\t"+[Link](4)); sal=[Link]([Link]());
} ps=[Link]("insert into Emp
[Link]( ); values(?,?,?)");
[Link]( ); [Link](1,eno);
[Link]( ); [Link](2,name);
} [Link](3,sal);
catch(Exception e)
[Link]();
{
}
[Link](e);
} [Link]("\nAll Records are: \n");
} st=[Link]();
} rs=[Link]("select * from Emp");
*************************************** [Link]("eno \t name \t sal.");
while([Link]()) {
Write a Java Program to create an Emp
(ENo, EName, and Sal) table and insert [Link]([Link]("eno")+"\t"+[Link]
record into it. (Use PreparedStatement g ("name")+"\t"+[Link]("sal")); }
Interface) [Link]();
import [Link].*; }catch(Exception e)
import [Link].*; { [Link](e);
public class CreateEmpTable } }}
{ static Connection cn; Note: - In this program the table created only
static Statement st; once. After that it will gives msg that “Table is
static PreparedStatement ps; created”
static ResultSet rs; *****************************************
Write a java program to count the number of Write a Multithreading program in java to
records in a table. display all the alphabets from A to Z after 3
seconds.
import [Link].*;
import [Link].*; import [Link].*;
class slip10 import [Link].*;
{ class mythread implements Runnable{
public static void main(String args[ ]) Thread t;
{ public mythread(){
Connection con; t=new Thread(this);
[Link]();}
try public void run()
{ {
[Link]("[Link]"); char ch;
con=[Link]("jdbc:odbc:em for(ch='a';ch<='z';ch++)
p"); {
if(con==null) [Link](ch);
{ try{
[Link]("Connection failed"); [Link](3000);}
[Link](1); catch(Exception e){}}}}
} class demo
[Link]("Connection Established....."); {public static void main(String s[]){
Statement stmt=[Link]( ); mythread m=new mythread();}}
ResultSet rs=[Link]("select * from
Emp"); output:-
int cnt=0; C:\Program Files\Java\jdk1.6.0_20\bin>javac
while([Link]( )) [Link]
{
cnt++; C:\Program Files\Java\jdk1.6.0_20\bin>java demo
}
[Link]("Number of Records are :- **********************************
"+cnt);
}
catch(Exception e)
{
[Link](e);
}
}
}
Output:-
C:\Program Files\Java\jdk1.6.0_20\bin>javac
[Link]
***************************
Write a java program for simple standalone msg=[Link]();
chatting application. (using AWT) [Link](msg);
[Link]("");
import [Link].*; String reply=(String)[Link]();
import [Link].*; [Link](reply);
import [Link].*; }
import [Link].*; catch(Exception e){}
import [Link].*; }}
class Awtcchat extends Frame implements public static void main(String a[]) throws
ActionListener { Exception {
TextField t1; Awtcchat ob=new Awtcchat();
}
Button b1; }
Socket s;
Scanner sc;
Server Program:
DataOutputStream dos;
DataInputStream dis; import [Link].*;
String msg;
Label l1,l2; import [Link].*;
Awtcchat() throws Exception import [Link].*;
import [Link].*;
{ import [Link].*;
[Link](this); {
sc=new Scanner([Link]);
s=[Link]();
dos=new
DataOutputStream([Link]()); dis=new
DataInputStream([Link]());
}public void actionPerformed(ActionEvent ae)
{
if([Link]()==b1)
{try
{String reply=(String)[Link]();
[Link](reply);
msg=[Link]();
[Link](msg);
[Link]("");
}catch(Exception e){}
}}
public static void main(String a[]) throws
Exception {
Awtschat ob=new Awtschat();
}
}
Output:
C:\Program Files\Java\jdk1.6.0_20\bin>javac
[Link]
C:\Program Files\Java\jdk1.6.0_20\bin>java
Awtschat
C:\Program Files\Java\jdk1.6.0_20\bin>javac
[Link]
C:\Program Files\Java\jdk1.6.0_20\bin>java
Awtcchat
*********************************
Write a Socket program in java for simple
stand-alone chatting application. {
s1 = (String)[Link]();
import [Link].*; if([Link]("end") || [Link]("END"))
import [Link].*; {
class C_Slip13_2 [Link]("chatting terminated");
{
public static void main(String a[]) throws break;
Exception { }
Socket s = new Socket("localhost",1000); [Link]("Client "+s1);
[Link]("client is connected : "); [Link]("Server ...");
DataInputStream ios=new s2 = [Link]();
DataInputStream([Link]()); [Link](s2);
DataOutputStream dos=new if([Link]("end") || [Link]("END"))
DataOutputStream([Link]());
BufferedReader br = new BufferedReader(new {
InputStreamReader([Link])); [Link]("chatting terminated");
String s1,s2; break;
while(true) }}}}
{ Output:
[Link]("Server ...."); C:\Program Files\Java\jdk1.6.0_20\bin>javac
s1=[Link](); C_Slip13_2.java
[Link](s1); C:\Program Files\Java\jdk1.6.0_20\bin>java
s2=(String)[Link](); C_Slip13_2
if([Link]("end") || [Link]("END")) client is connected :
{ Server ....
[Link]("chatting terminated"); hi
break; Client hi
}[Link]("Client "+s2); Server ....
}}} how are u
Client i am fine
import [Link].*; Server ....
import [Link].*; whats going on
Client nothing
class S_Slip13_2 Server ....
{ C:\Program Files\Java\jdk1.6.0_20\bin>javac
public static void main(String a[]) throws S_Slip13_2.java
Exception {
ServerSocket ss = new ServerSocket(1000); C:\Program Files\Java\jdk1.6.0_20\bin>java
S_Slip13_2
[Link]("Server is waiting for client : "); Server is waiting for client :
Socket s =[Link](); Client is connected
[Link]("Client is connected"); Client hi
DataInputStream ios=new Server ...
DataInputStream([Link]()); hi
DataOutputStream dos=new Client how are u
DataOutputStream([Link]()); Server ...
i am fine
BufferedReader br = new BufferedReader(new Client whats going on
InputStreamReader([Link])); Server ...
String s1,s2; Nothing
while(true) **************************************
Write a JSP program to create an online
shopping mall. User must be allowed to [Link]
do purchase from two pages. Each page <%@page contentType="text/html"
should have a page total. The third page pageEncoding="UTF-8"%>
should display a bill, which consists of a <!DOCTYPE html>
page total of whatever the purchase has <%
been done and print the total. (Use String rice = [Link]("rice");
Session) int r = [Link](rice);
String wheat = [Link]("wheat");
int w = [Link](wheat);
[Link] int tr = r * 40;
<%@page contentType="text/html"
int wt = w * 60;
pageEncoding="UTF-8"%>
int pt = tr + wt;
<!DOCTYPE html>
[Link]("first_Total", pt);
<html> %>
<head> <html>
<meta http-equiv="Content-Type" <head>
content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type"
<title>JSP Page</title> content="text/html; charset=UTF-8">
</head> <title>JSP Page</title>
<body> </head>
<form action=" [Link]" method="post"> <body>
<h1>Shopping Mall</h1>
<h1>Shopping Mall</h1>
Rice : <form action=" [Link]" method="post">
<select name="rice"> Maggi :
<option value="2">2 Kg</option> <select name="maggi">
<option value="5">5 Kg</option> <option value="1">1</option>
<option value="10">10 Kg</option> <option value="2">2</option>
<option value="15">15 Kg</option> <option value="3">3</option>
</select> <option value="4">4</option>
Wheat : <option value="5">5</option>
<select name="wheat"> </select>
<option value="2">2 Kg</option>
Good Day :
<option value="5">5 Kg</option>
<select name="good">
<option value="10">10 Kg</option>
<option value="1">1</option>
<option value="15">15 Kg</option> <option value="2">2</option>
</select> <option value="3">3</option>
<input type="submit" value="Submit"> <option value="4">4</option>
</form> <option value="5">5</option>
</body>
</select>
</html> <input type="submit" value="Submit">
</form>
</body>
</html>
[Link]
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% String m = [Link]("maggi");
String g = [Link]("good");
int mp = [Link](m);
int gp = [Link](g);
int mpt = mp * 10;
int gpt = gp * 10;
int secont_total = mpt + gpt;
int first_Total =
(Integer)[Link]().getAttribute("first_To
tal");
int grand_Total = first_Total + secont_total;
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Shopping Mall</h1>
<h1>First Page Total
<%=first_Total%></h1><br>
<h1>Second Page Total
<%=secont_total%></h1><br>
<h1>Total Bill<%=grand_Total%></h1><br>
</body>
</html>
per=[Link]([Link]());
Write a java program to create a student
table with field’s rno, name and per. ps=[Link]("insert into Stud
Insert values in the table. Display all the values(?,?,?)");
details of the student on screen. [Link](1,rno);
[Link](2,name);
import [Link].*; [Link](3,per);
import [Link].*; [Link]();
public class CreateStudentTable }
{ [Link]("\nAll
static Connection cn; Records are: \n");
static Statement st; st=[Link]();
static PreparedStatement ps; rs=[Link]("select *
static ResultSet rs; from Stud");
public static void main(String args[]) [Link]("RollNo
{ \t Name \t Perc.");
try while([Link]())
{int rno,per; {
String name;
BufferedReader br=new [Link]([Link]("rno")+"\t"+[Link]
BufferedReader(new g("name")+"\t"+[Link]("per"));
InputStreamReader([Link])); }
[Link]();
[Link]("[Link]"); }
catch(Exception e
cn=[Link]("jdbc:odbc:dsn1 {
","",""); [Link](e);
String str="create table }
Stud(rno number,name varchar(20),per number)"; }
ps=[Link](str); }
[Link]();
*************************************
[Link]("\nStudent Table Created");
[Link]("\n How
many Records you want to insert?");
int
n=[Link]([Link]());
[Link]("\nEnter
"+n+" Records \n");
for(int i=0;i<n;i++)
{
rno=[Link]([Link]());
[Link]("Enter per");
Write a JSP program which accept
UserName in a TextBox and greets the
user according to the time on server
machine.
[Link]
<html>
<body>
<form action=”[Link]” method=”get”>
Username:<input type=”text” name=”uname”/>
</br>
<input type=”button” name=”submit”/>
</form>
</body>
</html>
[Link]
<%@ page language=”java”
import=”[Link].*”%>
<html>
<body>
<% String
name=[Link](“uname”);%>
<%=”Welcome”+name+”<br>”%>
<%=”Server date/time:”+new [Link]()%>
</body>
</html>
*****************************************