0% found this document useful (0 votes)
2 views84 pages

Java

The document contains a list of Java programming exercises with their respective dates, aims, coding examples, outputs, and results. Each exercise focuses on different programming concepts such as swapping numbers, handling classes and objects, checking anagrams, and implementing inheritance. The document serves as a comprehensive guide for practicing Java programming skills.

Uploaded by

noblecoaswcs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views84 pages

Java

The document contains a list of Java programming exercises with their respective dates, aims, coding examples, outputs, and results. Each exercise focuses on different programming concepts such as swapping numbers, handling classes and objects, checking anagrams, and implementing inheritance. The document serves as a comprehensive guide for practicing Java programming skills.

Uploaded by

noblecoaswcs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

S.

No Date Name of the Program Page no Signature

1. 03/12/2025 Swapping Two Numbers 3

2. 08/12/2025 Student Details Using Class And 5


Objects
3. 10/12/2025 Invoice Bill Using Class And 7
Object

4. 15/12/2025 Check Two String Are Anagram 10


Or Not
5. 17/12/2025 Executing Various Window 13
Applications
6. 22/12/2025 Factorial Using Function 20

7. 24/12/2025 Prime Number Using Scanner 22

8. 29/12/2025 Matrix Multiplication 25

9. 31/12/2025 Method Overloading Using 29


Constructor
10. 05/01/2026 Single Inheritance 32

11. 07/01/2026 Multilevel Inheritance 35

12. 12/01/2026 String Null Pointer Exception 38


13. 14/01/2026 String Array Handling 40
Exception
14. 19/01/2026 Arithmetic Exception 42
15. 21/01/2026 User defined Exception 44
16. 28/01/2026 File Creation 46
17. 02/02/2026 File Copy Using Stream 49

18. 04/02/2026 Implementation of daemon 52


threads
19. 09/02/2026 Runnable interface 55
20. 11/02/2026 Digital Clock Using AppletAnd 59
Thread

1
21. 18/02/2026 Scrolling Text Using Apple And 62
Thread
22. 25/02/2026 Drawing Human Face Using 65
Graphic Primitives
23. 04/03/2026 Changing Background Color Of 67
Rectangle Using Applet
24. 11/03/2026 Implementing is Alive() and join() 70
25. 16/03/2026 Thread class 75
26. 23/03/2026 This pointer 79
27. 25/03/2026 Retrieve host name and Address 82

2
[Link]
SWAPPING TWO NUMBERS
DATE:03/12/2025

AIM:
To write a java program for swapping two numbers.

CODING:
class swap
{
public static void main(String args[])
{
float a=10.5f;
float b=20.6f;
float t;
[Link]("Before swap");
[Link](a);
[Link](b);
t=a;
a=b;
b=t;
[Link]("After swap");
[Link](a);
[Link](b);
}
}

3
OUTPUT:

D:\bca>java swap
Before swap
10.5
20.6
After swap
20.6
10.5

RESULT:

Thus the java program for swapping two numbers was successfully
executed.

4
[Link]
STUDENT DETAILS USING CLASS AND OBJECT
DATE:08/12/2025

AIM:

To write a java program for student details using class and object.

CODING:

class student
{
String name;
int rno;
public void display()
{
[Link]("Name:"+name);
[Link]("Rollno:"+rno);
}
public static void main(String args[])
{
student s=new student();
[Link]="AAA";
[Link]=10;
[Link]();
}
}

5
OUTPUT:

D:\bca>java student
Name:AAA
Rollno:10

RESULT:

Thus the program of student details using class and object was successfully
executed.

6
[Link]
INVOICE BILL USING CLASS AND OBJECT
DATE:10/12/2025

AIM:
To write a java program for invoice bill using class and object.

CODING:

