0% found this document useful (0 votes)
100 views118 pages

Javalabprint 1

The Java games apps and other religions and modern day electricity bill for online registration number to online radio network marketing and YouTube Facebook Yahoo shopping mall Andheri Raat din por theke ami ki the house is located approximately two months that we would have had time a the Java Yes my resume to have a lot better that is what it means is located here and there will be available tomorrow afternoon of all ages that is my favourite part and including to boy I of the house a

Uploaded by

Sportz Maniàác
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views118 pages

Javalabprint 1

The Java games apps and other religions and modern day electricity bill for online registration number to online radio network marketing and YouTube Facebook Yahoo shopping mall Andheri Raat din por theke ami ki the house is located approximately two months that we would have had time a the Java Yes my resume to have a lot better that is what it means is located here and there will be available tomorrow afternoon of all ages that is my favourite part and including to boy I of the house a

Uploaded by

Sportz Maniàác
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 118

PROGRAM NO : 1

DATE :

AIM : Write a program to create a menu with the choices – factorial of a


number , check palindrome or not , Armstrong numbers in a
given range, number traingle by entering the limit, fibonacci series.

PROGRAM

import java.util.*;
class pgm1
{
public static void main(String args[])
{
int choice,y=1;
Scanner p=new Scanner(System.in);
do
{
System.out.println("\nEnter your choice\n 1.factorial of a number \n 2.check palindrome or not \n
3.armstrong number in a given range\n 4.number traingle by entering the limit\n 5.fibonacci
series\n\n");
choice=p.nextInt();
switch(choice)
{

case 1 :
int i,f=1,nk;
Scanner s=new Scanner(System.in);
System.out.println("Enter the number");
nk=s.nextInt();
for(i=1;i<=nk;i++)
{
f=f*i;
}
System.out.println("factorial is:\n"+f);
break;

case 2:
int r,su=0,t,n;
Scanner ss=new Scanner(System.in);
System.out.println("Enter the number");
n=ss.nextInt();
t=n;
while(n!=0)
{
r=n%10;
su=(su*10)+r;
n=n/10;
}
if(t==su)
System.out.println("the number is palindrome");
else
System.out.println("the number is not palindrome");
break;

case 3:
int rem,sum,temp,beg,end,iu;
Scanner sh=new Scanner(System.in);
System.out.println("enter starting no:");
beg=sh.nextInt();
System.out.println("enter ending no :");
end=sh.nextInt();
for(iu=beg;iu<=end;iu++)
{
temp=iu;
rem=0;
sum=0;
while(temp!=0)
{
rem=temp%10;
sum=sum+rem*rem*rem;
temp=temp/10;
}
if(iu==sum)
{
System.out.println(""+sum);
}
}
break;

case 4:
int ii,jj,nj;
Scanner sg=new Scanner(System.in);
System.out.print("enter the limit:");
nj=sg.nextInt();
for(ii=1;ii<=nj;ii++)
{
for(jj=1;jj<=ii;jj++)
{
System.out.print(jj+ " ");
}
System.out.print("\n");
}
break;

case 5:
int a=0,b=1,cc,nn;
Scanner sss=new Scanner(System.in);
System.out.println("enter the limit:");
nn=sss.nextInt();
System.out.println("\n"+a+ "\n" +b);
for(int ih=0;ih<nn-2;ih++)
{
cc=a+b;
a=b;
b=cc;
System.out.println(" " +cc);
}
System.out.println("\n");
break;

default:System.out.println("\n invalid choice\n");


}
System.out.println("do you want to continue?\t 1.yes \t 2.no");
y=p.nextInt();
}
while(y!=2);
}
}

OUTPUT

user@user-H310M-S2-2-0:~$ telnet 192.168.101.200


Trying 192.168.101.200...
Connected to 192.168.101.200.
Escape character is '^]'.
CentOS release 6.7 (Final)
Kernel 2.6.32-573.8.1.el6.i686 on an i686
login: 18rmca13
Password:
Last login: Mon Jan 1 08:57:22 from 192.168.101.22
[18rmca13@mcalab ~]$ cd sem3
[18rmca13@mcalab sem3]$ cd javaorg
[18rmca13@mcalab javaorg]$ javac pgm1.java
[18rmca13@mcalab javaorg]$ java pgm1

Enter your choice


1.factorial of a number
2.check palindrome or not
3.armstrong number in a given range
4.number traingle by entering the limit
5.fibonacci series

1
Enter the number
2
factorial is:
2
do you want to continue? 1.yes 2.no
1

Enter your choice


1.factorial of a number
2.check palindrome or not
3.armstrong number in a given range
4.number traingle by entering the limit
5.fibonacci series

2
Enter the number
212
the number is palindrome
do you want to continue? 1.yes 2.no
1

Enter your choice


1.factorial of a number
2.check palindrome or not
3.armstrong number in a given range
4.number traingle by entering the limit
5.fibonacci series

3
enter starting no:
1
enter ending no :
10
1
do you want to continue? 1.yes 2.no
1

Enter your choice


1.factorial of a number
2.check palindrome or not
3.armstrong number in a given range
4.number traingle by entering the limit
5.fibonacci series

4
enter the limit:5
1
12
123
1234
12345
do you want to continue? 1.yes 2.no
1

Enter your choice


1.factorial of a number
2.check palindrome or not
3.armstrong number in a given range
4.number traingle by entering the limit
5.fibonacci series

5
enter the limit:
20

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181

do you want to continue? 1.yes 2.no


PROGRAM NO : 2
DATE :

AIM : Write a program to create a menu with the choices – matrix


addition , matrix multiplication,trace of matrix(the sum of the
elements on the main diagonal) and symmetric or not

PROGRAM

import java.util.*;
class Pgm2
{
public static void main(String sr[])
{
int a[][]=new int[10][10];
int b[][]=new int[10][10];
int c[][]=new int[10][10];
int d[][]=new int[10][10];
int i,j,n,temp,num,m,ch,k,sum=0;
int v=0;
Scanner s=new Scanner(System.in);
System.out.println("enter the row size");
n=s.nextInt();
System.out.println("enter the column size");
m=s.nextInt();
System.out.println("enter the first matrix");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
a[i][j]=s.nextInt();
}
}
System.out.println("elements are");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(+a[i][j]+"\t");
}
System.out.print("\n");
}
System.out.println("enter the second matrix");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[i][j]=s.nextInt();
}
}
System.out.println("elements are");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(+b[i][j]+"\t");
}
System.out.print("\n");
}
do
{
System.out.println("\n enter your choice");
System.out.println("1.matrix addition \n 2.matrix multiplication \n 3.trace of matrix \n 4.symmetric
or not \n 5.Exit");

ch=s.nextInt();
switch(ch)
{
case 1:
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("after addition");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(+c[i][j]+"\t");
}
System.out.print("\n");
}
break;
case 2:
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
d[i][j]=d[i][j]+(a[i][k]*b[k][j]);
}
}
System.out.println("after multipilicaton");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(+d[i][j]+"\t");
}
System.out.print("\n");
}
break;
case 3:
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(i==j)
{
sum=sum+a[i][j];
}
}

}
System.out.print("trace of matrix" +sum);
break;
case 4:
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[j][i]=a[i][j];
}
}
System.out.println("transpose of the matrix");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(+b[i][j]+"\t");
}
System.out.print("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=b[i][j])
{

v=2;
System.out.println(v);
break;
}

}
}
if(v==2)
{
System.out.println("matrix is not symmetric");
}
else
{
System.out.println("matrix is symmetric");
}

break;

}
}while(ch!=5);
}
}

OUTPUT
user@user-H310M-S2-2-0:~$ telnet 192.168.101.200
Trying 192.168.101.200...
Connected to 192.168.101.200.
Escape character is '^]'.
CentOS release 6.7 (Final)
Kernel 2.6.32-573.8.1.el6.i686 on an i686
login: 18rmca13
Password:
Last login: Mon Jan 1 09:17:03 from 192.168.101.22
[18rmca13@mcalab ~]$ cd sem3
[18rmca13@mcalab sem3]$ cd javaorg
[18rmca13@mcalab javaorg]$ javac pgm2.java
[18rmca13@mcalab javaorg]$ java Pgm2
enter the row size
2
enter the column size
2
enter the first matrix
2
6
5
4
elements are
2 6
5 4
enter the second matrix
8
9
3
8
elements are
8 9
3 8

enter your choice


1.matrix addition
2.matrix multiplication
3.trace of matrix
4.symmetric or not
5.Exit
1
after addition
10 15
8 12

enter your choice


1.matrix addition
2.matrix multiplication
3.trace of matrix
4.symmetric or not
5.Exit
2
after multipilicaton
34 66
52 77

enter your choice


1.matrix addition
2.matrix multiplication
3.trace of matrix
4.symmetric or not
5.Exit
3
trace of matrix6
enter your choice
1.matrix addition
2.matrix multiplication
3.trace of matrix
4.symmetric or not
5.Exit
4
transpose of the matrix
2 5
6 4
2
2
matrix is not symmetric

enter your choice


1.matrix addition
2.matrix multiplication
3.trace of matrix
4.symmetric or not
5.Exit
PROGRAM NO : 3
DATE :

AIM : Write a program to sort the elements of an array by entering


