EX NO: 1
DATE:
Substring Removal from a String Using String Buffer class
Aim:
Procedure:
Coding:
import [Link].*;
class strbuf
{
public static void main(String args[])
{
StringBuffer sb=new StringBuffer("jav");
[Link]("Before insert");
[Link](sb);
[Link]("After insert");
[Link]([Link](0,"Welcome to "));
[Link]("After append");
[Link]([Link]('a'));
[Link]("Length of the string");
[Link]([Link]());
[Link]("Change tyhe char");
[Link]([Link](0,5));
[Link]("After delete"+[Link](0,5));
[Link]("After replace:"+[Link](0,2,"Welcome"));
}
}
OUTPUT:
Aim:
3
EX NO: 2
DATE:
Determining the Perimeter and Area of Triangle Using Stream Class
Procedure:
Coding:
import [Link].*;
import [Link].*;
4
class test
{
void value(int h,int b)
{
[Link]("Area of Triangle:"+0.5*b*h);
}
void value(int a,int b,int c)
{
[Link]("Perimeter of triangle"+(a+b+c));
}
}
class triangle
{
public static void main(String args[])
{
String s;
try
{
test t=new test();
BufferedReader br=new
BufferedReader(new InputStreamReader([Link]));
[Link]("Enter breath and height value");
s=[Link]();
int b=[Link](s);
s=[Link]();
int h=[Link](s);
[Link](b,h);
5
[Link]("Enter a,b,c sides values:");
s=[Link]();
int a=[Link](s);
s=[Link]();
b=[Link](s);
s=[Link]();
int c=[Link](s);
[Link](a,b,c);
}
catch(Exception ie){}
}
}
OUTPUT:
EX NO:3
7
DATE:
Determining the Order of Numbers Generated Randomly Using
Random Class
Aim:
Procedure:
Coding:
8
import [Link].*;
public class rand
{
Random r=new Random();
int i,j;
int a[]=new int[10];
public void gen_no()
{
[Link]("\n\n\t Generated Random Number are...");
for(i=0;i<5;i++)
{
a[i]=[Link](20);
[Link]("\n\t"+a[i]);
}
}
public void sort()
{
int temp;
for(i=0;i<8;i++)
{
for(j=1;j<8-i;j++)
{
if(a[j-1]>a[j])
{
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}}}
public void show()
{
[Link]("\n\n\t Ascending Form");
[Link]("\n\n\t **************\n");
for(i=0;i<8;i++)
[Link]("\n\t"+a[i]);
[Link]("\n\n\t Descending Form");
[Link]("\n\n\t ***************\n");
for(i=7;i>=0;i--)
[Link]("\n\t"+a[i]);
}
public static void main(String args[])
{
[Link]("\n Ordering Number using random class");
rand r1=new rand();
r1.gen_no();
[Link]();
[Link]();
}
}
10
OUTPUT:
11
EX NO 4
DATE:
Usage of Calendar Class and Manipulation
Aim:
Procedure:
12
Coding:
import [Link].*;
class calendardemo
{
public static void main(String args[])
{
String
months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Jul","Aug","Sep","Oct","Nov","Dec
"};
[Link]("\n\t\t Implementation of calender class");
[Link]("\n\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Calendar c=[Link]();
GregorianCalendar gc=new GregorianCalendar();
[Link]("\n\t Date-->");
[Link](months[[Link]([Link])]);
[Link]("-"+[Link]([Link]));
[Link]("-"+[Link]([Link]));
[Link]("\n\n\t Time-->");
[Link]([Link]([Link])+":");
[Link]([Link]([Link])+":");
[Link]([Link]([Link]));
if([Link]([Link]([Link])))
[Link]("\n\n\t"+[Link]([Link])+"Is a Leap year");
else
[Link]("\n\n\t"+[Link]([Link])+"Is not a Leap year");
}
}
Output:
13
14
EX NO: 5
DATE:
String Manipulation using Character Array
Aim:
Procedure:
15
Coding:
import [Link].*;
import [Link].*;
class stringcompare
{
public static void main(String arg[])throws IOException
{
String s=new String();
char chars[];
char vowels[]={'a','e','i','o','u','A','E','I','O','U'};
int v=0,n=0,sp=0;
[Link]("String Manipulation Using Character Array");
[Link]("*****************************************");
[Link]("Enter the String");
InputStreamReader in=new InputStreamReader([Link]);
BufferedReader br=new BufferedReader(in);
s=[Link]();
[Link](s);
chars=[Link]();
for(int j=0;j<[Link]();j++)
{
if((chars[j]>47)&&(chars[j]<58))
n++;
else
if(((chars[j]>=65)&&(chars[j]<95))||((chars[j]>95)&&(chars[j]<122)))
{
for(int k=0;k<10;k++)
{
if(chars[j]==vowels[k])
v++;
}
}
else
sp++;
}
[Link]("\n\n Vowels"+v);
[Link]("\n\n Digits"+n);
[Link]("\n\n Special character"+sp);
}}
16
Output:
17
EX NO:6
DATE:
Usage Of Vector Class
Aim:
Procedure:
18
Coding:
import [Link].*;
import [Link].*;
class vectordemo
{
public static void main(String fr[])throws IOException
{
Vector vec=new Vector();
int n,i,j,k,pos=0,s;
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("\n\n\t\t Implementation of vector class");
[Link]("\n\t\t*********************************");
[Link]("\n\n\t Enter the [Link] elements:");
n=[Link]([Link]());
for(i=0;i<n;i++)
{
[Link]("\n\n\t Enter the #"+(i+1)+"elements:");
k=[Link]([Link]());
[Link](new Integer(k));
}
[Link]("\n\n\t Displaying the vector:"+vec);
[Link]("\n\t First Element in the vector:"+[Link]());
[Link]("\n\t Last Element in the vector:"+[Link]());
[Link]("\n\t Enter the element to be inserted:");
s=[Link]([Link]());
[Link]("\n\t Enter the position to be inserted:");
pos=[Link]([Link]());
[Link](new Integer(s),pos-1);
[Link]("\n\t Displaying vector after insertion:"+vec);
[Link]("\n\t Enter the position to remove:");
pos=[Link]([Link]());
[Link](pos-1);
[Link]("\n\t Vector after removal:"+vec);
[Link]("\n Displaying using Enumeration...");
Enumeration e=[Link]();
while([Link]())
[Link]("\n\t\t\t"+[Link]());
}
}
19
Output:
20
EX NO: 7
Interface And Package
DATE:
Aim:
Procedure:
21
Coding:
Impinp package
import [Link].*;
import pack.*;
class impinp extends student implements marks
{
int m1,m2,m3,tot;
public void gets(int no1,int no2,int no3)
{
m1=no1;
m2=no2;
m3=no3;
tot=no1+no2+no3;
}
public void view()
{
[Link]("\n\n\t Mark 1="+m1);
[Link]("\n\n\t Mark 2="+m2);
[Link]("\n\n\t Mark 3="+m3);
[Link]("\n\n\t Total="+tot);
}
public static void main(String args[])throws IOException
{
[Link]("\t\t\t Interfaces And Package");
[Link]("\t\t\t*****************");
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("\n Enter the Student Number: ");
int no=[Link]([Link]());
[Link]("\n Enter the Student name: ");
String name=[Link]();
[Link]("\n\t Enter the mark 1:");
int m1=[Link]([Link]());
[Link]("\n\t Enter the mark 2:");
int m2=[Link]([Link]());
[Link]("\n\t Enter the mark 3:");
int m3=[Link]([Link]());
impinp imp=new impinp();
[Link](no,name);
[Link]();
[Link](m1,m2,m3);
[Link]();
}}
Student pack
22
package pack;
public class student
{
int no;
String name;
public void get(int n,String s)
{
no=n;
name=s;
}
public void display()
{
[Link]("\n\t The Student number is: "+no);
[Link]("\n\t The Student name is: "+name);
}
public interface marks
{
public void gets(int no1,int no2,int no3);
public void view();
}
}
23
Output:
24
EX NO:9
DATE:
Implementing Thread Based Application and Exception Handling
Aim:
Procedure:
Coding:
25
import [Link].*;
class newthread implements Runnable
{
newthread()
{
Thread t=new Thread(this,"Demo Thread");
[Link]("Child:"+t);
[Link]();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
[Link]("\n\n\t Child:"+i);
[Link](500);
}
}
catch(InterruptedException i)
{
}
[Link]("\n\n\t Child is in exist");
}
}
class threaddemo
{
public static void main(String arg[])
{
new newthread();
try
{
for(int i=5;i>0;i--)
{
[Link]("\n\n\t Main:"+i);
[Link](100);
}
}
catch(InterruptedException i)
{
}
[Link]("\n\n\t Main is in exist");
}
}
26
Output:
27
EX NO: 9
DATE:
Application using Synchronization
Aim:
Procedure:
28
Coding;
import [Link].*;
class inventory
{
static int q=100,r=0;
static public synchronized void request(int order)
throws InterruptedException
{
for(int i=1;i<=3;i++)
{
[Link](300);
if(order<=q)
{
[Link]("\n\t Quantity Ordered:"+order);
q=q-order;
r=r+order;
[Link](" Quantity in hand:"+q);
[Link]("\n\t Total order taken:"+r);
}
else
{
[Link]("\n\t Ordered quantity more than in");
[Link]("hand");
}
order=((int)([Link]()*100));
}
}
public static void main(String args[ ]) throws InterruptedException
{
[Link]("\t\t\t APPLICATION USING");
[Link]("SYNCHRONIZATION");
[Link]("\t\t\t ......................................");
[Link](".");
new ourthread();
[Link](50);
[Link]((int)([Link]()*100));
[Link]("\n\t Existing from main thread...");
}
29
}
class ourthread extends Thread
{
ourthread()
{
super("Test thread");
[Link]("\n\t Child thread:"+this);
start();
}
public void run()
{
try
{
[Link]((int)([Link]()*100));
}
catch(InterruptedException e)
{
[Link]("\n\t"+e);
}
[Link]("\n\t Child thread existing");
}
}
Output:
30
EX NO: 10
31
DATE:
Electricity Bill Preparation
Aim:
Procedure:
Coding:
import [Link].*;
32
class Ebill{
public static void main(String args[]) throws IOException {
File f = new File("[Link]");
FileOutputStream fos = new FileOutputStream(f);
DataOutputStream dos = new DataOutputStream(fos);
BufferedReader br = new BufferedReader(new
InputStreamReader([Link]));
[Link]("Enter the current meter reading :");
String s = [Link]();
int cr =[Link](s);
[Link]("Enter the previous meter reading:");
s=[Link]();
int pr=[Link](s);
int tot = cr-pr;
double amount;
int i;
if(tot>=1000)
{ i=5;
amount = tot*i; }
else if(tot>=500 && tot<=999)
{ i=4;
amount = tot*i; }
else if(tot>=200 && tot <=499)
{ i=3;
amount=tot*i; }
else
{ i=2;
amount=tot*i; }
[Link](cr);
[Link](pr);
[Link](tot);
[Link](amount);
[Link]();
33
FileInputStream fis=new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
[Link]( "Current meter reading : "+ [Link]());
[Link]("Previous meter reading : "+[Link]());
[Link]("Total units charged : "+[Link]());
[Link]("Charges per Unit : "+ i);
[Link]("Total amount to be paid : "+[Link]());
[Link]();
[Link]();
}
}
Output:
34
35
EX NO: 11
Telephone Bill Preparation
DATE:
Aim:
Procdure:
Coding:
36
//Data File Creation for Telephone Billing
import [Link].*;
class TPbill
{
public static void main(String args[]) throws IOException
{
File f=new File("[Link]");
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dos=new DataOutputStream(fos);
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
String s;
[Link]("Enter the telephone no:");
s=[Link]();
int tel=[Link](s);
[Link]();
[Link]("Enter the total calls made:");
s=[Link]();
int tc=[Link](s);
[Link]();
int totf=100;
int tot=tc-totf;
double amount=0;
if(tot>=0)
amount=tot*1;
else
amount=50;
double sertax=amount*20/100;
[Link]("service tax="+sertax);
double tamt=amount+sertax;
[Link](tel);
[Link](tc);
[Link](totf);
[Link](tot);
[Link](amount);
[Link](sertax);
[Link](tamt);
[Link]();
37
FileInputStream fis=new FileInputStream(f);
DataInputStream dis=new DataInputStream(fis);
[Link]("\n Customer telephone Billing:");
[Link]("\n-----------------------------------");
[Link]("\n Telephone no :"+[Link]());
[Link]("\n No of calls made :"+[Link]());
[Link]("\n No of free calls :"+[Link]());
[Link]("\n No of calls to be charged :"+[Link]());
[Link]("\n Amount for total calls :"+[Link]());
[Link]("\n Service tax charge :"+[Link]());
[Link]("\n total amount to be paid :"+[Link]());
[Link]();
[Link]();
}
}
Output:
38
39
EX NO:14
EMAIL CREATION USING DATABASE
DATE:
Aim
Procedure:
Coding:
import [Link].*;
40
import [Link].*;
import [Link].*;
class inst
{
Connection con;
PreparedStatement ps;
Statement st;
ResultSet r;
int rs;
String str;
void inst1()
{
try
{
[Link]("[Link]");
con=[Link]("jdbc:odbc:Test");
Statement stm=[Link]();
}
catch(Exception e)
{
[Link]("\n\t Connection Error");
}
}
void addrec(int id,String str,int age,String emid)
throws SQLException
{
ps=[Link]("Insert into email values(?,?,?,?)");
[Link](1,id);
[Link](2,str);
[Link](3,age);
[Link](4,emid);
[Link]();
[Link]("\n\t Inserted");
[Link](true);
[Link]();
}
41
void update(int pid,String name,int age,String emid)
throws SQLException
{
st=[Link]();
String Upstring="Update e-mail set
name="+name+"Age="+age+"emid="+emid+"where id="+pid;
[Link](Upstring);
[Link](true);
[Link]("\n\t Record Updated");
[Link]();
}
void disp() throws SQLException
{
st=[Link]();
r=[Link]("Select*from Email");
[Link]("\n\t Id\n\n\t Age\n\n\t Email-id");
while([Link]())
{
[Link]([Link](1)+"\n\n\t"+[Link](2)
+"\n\n\t"+[Link](3)+"\n\n\t "+[Link](4));
}
[Link]();
[Link]();
[Link]();
}
void del(int pid) throws SQLException
{
st=[Link]();
[Link]("Delete from email where id="+pid+"");
[Link](true);
[Link]("\n\t Record Deleted");
[Link]();
}
}
class email
{
42
public static void main(String arg[ ])
throws IOException,SQLException
{
String s,name,emid;
int choice,pid,age;
inst i=new inst();
[Link]("\t\t\t DATABASE MANIPULATION");
[Link](\t\t\t ------------------------------------------);
BufferedReader br=new BufferedReader
(new InputStreamReader([Link]));
do
{
[Link]("\n\n\t\t 1. Insert");
[Link]("\n\n\t\t 2. Update");
[Link]("\n\n\t\t 3. Delete");
[Link]("\n\n\t\t 4. Display");
[Link]("\n\n\t\t 5. Exit");
[Link]("\n\n Enter your choice:");
s=[Link]();
choice=[Link](s);
switch(choice)
{
case 1:
{
i.inst1();
[Link]("\n\nt\t\t Enter the);
[Link](person" ID,Name,);
[Link](Age,Email ID:");
s=[Link]();
pid=[Link](s);
name=[Link]();
age=[Link](s);
emid=[Link]();
[Link](pid,name,age,emid);
break;
}
43
case 2:
{
i.inst1();
[Link]("\n\n\t\t Enter the);
[Link](personID to update:");
s=[Link]();
pid=[Link](s);
[Link]("\n\n\t\t Enter the);
[Link](person ID,Name,Age,);
[Link](Email ID:");
name=[Link]();
age=[Link](s);
emid=[Link]();
[Link](pid,name,age,emid);
break;
}
case 3:
{
i.inst1();
[Link]("\n\n\t\t Enter the);
[Link](person ID to delete);
[Link](records...");
s=[Link]();
pid=[Link](s);
[Link](pid);
}
case 4:
{
i.inst1();
[Link]();
break;
}
case 5:
[Link](\t ***END***);
break;
default:
44
[Link]("\n\t Invalid Selection");
}
}
while(choice!=5);
}
}
Output:
DATABASE MANIPULATION
45
-----------------------------------------
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. Exit
Enter your choice: 1
Enter the person ID, Name, Age, Email ID
2100
john
18
johnbca2011@[Link]
Inserted
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 1
Enter the person ID, Name, Age, Email ID
2101
gnp
19
freeknockout@[Link]
Inserted
1. INSERT
46
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 4
Id
Name Age
Email-Id
2100 john 18
johnbca2011@[Link]
2101 gnp
freeknockout@[Link]
19
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 3
Enter the person ID to delete records: 2100
Id
Name Age
2100 john 18
Email-Id
johnbca2011@[Link]
record deleted
1. INSERT
2. UPDATE
3. DELETE
4. DISPLAY
5. EXIT
Enter your choice: 5
***END***
47