import [Link].*;
import [Link].*;
class invoice
{
int pid,qty;
String pname;
Double price,bill;
DataInputStream ob=new DataInputStream([Link]);
void get()throws IOException
{
[Link]("Enter the product id:");
pid=[Link]([Link]());
[Link]("Enter the product name:");
pname=[Link]();
[Link]("Enter the quantity:");
qty=[Link]([Link]());
[Link]("Enter the price:");
price=[Link]([Link]());
}
void calc()

7
{

bill=qty*price;
}
void put()
{
[Link]("\n\n Bill amount is"+bill);
}
}
class invoicebill
{
public static void main(String args[]) throws IOException
{
[Link]("********************");
[Link]("INVOICE BILL USING CLASS AND OBJECT");
[Link]("*****************************************");
invoice inv=new invoice();
[Link]();
[Link]();
[Link]();
}
}

8
OUTPUT:
D:\bca>java invoicebill
********************
INVOICE BILL USING CLASS AND OBJECT
*****************************************
Enter the product id:
101
Enter the product name:
mobile
Enter the quantity:
1000
Enter the price:
25000
Bill amount is2.5E7

RESULT:
Thus the java program of invoice bill using class and object was successfully
executed.

9
[Link]
CHECK TWO STRINGS ARE ANAGRAM OR NOT
DATE:15/12/2025

AIM:
To write a java program for checking two strings are anagram or not.
CODING:
import [Link].*;
import [Link].*;
class anagram
{
public static void main(String args[]) throws IOException
{
String s1,s2;
DataInputStream ob=new DataInputStream([Link]);
[Link]("*****");
[Link]("CHECK TWO STRING ARE ANAGRAM OR NOT");
[Link]("enter 1st string:");
s1=[Link]();
[Link]("enter 2nd string:");
s2=[Link]();
if([Link]()!=[Link]())
{
[Link]("\n given string are not anagram");
[Link](0);
}
char c1[]=[Link]().toCharArray();
10
char c2[]=[Link]().toCharArray();
[Link](c1);
[Link](c2);
if([Link](c1,c2))
[Link]("\n given string are anagram");
else
[Link]("\n given string are not anagram");
}
}

11
OUTPUT:
D:\bca>java anagram
*****
CHECK TWO STRING ARE ANAGRAM OR NOT
enter 1st string:
java
enter 2nd string:avaj
given string are anagram

D:\bca>java anagram
*****
CHECK TWO STRING ARE ANAGRAM OR NOT
enter 1st string:
java
enter 2nd string:
app
given string are not anagram

RESULT:
Thus a java program of given string are anagram or not was successfully
executed.

12
[Link]
EXECUTING VARIOUS WINDOWS APPLICATION
DATE:17/12/2025

AIM:
To write a java program for executing various windows applications.
CODING:
import [Link].*;
import [Link].*;
class window
{
public static void main(String args[]) throws IOException
{
int ch;
DataInputStream ob=new DataInputStream([Link]);
do
{
[Link]("******");
[Link]("Executing various windows application");
[Link]("********");
[Link]("\n1-Notepad\n2-Paint\n3-Calculator\n4-Explorer\n5- Exit\n");
Runtime r=[Link]();
Process p=null;
[Link]("Enter your choice");
ch=[Link]([Link]());
switch(ch)
{

13
case 1:
try
{
p=[Link]("[Link]");
[Link]("Notepad is opened");
}
catch(Exception e)
{
[Link]("\n Error in notepad");
}
break;
case 2:
try
{
p=[Link]("[Link]");
[Link]("Paint is opened");
}
catch(Exception e)
{
[Link]("Error in paint");
}
break;
case 3:
try
{
p=[Link]("[Link]");
[Link]("Calculator is opened");

14
}
catch(Exception e)
{
[Link]("Error in calculator");
}
break;
case 4:
try
{
p=[Link]("[Link]");
[Link]("\n Explorer is opened");
}
catch(Exception e)
{
[Link]("\n Error in exception");
}
break;
case 5:
[Link]("Exit the program");
[Link](0);
default:
[Link]("Invalid choice");
break;
}
}
while(ch!=5);
}}

15
OUTPUT:
D:\bca>java window
******
Executing various windows application
********
1-Notepad
2-Paint
3-Calculator
4-Explorer
5- Exit
Enter your choice1
Notepad is opened
******

Executing various windows application


********