values from the key-board and also find out the largest and
smallest element from a two dimensional array

PROGRAM

import java.io.*;
import java.util.Scanner;
class maxminsort
{
public static void main(String arg[])
{
int i,j,temp,n;
int a[]=new int[10];
int max=a[0];
int min=a[0];
Scanner s=new Scanner(System.in);
System.out.println("Enter the limit:");
n=s.nextInt();
System.out.println("Enter the eles:");
for(i=1;i<=n;i++)
{
a[i]=s.nextInt();
}
System.out.println("Array eles are:");
for(i=1;i<=n;i++)
{
System.out.println(a[i]);
}
System.out.println("Sorted array is=");
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=1;i<=n;i++)
{
System.out.println(a[i]);
}
//System.out.println(a[1]);
for (i=1;i<=n; i++)

{
if (a[i] > max)
{
max = a[i];
}
if (a[i] < min)
{
min = a[i];
}
}
System.out.println("Largest Number in a given array is : " + max);
System.out.println("Smallest Number in a given array is : " + a[1]);
}
}

OUTPUT
PROGRAM NO : 4
DATE :

AIM : Find the factorial of a number using recursion.

PROGRAM

//factorial of a number using recursion


import java.util.Scanner;
class factrec
{
public static void main(String args[])
{
System.out.println("Enter the number:");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
int factorial = fact(num);
System.out.println("Factorial of a number is: "+factorial);
}
static int fact(int n)
{
int result;
if(n==1)
{
return 1;
}
result = fact(n-1)* n;
return result;
}
}

OUTPUT
PROGRAM NO : 5
DATE :

AIM : Implement string handling functions (String class and StringBuffer class)

PROGRAM

import java.io.*;
import java.util.*;
class StringPgm
{
public static void main(String args[])
{
String a,b;
char cs,cr,r;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first string");
a=sc.nextLine();
System.out.println("The String is "+a);

System.out.println("String Functions");

System.out.println("----------------");

System.out.println("Length of the String "+a+" is "+a.length());

System.out.println("The character at the fifth position of "+a+ " is " +a.charAt(5));


System.out.println("Enter The String To Compare");
b=sc.nextLine();
if(a.equals(b))
System.out.println("Strings Are Equal When equals method is used");
else
System.out.println("Strings Are Not Equal When equals method is used");
if(a==b)
System.out.println("Strings Are Equal When == is used");
else
System.out.println("Strings Are Not Equal When == is used");
int c = a.compareTo(b);
System.out.println( a+" and "+b+" Comparison gives "+c);
System.out.println("Enter The Character To Search");
cs=sc.next().charAt(0);
System.out.println("Found "+cs+" at the " +a.indexOf(cs)+" position of "+a);
System.out.println("Enter the character to be replace");
r=sc.next().charAt(0);
System.out.println("Enter the character to replace");
cr=sc.next().charAt(0);
System.out.println("replace " +r+" with "+cr+" gives "+a.replace(r,cr));

StringBuffer s=new StringBuffer(a);


System.out.println("Reverse of "+a+" is "+s.reverse());
System.out.println("Substring "+s.substring(2,5));
System.out.println("Appending Hai gives "+s.append("hai"));
System.out.println("Inserting for at 5th Position "+s.insert(5, "for"));
System.out.println("Deleting 7th character "+s.deleteCharAt(7));
}
}

OUTPUT
PROGRAM NO : 6
DATE :

AIM : Implement static blocks and static methods.

PROGRAM

import java.util.*;
class staticmain
{
static int a,b,c;
static
{
System.out.println("inside static block");
int x=5;
int y=2;
System.out.println("the value of x and y is:"+x+" "+y);
}
static void staticmeth(int a,int b)
{
System.out.println("inside static method");
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+(a+b));
}
}
public static void main(String arg[])
{
staticmeth(10,15);
}
}

OUTPUT
PROGRAM NO : 7
DATE :

AIM : Implement the use of


a) nested class
b)nested methods

PROGRAM

import java.util.*;
class C1
{
Scanner S=new Scanner(System.in);
int a=10;
int b=20;
int c=5;
int calculation()
{
System.out.println("a="+a+" "+"b="+b+" "+"c="+c);
int d=((a+b)*c);
return d;
}
void addition()
{
int f=calculation();
System.out.println("((a+b)*c)="+f);
int e=(a+b+c);
System.out.println("sum="+e);
C2 obj=new C2();
System.out.println("enter the value of p and q:");
double p=S.nextDouble();
double q=S.nextDouble();
obj.multiplication(p,q);
}
}
class C2
{
double p;
double q;
void multiplication(double x,double y)
{
p=x;
q=y;
System.out.println("p="+p+" "+"q="+q);
double r=p*q;
System.out.println(p+"*"+q+"="+r);
}
}
class nested
{
public static void main(String arg[])
{
C1 n=new C1();
n.addition();
}
}

OUTPUT
PROGRAM NO : 8
DATE :

AIM : Implement the use of Varargs method.

PROGRAM

import java.io.*;
import java.util.*;
class var
{
public static void main(String args[])
{

meth(10,20,30);
meth("Hilda",3,5,7);
}
static void meth(int ...a)
{
for(int x:a)
System.out.println(x);
}
static void meth(String c,int ...a)
{
System.out.println("\nName is " +c);
for(int x:a)
System.out.println(x);
}
}

OUTPUT
PROGRAM NO : 9
DATE :

AIM : Create a class Bank-Account with member variables-AcctNo,


CustomerName , account type, Balance and methods getDetails, deposit,
withdraw, displayDetails , without using constructors. Every account
must ensure a minimum balance. Get the details of n customers, perform
the bank transactions and display the details in tabular form.

PROGRAM

import java.util.*;
import java.io.*;
class BankAccount
{
Scanner sc= new Scanner(System.in);
int AcctNo;
String CustomerName;
String AccType;
float Balance,Amount;
void getDetails()
{
System.out.println("\nEnter Account Holders Name");
CustomerName=sc.nextLine();
System.out.println("\nEnter Account Type");
AccType=sc.nextLine();
System.out.println("\nEnter Account Number");
AcctNo=sc.nextInt();
System.out.println("\nEnter Amount");
Balance=sc.nextFloat();
}
void Deposit()
{
System.out.println("\nEnter The Amount to deposit");
Amount=sc.nextFloat();
}
void Withdraw()
{
System.out.println("\nEnter The Amount to withdraw");
Amount=sc.nextInt();
}
void Display()
{
System.out.print("\n");
System.out.println("Name : "+CustomerName);
System.out.println("Account Type : "+AccType);
System.out.println("Account Number : "+AcctNo);
System.out.println("Account Balance: "+Balance);
}
}
class Account
{
public static void main(String args[])
{
int n,i,acno,damt,op;
float camt;
char ch;
Scanner sc= new Scanner(System.in);
System.out.println("\nBanking Automated System");
System.out.println("------------------------");
System.out.println("\nEnter the number of accounts needed");
n=sc.nextInt();
BankAccount[] BA =new BankAccount[n];
for(i=0;i<n;i++)
BA[i] = new BankAccount();
do
{
System.out.println("\nSelect choice \n1.Open Account\n2.Deposit\n3.Withdraw\n4.Account
Details");
op=sc.nextInt();
switch(op)
{
case 1:
for(i=0;i<n;i++)
BA[i].getDetails();
System.out.println("\nAccounts Added Successfully");
break;
case 2:
System.out.println("\nEnter the account number");
acno=sc.nextInt();
for(i=0;i<n;i++)
{
if (BA[i].AcctNo== acno)
{
System.out.println("\nEnter the amount to deposit");
damt=sc.nextInt();
BA[i].Balance=BA[i].Balance+damt;
System.out.println("\nBalance : "+BA[i].Balance);
}
}
break;
case 3:
System.out.println("\nEnter the account number");
acno=sc.nextInt();
for(i=0;i<n;i++)
{
if (BA[i].AcctNo== acno)
{
System.out.println("\nEnter the amount to withdraw");
damt=sc.nextInt();
camt=BA[i].Balance-damt;

if (camt<1000)
System.out.println("Amount Exceeded,required Minimum balance is 1000");
else
{
BA[i].Balance=BA[i].Balance-damt;
System.out.println("\nBalance : "+BA[i].Balance);
}
}
}
break;
case 4:
System.out.println("\nEnter the account number");
acno=sc.nextInt();
for(i=0;i<n;i++)
{
if (BA[i].AcctNo== acno)
{
BA[i].Display();
System.out.print("\n");
}
}
break;
default:
System.out.println("\nInvalid Operation");
}
System.out.println("\nDo you want to continue(Y/N)?");
ch=sc.next().charAt(0);
System.out.println("------------------------");
}
while(ch=='Y'|| ch=='y');
}
}
OUTPUT
PROGRAM NO : 10
DATE :

AIM : Implement the above program using constructors.

PROGRAM

import java.util.*;
import java.io.*;
class Bank
{
Bank(double AcctNo,String CustomerName,String accounttype)
{
System.out.println("Account number : "+AcctNo+" Customer Name : "+CustomerName+" Account
Type : "+accounttype);
}
Bank(String accounttype,double Balance)
{
System.out.println(" Account Type : "+accounttype+" Balance "+Balance);
}
Bank(double AcctNo,double Balance)
{
System.out.println("Account number : "+AcctNo+" Balance "+Balance);
}
Bank(double AcctNo,String CustomerName,String accounttype,double Balance)
{
System.out.println("Account number\tCustomer Name\ttype\t\tAmount");
System.out.println(+AcctNo+"\t\t"+CustomerName+"\t\t"+accounttype+"\t\t"+Balance);
}
}
class ConstructorAccount
{
public static void main(String arg[])
{
int AcctNo,Balance=100;
String CustomerName,accounttype;
int c;
char ch;
Scanner s=new Scanner(System.in);
System.out.println("Enter number of Accounts");
int n=s.nextInt();
Bank oj[]=new Bank[n];
for(int i=0;i<n;i++)
{
System.out.println("Get Details");
System.out.println("Enter the Account number:");
AcctNo=s.nextInt();
System.out.println("Enter Name:");
CustomerName=s.next();
System.out.println("Enter account type:");
accounttype=s.next();

Bank obj1=new Bank(AcctNo,CustomerName,accounttype);


do
{
System.out.println("To \n1.Deposit\n2.Withdraw\n3.Display Details");
c=s.nextInt();
switch(c)
{
case 1:System.out.println("Deposit");
System.out.println("Enter amount to deposit");
Balance=s.nextInt();
Bank obj2=new Bank(accounttype,Balance);
break;
case 2:System.out.println("Withdraw");
if(Balance>100)
{
System.out.println("Enter amount for withdrawel");
int acw=s.nextInt();
Balance=Balance-acw;
System.out.println("Balance is:"+Balance);
}
else
{
System.out.println("Withdrawel is not possible");
}
Bank obj3=new Bank(AcctNo,Balance);
break;
case 3:System.out.println("Display Details");
Bank obj4=new Bank(AcctNo,CustomerName,accounttype,Balance);
break;
}
System.out.println("Do you want to countinue");
ch=s.next().charAt(0);
}while(ch=='y'||ch=='Y');
}
}
}
OUTPUT
PROGRAM NO : 11
DATE :

AIM : Implement the polymorphism concept : Overload the method volume that
returns volume of different shapes. The method is to be overloaded with
one parameter,2 parameters and 3 parameters and the parameters must
accept fractional values. Calculate the volume of at least 3 different
shapes.

PROGRAM

import java.util.*;
class Area
{
double a,b,c;
double shape(double x)
{
a=x;
return (a*a*a);
}
double shape(double x,double y,double z)
{
a=x;
b=y;
c=z;
return (a*b*c);
}
double shape(double x,double y)
{
a=x;
b=y;
return (3.14*(a*a)*b);
}
}
class shapeover
{
public static void main(String ag[])
{
double m,n,o;
Scanner s=new Scanner(System.in);
Area obj=new Area();
System.out.println("Enter length of square ");
m=s.nextDouble();
System.out.println("Volume of square is "+obj.shape(m));
System.out.println("Enter length,height and breadth of rectangle prism ");
m=s.nextDouble();
n=s.nextDouble();
o=s.nextDouble();
System.out.println("Volume of rectangular prism is "+obj.shape(m,n,o));
System.out.println("Enter radius and height of cylinder ");
m=s.nextDouble();
n=s.nextDouble();
System.out.println("Volume of cylinder is "+obj.shape(m,n));
}
}

OUTPUT
PROGRAM NO : 12
DATE :

AIM : Implement the use of this, return and final.

PROGRAM

import java.io.*;
import java.util.*;
class sample
{
int x;
int y;
final int z=10;
int mul=0;
sample(int x, int y)
{
this.x = x;
this.y = y;
}
void display()
{
System.out.println("Value of Z :"+z);

}
int multiply(int x,int y)
{
mul= x * y;
return mul;
}
}
class mainfinal
{
public static void main(String args[])
{
int a,b;
Scanner s=new Scanner(System.in);
System.out.println("Enter a number :");
a=s.nextInt();
System.out.println("Enter second number :");
b=s.nextInt();
Final obj = new Final(a,b);
int result = obj.multiply(a,b);
System.out.println("Multiplication of two numbers :"+result);
obj.display();
}
}
OUTPUT
PROGRAM NO : 13
DATE :

AIM : Implement single, multi level and heirarchical inheritance.

PROGRAM

a.single inheritance

import java.util.Scanner;
class rectangle
{
int l,b;
void getarea()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the length");
l=s.nextInt();
System.out.println("Enter the breadth");
b=s.nextInt();
}
void calcarea()
{
System.out.println("area of rectangle="+(l*b));
}
}

class triangle extends rectangle


{
int b1,h;
double z;
void getarea2()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the breadth");
b1=s.nextInt();
System.out.println("Enter the height");
h=s.nextInt();
}
void calcarea2() {
z=(0.5*b1*h);
System.out.println("area of triangle="+z);
}
}
class singleinh
{
public static void main(String args[]) {
triangle t=new triangle();
t.getarea();
t.calcarea();
t.getarea2();
t.calcarea2();
}
}

OUTPUT
b.multi level inheritance

PROGRAM

import java.util.Scanner;
class student
{
int rollnumber;
String name;
void getdata()
{
Scanner s=new Scanner(System.in);
System.out.println("enter student name");
name=s.next();
System.out.println("enter rollnumber");
rollnumber=s.nextInt();
}
void putdata()
{
System.out.println("student name:"+name);
System.out.println("rollnumber:"+rollnumber);
}
}
class test extends student
{
int sub1,sub2;
void getmark()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the mark of statics");
sub1=s.nextInt();
System.out.println("enter the mark of computer");
sub2=s.nextInt();
}
void putmark()
{
System.out.println("mark obtained");
System.out.println("mark of statics="+sub1);
System.out.println("mark of computer="+sub2);
}
}
class result extends test
{
int total;
void display()
{
total=sub1+sub2;
System.out.println("total score="+total);
}
}
class multilevel
{
public static void main(String args[])
{
result obj=new result();
obj.getdata();
obj.getmark();
obj.putdata();
obj.putmark();
obj.display();
}
}

OUTPUT
c.heirarchical inheritance

PROGRAM

import java.util.Scanner;
class faculty
{
int id;
void accept()
{
Scanner s=new Scanner(System.in);
System.out.println("enter id");
id=s.nextInt();
}
void meth()
{
System.out.println("id:"+id);
}
}

class details extends faculty


{
String name,des;
int age;
void show()
{
Scanner s=new Scanner(System.in);
System.out.println("enter faculty name");
name=s.next();
System.out.println("enter the designation");
des=s.next();
System.out.println("enter the age");
age=s.nextInt();
}
void disp()
{
System.out.println("*****Details*****");
System.out.println("faculty name:"+name);
System.out.println("age:"+age);
System.out.println("Designation:"+des);
}
}
class salary extends faculty
{
int salary,hra,da,bonus,total;
void get()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the Salary");
salary=s.nextInt();
System.out.println("enter the HRA");

hra=s.nextInt();
System.out.println("enter the DA");
da=s.nextInt();
System.out.println("enter the Bonus");
bonus=s.nextInt();
total=salary+hra+da+bonus;
}
void put()
{
System.out.println("salary:"+salary);
System.out.println("HRA:"+hra);
System.out.println("DA:"+da);
System.out.println("BONUS:"+bonus);
System.out.println("TOTAL SALARY:"+total);
}
}
class hierchy
{
public static void main(String args[])
{
details d=new details();
d.accept();
d.show();
salary obj=new salary();
obj.get();
d.disp();
obj.put();
}
}
OUTPUT
PROGRAM NO : 14
DATE :

AIM : Create a class Cake with attributes flavor and rate. Inherit a class
'orderCake' with additional attributes weight and pricecalc() and
another class 'readymade cake' with additional attributes quantity
and pricecalc(). Implement the above program and display the details
in tabular form.

PROGRAM

import java.io.*;
import java.util.*;
class cake
{
String flavor;
int rate;
Scanner s=new Scanner(System.in);
void show()
{
System.out.println("****CAKE DETAILS****");
System.out.println("Enter the flavor of cake :");
flavor=s.next();
System.out.println("Enter the rate :");
rate=s.nextInt();
}
}
class ordercake extends cake
{
int weight,price;
void accept()
{
System.out.println("****ORDER CAKE****");
System.out.println("Enter the weight of cake:");
weight=s.nextInt();
}
void pricecalc()
{
price=weight*rate;
System.out.println("Flavor\t\t Rate\t\t Price");
System.out.println(""+flavor+"\t\t "+rate+ "\t\t"+price);
}
}
class readymadecake extends cake
{
int quantity,amount;
void get()
{
System.out.println("****READYMADE CAKE****");
System.out.println("Enter the quantity of cake:");
quantity=s.nextInt();
}
void pricecalc()
{
amount=quantity*rate;
System.out.println("Flavor\t\tRate\tPrice");
System.out.println(""+flavor+"\t\t "+rate+ "\t"+amount);
}
}
class cakes
{
public static void main(String args[])
{
ordercake obj=new ordercake();
obj.show();
obj.accept();
obj.pricecalc();
readymadecake obj1=new readymadecake();
obj1.show();
obj1.get();
obj1.pricecalc();
}
}
OUTPUT
PROGRAM NO : 15
DATE :