16
1-Notepad
2-Paint
3-Calculator
4-Explorer
5- Exit
Enter your choice 2
Paint is opened
******

Executing various windows application


********
1-Notepad
2-Paint
3-Calculator
4-Explorer

17
5- Exit
Enter your choice 3
Calculator is opened
******

Executing various windows application


********
1-Notepad
2-Paint
3-Calculator
4-Explorer
5- Exit
Enter your choice 4
Explorer is opened

18
Executing various windows application
1-Notepad
2-Paint
3-Calculator
4-Explorer
5- Exit
Enter your choice5
Exit the program

RESULT:
Thus a java program for various window application was successfully
executed.

19
[Link]
FACTORIAL USING FUNCTION
DATE:22/12/2025

AIM:
To write a java program for factorial using function.
CODING:
class factorial
{
factorial(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
[Link]("Factorial value is:"+fact);
}
}
class fac
{
public static void main(String args[])
{
factorial f=new factorial(5);
}}

20
OUTPUT:
D:\bca>javac [Link]
D:\bca>java fac
Factorial value is:120

RESULT:

Thus the java program for factorial using function was successfully
executed.

21
[Link]
PRIME NUMBER USING SCANNER
DATE:24/12/2025

AIM:

To write a java program for prime number using scanner.

CODING:

import [Link].*;
import [Link].*;
class prime
{
public static void main(String args[])
{
int num,n,i,j,count;
Scanner s=new Scanner([Link]);
[Link]("Enter the number for prime number generation:");
num=[Link]();
[Link]("1is neither prime nor composite");
[Link]("2 is even prime number");
for(j=3;j<=num;j++)
{
i=1;
n=j;
count=0;
while(i<=n)
{
if((n%i==0))
22
{
count=count+1;
}
i=i+1;
}
if(count==2)
{
[Link](n);
}
}
}
}

23
OUTPUT:

D:\bca>java prime
Enter the number for prime number generation:
7
1is neither prime nor composite
2 is even prime number
3
5
7

RESULT:

Thus the java program for generating prime number was successfully
executed.

24
[Link]
MATRIX MULTIPLICATION
DATE:29/12/2025

AIM:
To write a java program for multiplication the matrix.

CODING:

import [Link].*;
import [Link].*;
class matmul
{
public static void main(String args[]) throws IOException
{
int m,n,p,q,sum=0,i,j,k; int a[][],b[][],c[][];
DataInputStream ob=new DataInputStream([Link]);
[Link]("*********************");
[Link]("MATRIX MULTIPLICATION");
[Link]("**********************");
[Link]("Enter the number of rows and columns of first matrix");
m=[Link]([Link]());
n=[Link]([Link]());
[Link]("Enter the number of rows and columns of second matrix");
p=[Link]([Link]());
q=[Link]([Link]());
if(n!=p)
{
[Link]("MATRIX MULTIPLICATION CANNOT PERFORMED");

25
[Link](0);
}
else
{
a=new int [m][n];
b=new int[p][q];
c=new int [m][q];
[Link]("Enter the element of first matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=[Link]([Link]());
[Link]("Enter the element of second matrix:");
for(i=0;i<p;i++)
for(j=0;j<p;j++)
b[i][j]=[Link]([Link]());
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
sum=0;
}
}

26
[Link]("first matrix is:");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
[Link](a[i][j]+"\t");
}
[Link]();
}
[Link]("second matrix is:");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
[Link](b[i][j]+"\t");
}
[Link]();
}
[Link]("Matrix multiplication is:");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
[Link](c[i][j]+"");
}
[Link]();
}}}}

27
OUTPUT:
D:\bca>java matmul
*********************
MATRIX MULTIPLICATION
**********************
Enter the number of rows and columns of first matrix 2
2
Enter the number of rows and columns of second matrix 2
2
Enter the element of first matrix:
3
3
3
3
Enter the element of second matrix:
3
3
3
3
First Matrix is:
3 3
3 3
Second Matrix is:
3 3
3 3
Matrix Multiplication is:
18 18
18 18

RESULT:
Thus the java program for matrix multiplication was successfully
executed.