AIM : Create a class called Employee so that it contains member variables:


name (String), email (String), and gender (char of either 'm' or 'f')· A
constructor to initialize the name, email and gender with the given
values.Define get and set methods- setEmail(), getName(), getEmail(),
and getGender().(There are no setters for name and gender, as these
properties are not designed to be changed).Define another method
toString() method that returns "name (gender) at email", e.g., "John(m)
at [email protected]". Implement the concept of encapsulation.

PROGRAM

import java.util.*;
class Employee
{
Scanner sc =new Scanner(System.in);
private String name;
private String email;
private char gender;
Employee(String n,String m,char g)
{
name=n;
email=m;
gender=g;
}
void setName()
{
System.out.println("Enter the name");
name=sc.nextLine();
}
public String getName()
{
return name;
}
void setEmail()
{
System.out.println("Enter the mail");
email=sc.nextLine();
}
public String getEmail()
{
return email;
}
void setGender()
{
System.out.println("Enter the gender");
gender=sc.next().charAt(0);
}
public char getGender()
{
return gender;
}
void display()
{
System.out.println(name+"("+gender+") at "+email);
}
}
class encapsulation
{
public static void main(String args[])
{
Employee emp=new Employee("hildacleetus","[email protected]",'f');
emp.setName();
emp.setEmail();
emp.setGender();
System.out.println("Name :" +emp.getName());
System.out.println("Mail :" +emp.getEmail());
System.out.println("Gender :" +emp.getGender());
emp.display();
}
}

OUTPUT
PROGRAM NO : 16
DATE :

AIM : Create a class name Toys with two place holders area () and perimeter ().
By using the properties of the Toys class calculate the area and perimeter
of bus, ball and 3 sided toy.

PROGRAM

import java.io.*;
import java.util.*;
abstract class toy
{
abstract void area();
abstract void perimeter();
}
class bus extends toy
{
int l,b,area,perimeter;
void get()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the length,breadth of bus");
l=s.nextInt();
b=s.nextInt();
}
void area()
{
area=l*b;;
System.out.println("area of bus:"+area);
}
void perimeter()
{
perimeter=2*(l+b);
System.out.println("perimeter of bus:"+perimeter);
}
}
class ball extends toy
{
int r;
double area,perimeter;
void accept()
{
System.out.println("Enter the radius of ball");
Scanner s=new Scanner(System.in);
r=s.nextInt();
}

void area()
{
area=2*(3.14*r*r);
System.out.println("area of ball:"+area);
}
void perimeter()
{
perimeter=2*3.14*r;
System.out.println("perimeter of ball:"+perimeter);
}
}
class triangle extends toy
{
void area() {
int h,b,area;
System.out.println("Enter the height,breadth of triangle");
Scanner s=new Scanner(System.in);
h=s.nextInt();
b=s.nextInt();
area=(b*h)/2;
System.out.println("area of triangle:"+area);
}
void perimeter()
{
int a,b,c,perimeter;
System.out.println("Enter the sides of triangle");
Scanner s=new Scanner(System.in);
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
perimeter=a+b+c;
System.out.println("perimeter of triangle:"+perimeter);
}
}
class maintoy
{
public static void main(String arg[])
{
bus obj1=new bus();
obj1.get();
obj1.area();
obj1.perimeter();
ball obj2=new ball();
obj2.accept();
obj2.area();
obj2.perimeter();
triangle obj3=new triangle();
obj3.area();
obj3.perimeter();
}
}

OUTPUT
PROGRAM NO : 17
DATE :

AIM : Implement Dynamic method dispatch to calculate the volume of at least 3


different shapes.

PROGRAM

import java.io.*;
import java.util.Scanner;
class cylinder
{
int r,h,l,b;
Scanner s=new Scanner(System.in);
double volume;
void volume()
{
System.out.println("Enter the radius and height of cylinder:");
r=s.nextInt();
h=s.nextInt();
volume=3.14*r*r*h;
System.out.println("Volume of cylinder="+volume);
}
}
class prism extends cylinder
{
void volume()
{
super.volume();
System.out.println("Enter the length,breadth and height of prism:");
l=s.nextInt();
b=s.nextInt();
h=s.nextInt();
volume=l*b*h;
System.out.println("Volume of prism="+volume);
}
}
class square extends cylinder
{
void volume()
{
System.out.println("Enter the length of square:");
l=s.nextInt();
volume=l*l*l;
System.out.println("Volume of square="+volume);
}
}

class dispatch
{
public static void main(String arg[])
{
cylinder r;
prism p=new prism();
r=p;
r.volume();
square s=new square();
r=s;
r.volume();
}
}

OUTPUT
PROGRAM NO : 18
DATE :

AIM : Find the number of characters in each string that is passed as command
line argument and also find the total number of vowels in it.

PROGRAM

class arg1
{
public static void main(String args[])
{
int len;
char ch;
String s;
int count=0,vow=0;
for(int i=0;i<args.length;i++)
{
s=args[i];
len=s.length();
for(int j=0;j<len;j++)
{
count++;
{
ch = s.charAt(j);
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{
vow++;
}
}
}
System.out.println("*********************************");
System.out.println("String : "+s);
System.out.println("Vowels count : "+vow);
System.out.println("Character count : "+count);
System.out.println("*********************************");
}
}
}

OUTPUT
PROGRAM NO : 19
DATE :

AIM : Define one class that contains placeholders for getting the personal details
of employees(Name, DOB, Address,Blood Group etc). Create two
interfaces that contain methods for accepting professional
details(Designation, date of joining,salary etc) and loan details(Loan
type , loan A/C no,sanction date, sanction amount etc) . Implement
multiple inheritance and display all details of n employees.

PROGRAM

import java.io.*;
import java.util.*;
abstract class personaldetails
{
Scanner s=new Scanner(System.in);
abstract void details();
}
interface professsional
{
void dprofesssional();
}
interface loan
{
void dloan();
}
class employee extends personaldetails implements professsional,loan
{
String name,address,place,bloodgroup,Designation,Loan_type,dob,date_of_join,sanction_date;
int salary,loan_AC_no,sanction_amount;
void details()
{
System.out.println("Enter name of employee:");
name=s.next();
System.out.println("Enter address:");
address=s.next();
System.out.println("Enter DOB");
dob=s.next();
System.out.println("Enter place:");
place=s.next();
System.out.println("Enter blood group:");
bloodgroup=s.next();
}
public void dprofesssional() {
System.out.println("Enter Designation:");
Designation=s.next();
System.out.println("Enter date of joining:");
date_of_join=s.next();
System.out.println("Enter salary:");
salary=s.nextInt();

}
public void dloan()
{
System.out.println("Enter Loan_type:");
Loan_type=s.next();
System.out.println("Enter loan_A/C_no:");
loan_AC_no=s.nextInt();
System.out.println("Enter sanction_date:");
sanction_date=s.next();
System.out.println("Enter sanction_amount:");
sanction_amount=s.nextInt();
}
void display()
{
System.out.println("***EMPLOYEE DETAILS***");
System.out.println("Enter name of employee:"+name);
System.out.println("Enter house name: "+address);
System.out.println("Enter DOB: "+dob);
System.out.println("Enter place: "+place);
System.out.println("Enter blood group: "+bloodgroup);
System.out.println("Enter Designation: "+Designation);
System.out.println("Enter date of joining: "+date_of_join);
System.out.println("Enter salary: "+salary);

System.out.println("Enter Loan_type: "+Loan_type);


System.out.println("Enter loan_A/C_no: "+loan_AC_no);
System.out.println("Enter sanction_date: "+sanction_date);
System.out.println("Enter sanction_amount: "+sanction_amount);
}
}
class multiplile
{
public static void main(String arg[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number of Employees");
int n=s.nextInt();
for(int i=0;i<n;i++)
{
employee obj=new employee();
obj.details();
obj.dprofesssional();
obj.dloan();
obj.display();
}
}
}

OUTPUT
PROGRAM NO : 20
DATE :

AIM : Create a package student which contains personal and educational


details. Import this package and print the details of n students in tabular
form.

PROGRAM

package studentpkd;
import java.util.Scanner;
public class student
{
String name,addr,bl,gend,dob;
int age,rnum,m1,m2,m3,m4,m5,total;
float percent;
Scanner s = new Scanner(System.in);
public void personel()
{
System.out.println("<<<<<<PERSONAL DETAILS>>>>>");
System.out.println("\nEnter the name of student:");
name = s.next();
System.out.print("\nEnter the date of birth:");
dob=s.next();
System.out.print("\nEnter the gender:");
gend=s.next();
System.out.println("\nEnter Address of student");
addr= s.next();
System.out.print("\nEnter the blood group:");
bl=s.next();
}
public void edu()
{
System.out.println("<<<<<<EDUCATIONAL DETAILS>>>>>");
System.out.println("Enter the roll no.");
rnum = s.nextInt();
System.out.println(" Enter Mark Details....");
System.out.println("Enter English mark");
m1= s.nextInt();
System.out.println("Enter Java Mark");
m2=s.nextInt();
System.out.println("Enter Software engineering mark");
m3=s.nextInt();
System.out.println("Enter Accountancy mark");
m4=s.nextInt();
System.out.println("Enter Php mark");
m5=s.nextInt();
total= m1+m2+m3+m4+m5;
percent= (float)total/500*100;
}

public void disp()


{
System.out.print("NAME\t DOB \t\t GENDER ADDRESS\tBLOOD GROUP\n");
System.out.print("--------------------------------------------------------\n");
System.out.print(name+"\t" +dob +"\t" +gend +"\t"+addr+"\t"+bl+"\n");
System.out.print("--------------------------------------------------------");
}
public void display()
{
System.out.print("\n------------------------------------------------------");
System.out.print("\nROLL NO :|" +rnum);
System.out.print("\nEnglish :|" +m1);
System.out.print("\nJava :|" +m2);
System.out.print("\nSE :|" +m3);
System.out.print("\nAccountancy :|" +m4);
System.out.print("\nPhp :|" +m5);
System.out.print("\n-------------------------------------------------------\n");
System.out.print("\n TOTAL MARKS :|" +total);
System.out.print("\n PERCENTAGE :|" +percent);
System.out.print("\n-------------------------------------------------------\n");
}
}

import studentpkd.*;
import java.util.Scanner;
class prog20
{
public static void main(String a[])
{
Scanner s=new Scanner(System.in);
int n,i;
student obj[]=new student[5];
System.out.print("\nEnter the number of student:");
n=s.nextInt();
for(i=1;i<=n;i++) {
obj[i]=new student();
}
for(i=1;i<=n;i++) {
System.out.print("\n\t...Student"+i+"...\n");
obj[i].personel();
obj[i].edu();
}
for(i=1;i<=n;i++) {
System.out.print("\n\t...STUDENT"+i+"...\n");
System.out.print("\n\t...PERSONAL DETAILS...\n");
obj[i].disp();
System.out.print("\n\t...EDUCATIONAL DETAILS...\n");
obj[i].display();
}
}
}

OUTPUT
PROGRAM NO : 21
DATE :
AIM : Write a Java program to implement the following exceptions
a) Arithmetic Exception
b) ArrayIndexOutOfBounds Exception
c) NullPointer Exception
d) NumberFormat Exception
e) StringIndexOutOfBound Exception