28
[Link]
METHOD OVERLOADING USING CONSTRUCTOR
DATE:31/12/2025

AIM:

To write the program for Method Overloading using Constructor.

CODING:

class exover
{
void test()
{
[Link]("No parameters");
}
void test(int a)
{
[Link]("a:"+a);
}
void test(int a,int b)
{
[Link]("a and b"+a+b);
}
double test(double a)
{
[Link]("double value is"+a);
return a*a;
}

29
public static void main(String args[])
{
exover ex=new exover();
double d;
[Link]();
[Link](10);
[Link](10,20);
d=[Link](120.5);
[Link]("double value is"+d);
}
}

30
OUTPUT:

D:\bca>javac [Link]
D:\bca>java exover
No parameters
a:10
a and b:1020
double value is 120.5
double value is 14520.25

RESULT:
Thus the java program for method overloading using constructor was
successfully executed.

31
[Link]
SINGLE INHERITANCE
DATE:05/01/2026

AIM:
To write a java program for single inheritance.
CODING:
class area
{
int a;
area(int n)
{
a=n;
}
int calc()
{
return(a*a);
}
}
class rectangle extends area
{
int b;
rectangle(int m,int n)
{
super(n);
b=m;

32
}

int calc1()
{
return(a*b);
}
}
class singleinh
{
public static void main(String args[])
{
rectangle rec=new rectangle(10,20);
[Link]("output");
[Link]("area of square:"+[Link]());
[Link]("area of rectangle:"+rec.calc1());
}
}

33
OUTPUT:
D:\bca>java singleinh
area of square:400
area of rectangle:200

RESULT:
Thus the java program for single inheritance was successfully
executed.

34
[Link]
MULTILEVEL INHERITANCE
DATE:07/01/2026

AIM:
To write a java program for multilevel inheritance.

CODING:

class empty
{
String empname="karthi";
int eid=101;
int salary=50000;
void display()
{
[Link]("employee name:"+empname);
[Link]("employee id:"+eid);
[Link]("salary:"+salary);
}
}
class allowance extends empty
{
int bp=30000;
double hra,ta,pf;
void calc()
{
hra=bp*0.12;

35
ta=bp*0.1;
pf=bp*0.1;
[Link]("home rent allowance:"+hra);
[Link]("travelling allowance:"+ta);
[Link]("provident fund:"+pf);
}
}
class sal extends allowance
{
double gp,np;
void calc1()
{
gp=bp+hra+ta;
np=gp-pf;
[Link]("gross pay:"+gp);
[Link]("net pay:"+np);
}
}
class empsal
{
public static void main(String args[])
{
sal s=new sal();
[Link]();
[Link]();
s.calc1();
}}

36
OUTPUT:
D:\bca>java empsal
employee name:karthi
employee id:101
salary:50000
home rent allowance:3600.0
travelling allowance:3000.0
provident fund:3000.0
gross pay:36600.0
net pay:33600.0

RESULT:
Thus the java program for multilevel inheritance was successfully executed.

37
[Link]
STRING NULL POINTER EXCEPTION
DATE:12/01/2026

AIM:
To write a java program for string null pointer exception.
CODING:
class nullexcep
{
public static void main(String args[])
{
try
{
String str=null;
[Link]([Link]());
}
catch(NullPointerException e)
{
[Link]("there is null value");
}
}
}

38
OUTPUT:
D:\bca>java nullexcep
there is null value

RESULT:
Thus the java program for string null pointer exception was successfully
executed.

39
[Link]
STRING ARRAY HANDLING EXCEPTION
DATE:14/01/2026

AIM:
To write a java program for string array handling exception.
CODING:
class excep1
{
public static void main(String args[])
{
try
{
String str="java";
[Link]([Link]());
char c=[Link](0);
c=[Link](35);
[Link](c);
}
catch(StringIndexOutOfBoundsException e)
{
[Link]("String Index Out Of Bounds Exception!");
}
}
}

40
OUTPUT:
D:\bca>java excep1
4
String Index Out Of Bounds Exception!