PROGRAM

a) Arithmetic Exception

import java.util.Scanner;
class arithex
{
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
{
try {
int n1, n2=0;
System.out.println("Enter first number:");
n1=s.nextInt();
System.out.println("Enter second number:");
n2=s.nextInt();
int c=n1/n2;
System.out.println ("Result: "+c);
}
catch(ArithmeticException e) {
System.out.println ("Can't divide a number by 0"); }
}
}
}

OUTPUT

b) ArrayIndexOutOfBounds Exception

PROGRAM
import java.io.*;
import java.util.*;
class arrayex
{
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
try {
System.out.println("Enter the limit");
int n=s.nextInt();
int a[] = new int[n];
System.out.println("Enter the elements");
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
}
System.out.println("Enter a position");
int pos=s.nextInt();
System.out.println(a[pos]);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println ("Array Index is Out Of Bounds"); }
}
}

OUTPUT

c) NullPointer Exception

PROGRAM
class nullpointex
{
public static void main(String args[])
{
try
{
String a = null;
System.out.println(a.charAt(0));
}
catch(NullPointerException e)
{
System.out.println("NullPointerException..");
}
}
}

OUTPUT

d) NumberFormat Exception

PROGRAM
import java.io.*;
import java.util.*;
class numberex
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
try {
System.out.println("Enter a value");
String str=s.next();
int num = Integer.parseInt (str) ;

System.out.println(num);
} catch(NumberFormatException e) {
System.out.println("Number format exception");
}
}
}

OUTPUT

e) StringIndexOutOfBound Exception
PROGRAM

import java.util.Scanner;
class stringex
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
{
try
{
String str=" ";
System.out.println("Enter a string:");
str=s.next();
System.out.println("String length:" +str.length());;
char c = str.charAt(0);
c = str.charAt(10);
System.out.println(c);
}
catch(StringIndexOutOfBoundsException e)
{
System.out.println("StringIndexOutOfBoundsException!!");
}
}
}
}

OUTPUT

PROGRAM NO : 22
DATE :
AIM : Create an user defined exception
A) To check whether the number is positive or negative
B) To add 2 numbers and if the result is less than 20 , raise an exception

PROGRAM

A) To check whether the number is positive or negative

import java.util.Scanner;
import java.io.IOException;
import java.io.InputStreamReader;
class MyException extends Exception
{
public MyException(String str)
{
System.out.println(str);
}
}
class userd
{
public static void main(String[] args)
throws IOException
{
Scanner s = new Scanner(System.in);
System.out.print("Input number : ");
try {
int num = s.nextInt();
if(num < 0)
throw new MyException("Number is negative");
else
throw new MyException("Number is positive");
}
catch (MyException m) {
System.out.println(m);
}
}
}

OUTPUT
B) To add 2 numbers and if the result is less than 20 , raise an exception
PROGRAM

import java.util.Scanner;
import java.io.IOException;
class MyException extends Exception
{
public MyException(String str)
{
System.out.println(str);
}
}
class useradd
{
public static void main(String[] args)
throws IOException
{
Scanner s = new Scanner(System.in);
try {
System.out.println("First number : ");
int a = s.nextInt();
System.out.println("Second number : ");
int b = s.nextInt();
int num = a+b;
System.out.println("Sum is:"+num);
if(num < 20)
throw new MyException("sum of numbers less than 20");
}
catch (MyException e) {
System.out.println(e);
}
}
}

OUTPUT

PROGRAM NO : 23
DATE :
AIM : Create multiple threads and use all possible methods associated with
Threads. (is Alive(),yield(),start(),sleep(),stop()).

PROGRAM

class A extends Thread


{
public void run()
{
for (int i =1; i<=4; i++)
{
if(i==3)
yield();
System.out.println("\t From ThreadA : i = " + i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run() {
for (int j =1; j<=4; j++)
{
if(j==3) stop();
System.out.println("\t From ThreadB : j = " + j);
}
System.out.println("Exit from B");
}
}
class C extends Thread
{
public void run()
{
for (int k=1; k<=4; k++)
{
if(k==1)
try
{
sleep(2000);
}
catch(Exception e)
{
}
System.out.println("\t From ThreadC: k= " + k);
}
System.out.println("Exit from C");
}}

class thread
{
public static void main (String args[])
{
A a=new A();
System.out.println("Start A");
a.start();
B b=new B();
System.out.println("Start B");
b.start();
C c=new C();
System.out.println("Start C");
c.start();
System.out.println("Thread A is:"+a.isAlive());
System.out.println("Thread B is:"+b.isAlive());
System.out.println("Thread C is:"+c.isAlive());
}
}

OUTPUT

PROGRAM NO : 24
DATE :

AIM : Illustrate the use of synchronized keyword.

PROGRAM

class pyramid
{
synchronized void draw(char ch)
{
for (int i=0;i<10;i+=2)
{
for (int k=10-i;k>0;k-=2)
{
System.out.print(" ");
}
for (int j=0;j<=i;j++)
{
System.out.print(ch);
}
System.out.println();
}
}
}
class A extends Thread
{
pyramid p;
A(pyramid p)
{
this.p=p;
}
public void run()
{
p.draw('*');
}
}
class B extends Thread
{
pyramid p;
B(pyramid p)
{
this.p=p;
}
public void run()
{
p.draw('#');
}
}

class synch24
{
public static void main(String args[])
{
pyramid obj=new pyramid();
A ThreadA= new A(obj);
B ThreadB= new B(obj);
ThreadA.start();
ThreadB.start();
}
}

OUTPUT
PROGRAM NO : 25
DATE :

AIM : Perform some file operations and also perform read the content of a file
and write it to another file. After writing , insert some more contents to
the file and copy to another file.

PROGRAM

import java.io.*;
class fileop
{
public static void main(String s[])throws IOException
{
System.out.print("\nCreating file....");
DataInputStream din=new DataInputStream(System.in);
FileOutputStream fout=new FileOutputStream ("myfile.txt");
System.out.println("press # to quit the file");
char ch;
while((ch=(char)din.read())!='#')
fout.write(ch);
fout.close();
System.out.print("\nReading a file....");
FileInputStream fin = new FileInputStream("myfile.txt");
System.out.println("\nTotal file size readed (in bytes) : " + fin.available());
int content;
while ((content = fin.read()) != -1)
{
System.out.print((char) content);
}
System.out.print("\nCopying file...");
int c;
FileInputStream finp=new FileInputStream ("myfile.txt");
FileOutputStream foutp=new FileOutputStream("myfile1.txt");
while((c=finp.read())!=-1)
foutp.write((char)c);
foutp.close();
System.out.print("\nCopied successfully !");
System.out.print("\nAppending file....");
DataInputStream dinp=new DataInputStream(System.in);
FileOutputStream foutpu=new FileOutputStream ("myfile.txt",true);
System.out.println("press $ to quit the file");
char chh;
while((chh=(char)dinp.read())!='$')
foutpu.write(chh);
foutpu.close();
System.out.print("\nAfter appending....");
FileInputStream fp = new FileInputStream("myfile.txt");
System.out.println("\nTotal file size readed (in bytes) : " + fp.available());
while ((content = fp.read()) != -1)
{
System.out.print((char) content);
}
System.out.print("\n");
}}

OUTPUT

PROGRAM NO : 27
DATE :

AIM : Using applet, draw


a. Olympic symbol
b. Rainbow
c. Vehicle
d.Polygon with 6 corners
e.Display greeting card that contains an image.
f.Display messages in applet window using 4 different fonts
[ The above applet diagrams must contain all the graphics shapes]

PROGRAM

a. Olympic symbol

import java.applet.*;
import java.awt.*;
/*<applet code="pgm27A.java" width=500 height=400>
</applet>*/
public class pfm27A extends Applet
{
public void paint(Graphics g) {
g.setColor(Color.blue);
g.drawOval(30,40,80,80);
g.setColor(Color.yellow);
g.drawOval(75,80,80,80);
g.setColor(Color.black);
g.drawOval(120,40,80,80);
g.setColor(Color.green);
g.drawOval(165,80,80,80);
g.setColor(Color.red);
g.drawOval(210,40,80,80);
}}

OUTPUT
b. Rainbow

PROGRAM

import java.awt.*;
import java.applet.*;
/*<applet code="pgm27B.java" height=500 width=700>
</applet>*/
public class pgm27B extends Applet
{
public void init()
{
setSize(250,250);
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillArc(250,200,250,250,0,180);

g.setColor(Color.green);
g.fillArc(260,210,230,230,0,180);

g.setColor(Color.red);
g.fillArc(270,220,210,210,0,180);

g.setColor(Color.black);
g.fillArc(280,230,190,190,0,180);

g.setColor(Color.yellow);
g.fillArc(290,240,170,170,0,180);

g.setColor(Color.red);
g.fillArc(300,250,150,150,0,180);

g.setColor(Color.black);
g.fillArc(310,260,130,130,0,180);

g.setColor(Color.white);
g.fillArc(320,270,110,110,0,180);
}
}
OUTPUT
c. Vehicle

PROGRAM

import java.awt.*;
import java.applet.*;
/*<applet code="pgm27C.java" width=500 height=300 ></applet>*/
public class pgm27C extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillRoundRect(100,100,200,70,10,10);
g.setColor(Color.red);
g.fillArc(100,100,100,100,0,180);
g.setColor(Color.black);
g.fillRoundRect(185,60,50,50,10,10);
g.setColor(Color.black);
g.fillOval(125,150,50,50);
g.setColor(Color.black);
g.fillOval(130,157,40,40);
g.setColor(Color.black);
g.fillOval(225,150,50,50);
g.setColor(Color.black);
g.fillOval(230,157,40,40);
}
}

OUTPUT
d.Polygon with 6 corners

PROGRAM

import java.applet.*;
import java.awt.*;
/*<applet code="pgm27D.java" width=350 height=350>
</applet>*/
public class pgm27D extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
int x[]={50,100,125,100,50,25};
int y[]={50,50,100,150,150,100};
int l=x.length;

g.fillPolygon(x,y,l);
}
}