RESULT:
Thus the java program for string array handling exception was successfully
executed.

41
[Link]
ARITHMETIC EXCEPTION
DATE:19/01/2026

AIM:
To write a java program for arithmetic exception.
CODING:
class arithexcep
{
public static void main(String args[])
{
try
{
int x=10,y=0;
int result=x/y;
[Link]("result:"+result);
}
catch(ArithmeticException e)
{
[Link]("number cannot be divided");
}
}
}

42
OUTPUT:
D:\bca>java arithexcep
number cannot be divided

RESULT:
Thus the java program of arithmetic exception was successfully executed.

43
[Link]
USER DEFINED EXCEPTION
DATE:21/01/2026

AIM:
To write a java program for user defined exception.
CODING:
class A extends Exception
{
A(String s1)
{
super(s1);
}
}
class owndemo
{
public static void main(String args[])
{
try
{
throw new A("demo");
}
catch(Exception e)
{
[Link](e);
}}}

44
OUTPUT:
D:\bca>java owndemo
A: demo

RESULT:
Thus the java program for user defined exception was successfully executed.

45
[Link]
FILE CREATION
DATE:28/01/2026

AIM:
To write a java program for file creation.
CODING:
import [Link].*;
public class streamread
{
public static void main(String args[]) throws IOException
{
InputStreamReader cin=null;
try
{
cin=new InputStreamReader([Link]);
[Link]("Enter character 'e' to exit");
char c;
do
{
c=(char)[Link]();
[Link](c);
}
while(c!='e');
}
finally

46
{
if(cin!=null)
{
[Link]();
}
}
}
}

47
OUTPUT:
D:\bca>java streamread
enter character 'e' to exit
java
j
a
v
a

e
e

RESULT:
Thus the java program for file creation was successfully executed.

48
[Link]
FILE COPY USING STREAM
DATE:02/02/2026