OUTPUT
e.Display greeting card that contains an image

PROGRAM

import java.awt.*;
import java.applet.*;

/*<applet code="pgm27E.java" height=400 width=400>


</applet> */
public class pgm27E extends Applet {

Image picture;

public void init() {


setBackground(Color.red);
picture = getImage(getDocumentBase(),"flower.png");
}

public void paint(Graphics g) {

g.drawImage(picture, 30,30, this);


g.setColor(Color.blue);
g.drawString("…WISH YOU A HAPPY BIRTHDAY! ",50,350);
}

}
OUTPUT
f.Display messages in applet window using 4 different fonts

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.Font;
/*<applet code="pgm27F.java" height=500 width=300>
</applet>*/
public class pgm27F extends Applet
{
Font f1,f2,f3,f4;
public void init()
{
f1=new Font("Arial",Font.BOLD,18);
f2=new Font("TimesRoman",Font.PLAIN,20);
f3=new Font("Elephant",Font.ITALIC,30);
f4=new Font("Algebra",Font.BOLD,25);
}
public void paint(Graphics g)
{
g.drawString("radhika",50,50);
g.setFont(f1);
g.drawString("devika",50,80);
g.setFont(f2);
g.drawString("robina",50,140);
g.setFont(f3);
g.drawString("aishu",60,180);
g.setFont(f4);
}
}

OUTPUT
PROGRAM NO : 28
DATE :

AIM : Using applet, scroll a message from right to left across the applet’s
window.

PROGRAM

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/* <APPLET CODE=scrollingtext.java WIDTH=400 HEIGHT=200 > </APPLET> */
public class scrollingtext extends Applet implements Runnable
{
String msg="Welcome to uc college ";
Thread t=null;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
t=new Thread(this);
t.start();
}
public void run()
{
char ch;
for(; ;)
{
try
{
repaint();
Thread.sleep(400);
ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg+=ch;
}
catch(InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
g.drawString(msg,10,10);
}
}
OUTPUT
PROGRAM NO : 29
DATE :

AIM : Handle all mouse events using applet.

PROGRAM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="mouse.java" width=500 height=500></applet>*/
public class mouse extends Applet implements MouseListener,MouseMotionListener
{
String msg=" ";
int mouseX=0,mouseY=0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="Mouse clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="Mouse Exited";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
msg="Button Pressed";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
msg="Button Released";
repaint();
}
public void mouseDragged(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
msg="**";
showStatus("Dragging mouse at "+ mouseX + " , " +mouseY);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus(" Moving mouse at "+me.getX() + " ," +me.getY());
}
public void paint(Graphics g)
{
g.drawString(msg,mouseX,mouseY);
}
}

OUTPUT
PROGRAM NO : 30
DATE :

AIM : Handle window events and mouse events like mouse clicked and mouse
dragged with the help of adapter class.

PROGRAM

a)mouse clicked

import java.awt.*;
import java.awt.event.*;
public class madapter extends MouseAdapter{
Frame f;
madapter(){
f=new Frame("Mouse Adapter");
f.addMouseListener(this);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public void mouseClicked(MouseEvent e) {
Graphics g=f.getGraphics();
g.setColor(Color.RED);
g.fillOval(e.getX(),e.getY(),30,30);
//g.fillRect(e.getX(),e.getY(),60,50);
}
public static void main(String[] args) {
new madapter();
}
}

OUTPUT
PROGRAM

b) mouse dragged

import java.awt.*;
import java.awt.event.*;
public class mousemotion extends MouseMotionAdapter{
Frame f;
mousemotion(){
f=new Frame("Mouse Motion Adapter");
f.addMouseMotionListener(this);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public void mouseDragged(MouseEvent e) {
Graphics g=f.getGraphics();
g.setColor(Color.YELLOW);
g.fillOval(e.getX(),e.getY(),20,20);
}
public static void main(String[] args) {
new mousemotion();
}
}

OUTPUT
PROGRAM NO : 31
DATE :

AIM : Handle all key events using applet

PROGRAM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="key" width=300 height=400>
</applet>
*/
public class key extends Applet implements KeyListener
{
int X=20,Y=30;
String msg="KeyEvents--->";
public void init()
{
addKeyListener(this);
requestFocus();
setBackground(Color.green);
setForeground(Color.blue);
}
public void keyPressed(KeyEvent k)
{
showStatus("Key pressed");
int key=k.getKeyCode();
switch(key)
{
case KeyEvent.VK_UP:
showStatus("Move to Up");
break;
case KeyEvent.VK_DOWN:
showStatus("Move to Down");
break;
case KeyEvent.VK_LEFT:
showStatus("Move to Left");
break;
case KeyEvent.VK_RIGHT:
showStatus("Move to Right");
break;
}
repaint();
}
public void keyReleased(KeyEvent k)
{
showStatus("Key released");
}
public void keyTyped(KeyEvent k)
{
msg+=k.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,X,Y);
}
}

OUTPUT
PROGRAM NO : 32
DATE :

AIM : Using applet, play an audio file.

PROGRAM

import java.awt.*;
import java.applet.*;
import java.io.*;
/*<applet code="audio.java" height=500 width=500>
</applet>*/
public class audio extends Applet
{
AudioClip ac;
public void init()
{
ac=getAudioClip(getCodeBase(),"cello.wav");
}
public void start()
{
ac.play();
}

public void paint( Graphics g)


{
g.drawString("Music playing",100,100);
}
}

OUTPUT
PROGRAM NO : 33
DATE :

AIM : Without using buttons, enter 3 values in 3 textboxes and find the average
of these values by displaying the result in the applet window.

PROGRAM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="textbox.java" width=600 height=300>
</applet>*/
public class textbox extends Applet implements ActionListener
{
TextField t1 = new TextField(10);
TextField t2 = new TextField(10);
TextField t3 = new TextField(10);
TextField t4=new TextField(10);
Label l1 = new Label("First No=:");
Label l2 = new Label("Second No:");
Label l3=new Label("Third No:");
Label l4=new Label("AVERAGE:");
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
t4.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == t4)
{
int n1 = Integer.parseInt(t1.getText());
int n2 = Integer.parseInt(t2.getText());
int n3 = Integer.parseInt(t3.getText());
t4.setText(" " +((n1 + n2+n3)/3));
}}}
OUTPUT
PROGRAM NO : 34
DATE :

AIM : While clicking a button, display any smiley in applet window.

PROGRAM

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="smiley.class" width=350 height=350>
</applet>*/
public class smiley extends Applet implements ActionListener
{
int f,fl;
public void start()
{
Button btnsmile1=new Button("Happy");
add(btnsmile1);
btnsmile1.addActionListener(this);
Button btnsmile2=new Button("Sad");
add(btnsmile2);
btnsmile2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("Happy"))
f++;
repaint();
s=ae.getActionCommand();
if(s.equals("Sad"))
fl++;
repaint();
}
public void paint(Graphics g)
{
if(f==1)
{
g.setColor(Color.yellow);
g.fillOval(50,60,100,95);
g.drawOval(50,60,100,95);
g.setColor(Color.black);
g.fillOval(75,90,10,10);
g.drawOval(75,90,10,10);
g.setColor(Color.black);
g.fillOval(115,90,10,10);
g.drawOval(115,90,10,10);
g.setColor(Color.black);
g.fillArc(70,80,22,10,0,180);
g.drawArc(70,80,22,10,0,180);

g.setColor(Color.black);
g.fillArc(110,80,22,10,0,180);
g.drawArc(110,80,22,10,0,180);

g.setColor(Color.red);
g.fillArc(80,114,40,15,180,180);
g.drawArc(80,114,40,15,180,180);
// g.drawArc(90,120,22,10,0,360);
}
if(fl==1)
{
g.setColor(Color.yellow);
g.fillOval(50,60,100,95);
g.drawOval(50,60,100,95);
g.setColor(Color.black);
g.fillOval(75,90,10,10);
g.drawOval(75,90,10,10);

g.setColor(Color.black);
g.fillOval(115,90,10,10);
g.drawOval(115,90,10,10);

g.setColor(Color.black);
g.fillArc(70,80,22,10,0,180);
g.drawArc(70,80,22,10,0,180);

g.setColor(Color.black);
g.fillArc(110,80,22,10,0,180);
g.drawArc(110,80,22,10,0,180);

g.setColor(Color.black);
g.fillArc(80,115,40,15,0,180);
g.drawArc(80,115,40,15,0,180);
// g.drawArc(90,120,22,10,0,360);
}
}
}
OUTPUT
PROGRAM NO : 35
DATE :

AIM : Prepare a Job Application using applet .Accept all required details from
user and when the submit button is pressed all the details are to be
displayed on a text area.

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="resumes.java" width=800 height=750>
</applet>*/
public class resumes extends Applet implements ItemListener,ActionListener
{
TextField tf1,tf2,tf3,tf4,tf6,tf7;
Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,ld,lm,ly;
Button b1;
CheckboxGroup cbg;
Checkbox cb1,cb2;
Choice ch,st,dd,mm,yy;
String val,msg;
public void init(){
setBackground(Color.yellow);
setLayout(new FlowLayout(FlowLayout.LEFT));
setLayout(null);
l1=new Label("RESUME");
l1.setBounds(250,10,130,50);
l1.setFont(new Font("Monospace",Font.BOLD,28));
l2=new Label("Name :");
l2.setBounds(40,90,50,50);
tf1=new TextField(15);
tf1.setBounds(150,100,150,30);
l3=new Label("Father's Name:");
l3.setBounds(40,150,100,70);
tf2=new TextField(15);
tf2.setBounds(150,170,150,30);
l4=new Label("Date of Birth:");
l4.setBounds(40,210,90,70);
//ld=new Label("DD:");
//ld.setBounds(150,230,20,30);
dd=new Choice();
dd.addItem("DD");
for(int i=1;i<=31;i++)
{
if(i<10)
dd.addItem("0"+i);
else
dd.addItem(""+i); }
dd.setBounds(150,230,45,30);
//lm=new Label("MM:");
//lm.setBounds(220,230,30,30);
mm=new Choice();
mm.addItem("MM");
for(int k=1;k<=12;k++)
{
if(k<10)
mm.addItem("0"+k);
else
mm.addItem(""+k);
}
mm.setBounds(210,230,45,30);
yy=new Choice();
yy.addItem("YYYY");
for(int j=1980;j<=2018;j++)
{
yy.addItem(" "+j);
}
yy.setBounds(270,230,60,30);
l5=new Label("Gender :");
l5.setBounds(40,270,90,70);
cbg=new CheckboxGroup();
cb1=new Checkbox("Male",cbg,true);
cb2=new Checkbox("Female",cbg,false);
cb1.setBounds(150,290,70,30);
cb2.setBounds(230,290,70,30);
l6=new Label("City :");
l6.setBounds(40,330,90,70);
tf4=new TextField(15);
tf4.setBounds(150,350,150,30);
l7=new Label("State :");
l7.setBounds(40,390,90,70);
st=new Choice();
st.addItem("Kerala");
st.add("Andra Pradesh");
st.add("Arunachal Pradesh");
st.add("Assam");
st.add("Bihar");
st.add("Chhattisgarh");
st.add("Goa");
st.add("Gujarat");
st.add("Haryana");
st.add("Himachal Pradesh");
st.add("Jammu & Kashmir");
st.add("Jharkhand");
st.add("Karnataka");
st.add("Kerala");
st.add("Madhya Pradesh"); eweffdf
st.add("Maharashtra");
st.add("Manipur");
st.add("Meghalaya");
st.add("Mizoram");
st.add("Nagaland");
st.add("Odisha");
st.add("Punjab");
st.add("Rajasthan");
st.add("Sikkim");
st.add("Tamilnadu");
st.add("Telangana");
st.add("Tripura");
st.add("Uttar Pradesh");
st.add("Uttarakhand");
st.add("West Bengal");
st.setBounds(150,410,150,30);
l8=new Label("Phone(Mob) :");
l8.setBounds(40,450,90,70);
tf6=new TextField(15);
tf6.setBounds(150,470,150,30);
l9=new Label("Qualification :");
l9.setBounds(40,510,90,70);
tf7=new TextField(15);
tf7.setBounds(150,530,150,30);
b1=new Button("Submit");
b1.setBounds(330,630,100,30);

cb1.addItemListener(this);
cb2.addItemListener(this);
l10=new Label("Cast(category):");
l10.setBounds(40,575,110,60);
ch=new Choice();
ch.addItem("General");
ch.add("OBC");
ch.add("OEC");
ch.add("SC/ST");
ch.setBounds(150,590,150,30);
add(l1);
add(l2);
add(tf1);
add(l3);
add(tf2);
add(l4);
//add(ld);
add(dd);
//add(lm);
add(mm);
//add(ly);
add(yy);
add(l5);
add(cb1);
add(cb2);
add(l6);
add(tf4);
add(l7);
add(st);
add(l8);
add(tf6);
add(l9);
add(tf7);
add(l10);
add(ch);
add(b1);
b1.addActionListener(this);
ch.addItemListener(this);
st.addItemListener(this);
dd.addItemListener(this);
yy.addItemListener(this);
mm.addItemListener(this);
}
public void itemStateChanged(ItemEvent ae)
{
}
public void actionPerformed(ActionEvent ap)
{
msg=ap.getActionCommand();
if(msg.equals("Submit"));
{
val="\tRESUME\n"+"NAME:"+tf1.getText()+"\nFATHER'S NAME:"+tf2.getText()+"\nDATE OF
BIRTH:"+dd.getSelectedItem()+" / "+mm.getSelectedItem()+" / "+ yy.getSelectedItem()
+"\nSEX:"+cbg.getSelectedCheckbox().getLabel()+"\nCITY:"+tf4.getText()
+"\nSTATE:"+st.getSelectedItem()+"\nPHONE(MOB):"+tf6.getText()
+"\nQUALIFICATION:"+tf7.getText()+"\nCAST(CATEGORY): "+ch.getSelectedItem();
TextArea text=new TextArea(val,10,10);
text.setBounds(480,110,200,200);
add(text);
}}}
OUTPUT
PROGRAM NO : 36
DATE :

AIM : Draw the structure of a house. It should contain one door and two
windows. Door is to be represented using vertical scrollbar and windows
are to be represented using horizontal scrollbar. Change the colour of the
house when you move these scrollbars.

PROGRAM

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="house.java" width=500 height=500>
</applet>*/
public class house extends Applet implements AdjustmentListener
{
Scrollbar s1,s2,s3;
public void init()
{
setLayout(null);
s1=new Scrollbar(Scrollbar.VERTICAL);
s2=new Scrollbar(Scrollbar.HORIZONTAL);
s3=new Scrollbar(Scrollbar.HORIZONTAL);
s1.addAdjustmentListener(this);
s2.addAdjustmentListener(this);
s3.addAdjustmentListener(this);
s1.setBounds(240,300,50,100);
s2.setBounds(120,300,100,30);
s3.setBounds(280,200,100,30);
add(s1);
add(s2);
add(s3);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
repaint();
}
public void paint(Graphics g)
{
int x,y,z;
x=s1.getValue();
y=s2.getValue();
z=s3.getValue();
Color c=new Color(x,y,z);
g.setColor(c);
int a[]={100,100,250,400,400,100};
int b[]={400,200,100,200,400,400};
g.fillPolygon(a,b,6);
}}

OUTPUT
PROGRAM NO : 37
DATE :

AIM : Write a program to implement Font metrics.

PROGRAM