AIM:
To write a java program for file copy using stream.
CODING:
import [Link].*;
class filecopy
{
public static void main(String args[]) throws IOException
{
int i;
String src,des;
DataInputStream ob=new DataInputStream([Link]);
[Link]("enter the source file name:");
src=[Link]();
[Link]("enter the destination file name:");
des=[Link]();
try
{
FileInputStream fin=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(des);
do
{
i=[Link]();
if(i!=-1)

49
{
[Link]((char)i);
[Link](i);
}
}
while(i!=-1);
[Link]("\n source file:"+src+"is successfully copied to
destination."+des);
}
catch(IOException e)
{
[Link]("file error"+e);
}
}
}

50
OUTPUT:
Enter the source file name:[Link]
Enter the destination file name:[Link]
Nishandhini
Karthigaiselvi
Selvalakshmi
Jansirani
Source file:[Link] is successfully copied to [Link]

RESULT:
Thus the program of file copy using stream was successfully executed.

51
[Link]
IMPLEMENTATION OF DAEMON THREADS
DATE:04/02/2026

AIM:
To write a java program for implementation of daemon threads.
CODING:
class A extends Thread
{
public void run()
{
if([Link]().isDaemon())
[Link]("Daemon Thread work");
else
[Link]("User Thread work");
}
}
class daemondemo
{
public static void main(String args[])
{
A a1=new A();
A a2=new A();
A a3=new A();
[Link](true);
[Link]();
[Link]();

52
[Link]();
}
}

53
OUTPUT:
D:\bca>java daemondemo
Daemon Thread work
User Thread work
User Thread work

RESULT:
Thus the java program of implementation of daemon threads was
successfully executed.

54
[Link]
RUNNABLE INTERFACE
DATE:09/02/2026

AIM:
To write a java program for runnable interface.
CODING:
class A implements Runnable
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
[Link](1000);
[Link]("good morning");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class B implements Runnable

55
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
[Link](2000);
[Link]("hello");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class C implements Runnable
{
public void run()
{
try
{
for(int k=1;k<=10;k++)
{
[Link](3000);
[Link]("welcome");

56
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class runnabledemo
{
public static void main(String args[])
{
A a1=new A();
B b1=new B();
C c1=new C();
Thread t1=new Thread(a1);
Thread t2=new Thread(b1);
Thread t3=new Thread(c1);
[Link]();
[Link]();
[Link]();
}
}

57
OUTPUT:
D:\bca>java runnabledemo
good morning
hello
good morning
welcome
good morning
hello
good morning
good morning
hello
welcome
good morning
good morning

RESULT:
Thus the java program for runnable interface was successfully executed.

58
[Link]
DIGITAL CLOCK USING APPLET AND THREAD
DATE:11/02/2026

AIM:
To write a java program for digital clock using applet and thread.
CODING:
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="[Link]"width="200"height="200"></applet>*/
public class Digital extends Applet implements Runnable
{
Thread t;
public void start()
{
t=new Thread(this);
[Link]();
}
public void run()
{
try
{
for(;;)
{
repaint();
[Link](1000);
59
}
}
catch(InterruptedException e)
{
[Link]("error");
}
}
public void paint(Graphics g)
{
showStatus("WELCOME TO DIGITAL CLOCK");
setBackground([Link]);
setForeground([Link]);
Date d=new Date();
[Link](new Font("Times New Roman",[Link],30));
[Link]([Link]()+":"+[Link]()+":"+[Link](),600,300);
}
}

60
OUTPUT:

RESULT:
Thus the java program of Digital clock using applet and thread was
successfully executed.
61
[Link]
SCROLLING TEXT USING APPLET AND THREAD
DATE:18/02/2026

AIM:
To write a java program for scrolling text using applet and thread.
CODING:
import [Link].*;
import [Link].*;
/*<applet code="scroll"width="200"height="200"></applet>*/
public class scroll extends Applet implements Runnable
{
Thread t;
char c;
String s;
public void start()
{
s="SCROLLING TEXT USING APPLET AND THREAD";
t=new Thread(this);
[Link]();
}
public void run()
{
try
{
for(;;)

62
{
repaint();
[Link](1000);
c=[Link](0);
s=[Link](1)+c;
}
}
catch(InterruptedException e)
{
[Link]("error");
}
}
public void paint(Graphics g)
{
showStatus("SCROLLING TEXT USING APPLET AND THREAD");
setBackground([Link]);
setForeground([Link]);
[Link](new Font("monotype corsiva",[Link],30));
[Link](s,400,400);
}
}

63
OUTPUT:

RESULT:
Thus the java program for scrolling text using applet and thread was
successfully executed.

64
[Link] DRAWING HUMAN FACE USING GRAPHIC
PRIMITIVES
DATE:25/02/2026

AIM:
To write a java program for drawing human face using graphic primitives.
CODING:
import [Link].*;
import [Link].*;
/*<applet code="face"width="400"height="400"></applet>*/
public class face extends Applet
{
public void paint(Graphics g)
{
showStatus("drawing human face");
setBackground([Link]);
setForeground([Link]);
[Link]("drawing human face",120,20);
[Link](40,40,120,150);
[Link](57,75,30,20);
[Link](110,75,30,20);
[Link](68,81,10,10);
[Link](121,81,10,10);
[Link](85,100,30,30);
[Link](60,125,80,40,180,180);
[Link](25,92,15,30);
[Link](160,92,15,30);}}
65
OUTPUT:

RESULT:
Thus the java program for drawing human face using graphic primitive was
successfully executed.

66
[Link]
CHANGING BACKGROUND COLOR OF
DATE:04/03/2026
RECTANGLE USING APPLET

AIM:
To write a java program for changing background color of rectangle using
applet.
CODING:
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="SB"width="400"height="300"></applet>*/
public class SB extends Applet implements AdjustmentListener
{
Scrollbar r,g,b;
TextField ta;
public void init()
{
setLayout(null);
r=new Scrollbar(0,0,1,0,256);
[Link](10,120,200,30);
g=new Scrollbar(0,0,1,0,256);
[Link](100,150,200,30);
b=new Scrollbar(0,0,1,0,256);
[Link](100,180,200,300);
ta=new TextField(50);

67
[Link](100,10,200,100);
add(r);
add(g);
add(b);
add(ta);
[Link] AdjustmentListener(this);
[Link] AdjustmentListener(this);
[Link] AdjustmentListener(this);
}
public void adjustmentValueChanged(Adjustment Event ae)
{
int cr,cg,cb;
cr=[Link]();
cg=[Link]();
cb=[Link]();
showStatus("Color is-->r="+cr+",g="+cg+",b="+cb);
[Link](new Color(cr,cg,cb));
}
}

68
OUTPUT:

RESULT:
Thus the java program for changing the background color of rectangle was
successfully executed.

69
[Link]
IMPLEMENTING IS ALIVE() AND JOIN()
DATE:11/03/2026

AIM:
To write a java program for implementing is alive() and join().
CODING:
class A extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
sleep(1000);
[Link]("good morning");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class B extends Thread

70
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
sleep(2000);
[Link]("hello");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class C extends Thread
{
public void run()
{
try
{
for(int k=1;k<=10;k++)
{
sleep(3000);
[Link]("welcome");

71
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class isalivedemo
{
public static void main(String args[])
{
A a1=new A();
B b1=new B();
C c1=new C();
[Link]();
[Link]();
[Link]();
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
try
{
[Link]();
[Link]();
[Link]();
}

72
catch(InterruptedException e)
{
[Link](e);
}
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
}
}

73
OUTPUT:
D:\bca>java isalivedemo
true
true
true
good morning
good morning
hello
good morning
welcome
good morning
hello
good morning
welcome
hello
good morning
good morning
good morning
hello
welcome
good morning

RESULT:
Thus the java program for implementing is alive() and join() was
successfully executed.

74
[Link]
THREAD CLASS
DATE:16/03/2026

AIM:
To write a java program for thread class.
CODING:
class A extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
sleep(1000);
[Link]("good morning");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class B extends Thread

75
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
sleep(2000);
[Link]("hello");
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class C extends Thread
{
public void run()
{
try
{
for(int k=1;k<=10;k++)
{
sleep(3000);
[Link]("welcome");

76
}
}
catch(Exception e)
{
[Link](e);
}
}
}
class threaddemo
{
public static void main(String args[])
{
A a1=new A();
B b1=new B();
C c1=new C();
[Link]();
[Link]();
[Link]();
}
}

77
OUTPUT:

D:\bca>java threaddemo
good morning
hello
good morning
welcome
good morning
hello
good morning
good morning
welcome
hello
good morning

RESULT:
Thus the java program for thread demo was successfullyexecuted.

78
[Link]
THIS POINTER
DATE:23/03/2026

AIM:
To write a java program for this pointer.
CODING:
class point
{
int x,y;
point(int x,int y)
{
this.x=x;
this.y=y;
}
void display()
{
[Link]("point:("+x+","+y+")");
}
}
class pointd extends point
{
pointd(int x,int y)
{
super(x,y);
}
void display()

79
{
[Link]("pointd:("+x+","+y+")");
}
}
class manip
{
public static void main(String args[])
{
point point=new point(3,5);
pointd pointd=new pointd(7,9);
[Link]();
[Link]();
}
}

80
OUTPUT:
D:\bca>java manip
point:(3,5)
pointd:(7,9)

RESULT:
Thus the java program for this pointer was successfully executed.

81
[Link]

DATE:25/03/2026 RETRIVE HOST NAME AND ADDRESS

AIM:
To write a java program for retrieve host name and address .
CODING:
import [Link].*;
class host
{
public static void main(String args[]) throws UnknownHostException
{
[Link]("retrieve host name and address:");
InetAddress addr=[Link]();
String name=[Link]();
[Link]("/n/n name of the local host is:"+name);
String ip=[Link]();
[Link]("/n/n address of the local host is:"+ip);
}
}

82
OUTPUT:
D:\bca>java host
retrieve host name and address:
/n/n name of the local host is:DESKTOP-AI1O0Q9
/n/n address of the local host is:[Link]

RESULT:
Thus the program of retrieve host name and address was successfully

83
executed.

84

You might also like