import java.awt.*;
/* <APPLET CODE ="fontmatrix.java" WIDTH=300 HEIGHT=200> </APPLET> */
public class fontmatrix extends java.applet.Applet
{
public void paint(Graphics g)
{
String s="Hello Java";
Font f=new Font("Arial",Font.BOLD+Font.ITALIC,20);
g.setFont(f);
FontMetrics met=g.getFontMetrics(f);
int ascent=met.getAscent();
int height=met.getHeight();
int leading=met.getLeading();
int baseline=leading+ascent;
for(int i=0;i<10;i++)
{
g.drawString("Line"+String.valueOf(i),10,baseline);
baseline+=height;
}
}
}

OUTPUT
PROGRAM NO : 38
DATE :

AIM : Implement all Layout Mangers.

PROGRAM

a. Border Layout

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="border.java" width=300 height=200>
</applet>*/
public class border extends Applet
{
Button s,n,e,w;
public void init() {
setLayout(new BorderLayout());
Button s=new Button("SOUTH");
Button n=new Button("NORTH");
Button e=new Button("EAST");
Button w=new Button("WEST");
String msg="****BORDER LAYOUT****";
TextArea ta=new TextArea(msg);
add(n,BorderLayout.NORTH);
add(s,BorderLayout.SOUTH);
add(e,BorderLayout.EAST);
add(w,BorderLayout.WEST);
add(ta,BorderLayout.CENTER);
}}

OUTPUT
b. Grid Layout

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="grid.java" width=300 height=200>
</applet>*/
public class grid extends Applet
{
static final int n=4;
public void init()
{
setLayout(new GridLayout(n,n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
int k=i*n+j;
if(k>0)
{
Button b=new Button(""+k);
add(b);
}}}}}

OUTPUT
c. Flow Layout

PROGRAM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="flow.java" width=300 height=200>
</applet>*/
public class flow extends Applet implements ItemListener
{
String msg="";
Checkbox c1,c2,c3,c4;
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
c1=new Checkbox("c1",null,true);
c2=new Checkbox("c2");
c3=new Checkbox("c2");
c4=new Checkbox("c2");
add(c1);
add(c2);
add(c3);
add(c4);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="Current State :";
g.drawString(msg,6,80);
msg="c1 : "+c1.getState();
g.drawString(msg,6,100);
msg="c2 : "+c2.getState();
g.drawString(msg,6,120);
msg="c3 : "+c3.getState();
g.drawString(msg,6,140);
msg="c4 : "+c4.getState();
g.drawString(msg,6,160);
}
}
OUTPUT
d. Card Layout

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*<applet code="card.java" height=500 width=500></applet>*/


public class card extends Applet implements ActionListener,MouseListener
{
Checkbox winxp,winvista,solaris,mac;
Panel oscards;
CardLayout cardlo;
Button win,other;
public void init()
{
win=new Button("windows");
other=new Button("other");
add(win);
add(other);
cardlo =new CardLayout();
oscards= new Panel();
oscards.setLayout(cardlo);
winxp= new Checkbox("Windows xp",null,true);
winvista=new Checkbox("Windows Vista");
solaris =new Checkbox("solaris");
mac=new Checkbox("mac");
Panel winpan=new Panel();
winpan.add(winxp);
winpan.add(winvista);

Panel otherpan= new Panel();


otherpan.add(solaris);
otherpan.add(mac);
oscards.add(winpan,"windows");
oscards.add(otherpan,"other");
add(oscards);
win.addActionListener(this);
other.addActionListener(this);
addMouseListener(this);
}
public void mousePressed(MouseEvent me)
{
cardlo.next(oscards);
}
public void mouseClicked(MouseEvent me)
{}
public void mouseEntered(MouseEvent me)
{}
public void mouseExited(MouseEvent me)
{}
public void mouseReleased(MouseEvent me)
{}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==win)
{
cardlo.show(oscards,"windows");
}
else
{
cardlo.show(oscards,"other");
}
}
}

OUTPUT
PROGRAM NO : 39
DATE :

AIM : Write a program to create a frame window in an applet.

PROGRAM

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="appletframe.java" width=500 height=500>
</applet>*/
class SampleFrame extends Frame
{
SampleFrame(String title)
{
super(title);
MyWindowAdapter adapter=new MyWindowAdapter(this);
addWindowListener(adapter);
}
public void paint(Graphics g)
{
g.drawString("this is in frame window",10,40);
}
}
class MyWindowAdapter extends WindowAdapter
{
SampleFrame sampleframe;
public MyWindowAdapter(SampleFrame sampleframe)
{
this.sampleframe = sampleframe;
}
public void windowClosing(WindowEvent we)
{
sampleframe.setVisible(false);
}
}
public class appletframe extends Applet
{
Frame f;
public void init()
{
f=new SampleFrame("A frame window");
f.setSize(250,250);
f.setVisible(true);
}
public void start()
{
f.setVisible(true);
}
public void stop()
{
f.setVisible(false);
}
public void paint(Graphics g)
{
g.drawString("this is in applet window",10,20);
}
}

OUTPUT
PROGRAM NO : 40
DATE :

AIM : Create menus- File, Edit, and Help. File menu includes menu items –New,
Open and Save. When Open is clicked, the corresponding dialog box is to
be displayed. A separator should be there between Open and save. Save
as is the sub menu item of Save. Edit menu contains menu items Cut
Copy and Paste. Help should contain menu items Help topics and about
Applet and those items are to be of checkable. The menu items of Edit
should be displayed as Pop up Menu items also.

PROGRAM

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="menu.java" width=300 height=300>
</applet>*/
public class menu extends Applet implements ActionListener
{
Frame f;
MenuBar mb;
Menu m1,m2,m3,me1;
MenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7,mi8;
public void init()
{
f=new Frame("Menu");
f.setVisible(true);
f.setSize(600,600);
mb=new MenuBar();
f.setMenuBar(mb);
m1=new Menu("File");
mi1=new MenuItem("New");
mb.add(m1);
m1.add(mi1);
mi2=new MenuItem("Open");
mi2.addActionListener(this);
m1.add(mi2);
m1.addSeparator();
me1=new Menu("Save");
me1.add(mi3=new MenuItem("Save As"));
m1.add(me1); m2=new Menu("Edit");
mb.add(m2);
mi4=new MenuItem("Cut");
m2.add(mi4);
mi5=new MenuItem("Copy"); m2.add(mi5);
mi6=new MenuItem("Paste");
m2.add(mi6);
PopupMenu p=new PopupMenu();
p.add(new MenuItem("Cut"));
p.add(new MenuItem("Copy"));
p.add(new MenuItem("Paste"));
f.add(p);
p.show(f,200,200);
m3=new Menu("Help");
mb.add(m3);
mi7=new CheckboxMenuItem("Help Topics");
m3.add(mi7);
mi8=new CheckboxMenuItem("About Applet");
m3.add(mi8);
}
public void start()
{
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand()=="Open")
{
FileDialog fd=new FileDialog(f,"FileDialog");
fd.setVisible(true);
}
}
public void stop()
{
f.setVisible(false);
}
}

OUTPUT
PROGRAM NO : 26
DATE :

AIM : Write a java program to perform


A) Byte Stream classes
B) Character Stream classes
C) I/O classes

PROGRAM

A) byte stream classes

import java.io.*;
class bytestream
{
public static void main(String args[]) throws IOException
{
byte b[]="welcome to uc college".getBytes();
ByteArrayInputStream inp =new ByteArrayInputStream(b);
int n=inp.available();
System.out.println("Number of available bytes: "+n);
long s=inp.skip(11);
System.out.println("Number of skipped bytes: "+s);
int i;
System.out.print("String after skipping s bytes: ");
while((i=inp.read()) != -1)
{
System.out.print((char)i);
}
inp.reset();
System.out.println();
int j;
System.out.print("String in uppercase: ");
while((j=inp.read()) != -1)
{
System.out.print(Character.toUpperCase((char) j));
}
}

}
OUTPUT

B) Character Stream Classes

PROGRAM

import java.io.*;
class character
{
public static void main(String args[]) throws IOException
{
String s="This program is skipping first character of each word in the string";
StringReader sr=new StringReader(s);
System.out.println("The input string is: "+s);
BufferedReader br=new BufferedReader(sr);
System.out.print ("The output string is: ");
br.skip(1);
int i=0;
while((i=br.read()) !=-1)
{
System.out.print((char)i);
if((char)i==' ')
{
br.skip(1);
}
}
}
}
OUTPUT

C) I/O classes

PROGRAM

import java.io.*;
class inout
{
public static void main(String args[]) throws IOException
{
FileOutputStream fos = new FileOutputStream("mydata1.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeInt(120);
dos.writeDouble(375.50);
dos.writeInt('A'+ 1);
dos.writeBoolean(true);
dos.writeChar('X');
dos.close();
fos.close();
// read primitive data in binary format from the "mydata" file
FileInputStream fis = new FileInputStream( "mydata1.txt");
DataInputStream dis = new DataInputStream(fis);
System.out.println(dis.readInt());
System.out.println(dis.readDouble());
System.out.println(dis.readInt());
System.out.println(dis.readBoolean());
System.out.println(dis.readChar());
dis.close();
fis.close();
}
}
OUTPUT

You might also like