SRI VASAVI COLLEGE
[Re-Accredited with ‘B’ Grade by NAAC]
(Affiliated to Bharathiar University)
ERODE–638316
DEPARTMENT OF COMPUTER SCIENCE
CoreLab4:
PROGRAMMING LAB-JAVA
(33P)
PRACTICAL RECORD NOTEBOOK
2025–2026
2024 2025
NAME :
REGISTER NUMBER :
CLASS :II–B.ScComputerScience
SRI VASAVI COLLEGE
[Re-Accredited with‘B’ Grade by NAAC]
(Affiliated to Bharathiar University)
ERODE–638316
DEPARTMENT OF COMPUTER SCIENCE
This is to certify that, this is a bonafide record of practical work done
by Register Number of
II-B.Sc Computer Science for Core Lab 4: Programming Lab-JAVA (33P)
of Sri Vasavi College during ODD Semester of the academic year 2025-2
2026
5.
Staff In-Charge Head of the Department
Dr.D.SASIKALA Dr.R.PRAGALADAN
Assistant Professor Associate Professor & Head
Department of Computer Science Department of Computer Science
Sri Vasavi College, Erode – 638 316. Sri Vasavi College, Erode – 638 316
Submitted to the Bharathiar University Practical Examinations
held on at Computer Lab, Department of
Computer Science, Sri Vasavi College, Erode – 638 316.
Date :
Place : Erode
INTERNAL EXAMINER EXTERNAL EXAMINER
PROGRAM CONTENTS
S.NO DATE PARTICULARS PAGE NUMBER
1 STRINGEXTRACTION
2 MULTIPLEINHERITANCE
PAYOUTOFBOUNDS
3
EXCEPTION
4 MULTITHREADING
5 DRAWSHAPES
6 MYDETAILSDEMO
7 MULTIPLESELECTION
8 TEXTDEMO
MENUBARANDPULL
9
DOWN MENUS
10 MOUSEDEMO
DRAWSHAPESINMOUSE
11
CLICKPOSITION
12 APPENDTEXTINAFILE
STRING EXTRACTION
Ex.No.:1
Date :
AIM:
ALGORITHM:
Step 1:Start the process.
Step2:Import the necessary files.
Step3:Declare the variables.
Step4:Assign the string to variables.
Step5:Using the substring() Extract the position of a string.
Step6:Display the string.
Step7:Stop the process.
1
CODING:
import java.lang.*;
public class Substr1
{
Public static void main(String args[])
{
String Str=new String(“JAVA PROGRAMMING”);
String.out.println(“Given string is: JAVA PROGRAMMING”);
System.out.print(“The extracted substring is:”);
System.out.println(Str.substring(0,4));
}
}
2
OUTPUT:
D:\jdk1.4\bin>javacSubstr1.java
D:\jdk1.4\bin>java Substr1
Given string is:JAVA PROGRAMMING
The extracted substring is:JAVA
RESULT:
3
MULITIPLE INHERITANCE
Ex.No.: 2
Date :
AIM:
ALGORITHM:
Step1:Start the process.
Step2:Import the necessary files.
Step3:Declare the interface and main class.
Step4:Declare the variable and assign values.
Step5:Perform the action on the specific function.
Step6:Display the result.
Step7:Stop the process.
4
CODING:
import java.lang.*;
interface first
{
int a =14;
public void add();
public void sub();
}
interface second
int b = 7;
public void mul();
public void div();
}
class Arithmetic implements first,second
public void add()
5
{
System.out.println("Addition:"+(a+b));
public void sub()
System.out.println("Subtraction:"+(a-b));
public void mul()
System.out.println("Multiplication:"+(a*b));
public void div()
System.out.println("Division:"+(a/b));
class prg2
6
public static void main(String args [] )
Arithmetic a=new Arithmetic();
System.out.println("a value is :"+a.a);
System.out.println("b value is:"+a.b);
a.add();
a.sub();
a.mul();
a.div();
7
OUTPUT:
D:\jdk1.4\bin>javac prg2.java
D:\jdk1.4\bin>java prg2
A value is:14
B value is:7
Addition:21
Subtraction:7
Multiplication:98
Division:2
RESULT:
8
PAYOUT OF BOUNDS EXCEPTION
Ex.No:3
Date:
AIM:
ALGORITHM:
Step1: Start the process.
Step2:Import the necessary files.
Step3: Declare the variables and assign the value
Step4:Check the condition balanced amount is lessthan
Withdraw amount the n display pay out of bounds.
Step5:Execute the program.
Step6: Display the result.
Step7:Stop the process.
9
CODING:
class prg3
String name;
int bp,hra,ma,pf,lic,gp,np;
prg3 (string a,int b)
name=a;
bp=b;
void display()throws Pay
System.out.println("EMPLOYEEDETAILS");
if (bp<=10000)
throw new Pay(bp);
hra=bp*10/100;
ma=bp*5/100;
gp=bp+hra+ma;
10
pf=bp*10/100;
lic=bp*20/100;
np=gp-(pf+lic);
System.out.println("name:"+name);
System.out.println("Basic pay:"+bp);
System.out.println("Medical allowance:"+ma);
System.out.println("Human resources:"+hra);
System.out.println("Grand pay:"+gp);
System.out.println("Provident fund :"+pf);
System.out.println("lic:"+lic);
System.out.println("Net amount:"+np);
System.out.println("");
public static void main(String args[])
System.out.println("Payout of bounds");
prg3 x=new prg3("Dhivya",120000);
prg3 y=new prg3("Yash",800000);
11
try
x.display();
y.display();
catch(Pay P){}
System.out.println("The salary is too low");
class Pay extends Exception
int basic;
Pay (int a)
basic=a;
12
OUTPUT:
D:\jdk1.4\bin>javacprg3.java
D:\jdk1.4\bin>java prg3
Payout of Bounds
EMPLOYEE DETAILS
name:Dhivya
basic pay:120000
medical allowance:6000
human resources:12000
grand pay:138000
provident fund:12000
lic:24000
net amount:102000
EMPLOYEE DETAILS
name:yash
basic pay:800000
medical allowance:40000
human resources:80000
grand pay:920000
13
provident fund:80000
lic:160000
net amount:680000
The salary is too low
RESULT
14
MULTITHREADING
Ex.No:4
Date :
AIM:
ALGORITHM:
Step1: Start the process.
Step2:Import the process
Step3:Declare the variable and define any multiplication table
Perform that.
Step4:In the main class create an object and assign priorities
For them and run the object.
Step5:Execute the program.
Step6: Display the result.
Step7:Stop the process.
15
CODING:
import java.lang.*;
class table1extendsThread
public void run()
int i;
System.out.println(“\nFIRST MULTIPLICATION TABLE”);
for(i=1;i<5;i++)
System.out.println(""+i+"*1="+i);
class table2 extends Thread
public void run()
16
int i,s;
System.out.println(“\nSECOND MULTIPLICATION TABLE”);
for(i=1;i<5;i++)
{
S=i*2;
System.out.println(""+i+"*2="+s);
class table3 extends Thread
public void run()
int i,t;
System.out.println(“\nTHIRDMULTIPLICATIONTABLE”);
for(i=1;i<5;i++)
t=i*3;
System.out.println(""+i+"*3="+t);
17
}
classprg4
Public static void main(String args[])
table1 q=new table1();
table2 r=new table2();
table3 s=new table3();
q.run();
r.run();
s.start();
18
OUTPUT:
D:\jdk1.4\bin>javacprg4.java
D:\jdk1.4\bin>java prg4
FIRST MULTIPLICATION TABLE
1*1=1
2*1=2
3*1=3
4*1=4
SECOND MULTIPLICATION TABLE
1*2=2
2*2=4
3*2=6
4*2=8
THIRD MULTIPLICATION TABLE
1*3=3
2*3=6
3*3=9
4*3=12
RESULT:
19
DRAW SHAPES
EX.No:5
Date:
AIM:
ALGORITHM:
Step1: Start the process.
Step2:Import the necessary files.
Step3:Declare the class that extend applet.
Step4:Declare several shape using draw string draw
Oval,drawind and etc..
Step5: Set the color forshape.
Step6:Create HTML document using applet tag that Specify
Height and width.
Step7:Execute the program.
Step8: Display the result.
Step9:Stop the process.
20
CODING:
import java.applet.*;
import java.awt.*;
public class prg5extends Applet
public void paint(Graphics g)
g.draw Line(2,2,40,100);
g.drawRect(10,240,40,30);
g.drawRoundRect(5,280,80,50,10,10);
g.draw Oval(40,330,200,120);
g.drawArc(100,280,80,40,180,180);
int x[]={30,200,30,200,30};
int y[]={30,30,200,200,30};
int n=5;
21
g.draw Polygon(x,y,n);
HTMLCODING:
<html>
<head>Draw shapes</head>
<body>
<applet code="prg5"width="1000"height"700">
</applet>
</body>
</html>
22
Output:
RESULT:
23
MY DETAILS DEMO
Ex.No:6
Date :
AIM:
ALGORITHM:
Step 1:Start the process.
Step2:Import the necessary files.
Step3:Declare the class that extends applet.
Step4:Create new class frame and set name as”MyDetails”.
Step5:Create objects for your tables and four textfields and One
button
Step6:Add the tables and textboxes and button in the frame my
details.
Step7:If the clickbutton,displaythename,street,cityand pincode
for the corresponding file.
Step8:Run and execute theprogram.
Step 9: Display the result.
Step10:Stoptheprocess.
24
CODING:
import java.awt.*;
importjava.awt.event.*;
class Prg6 extends Frame implements ActionListener
Button b1,b2;
Labell1,l2,l3,l4;
TextFieldt1,t2,t3,t4;
Prg6()
setBounds(100,100,500,400);
set Layout(newFlowLayout());
l1=new Label("NAME");
l2=new Label("STREET");
l3=new Label("CITY");
l4=new Label("PINCODE");
t1=new TextField(10);
25
t2=new TextField(10);t3=new
TextField(10);t4=new
TextField(10);
b1=newButton("MyDetails");
b2=new Button("Exit");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(b1);
add(b2);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
26
}
public void action Performed(ActionEvent e)
if(e.getSource()==b1)
t1.setText("SAKTHI");
t2.setText("SIVANAGAR");
t3.setText("ERODE");
t4.setText("638011");
if(e.getSource()==b2)
System.exit(0);
}}
public static void main(String arg[])
newPrg6();
27
}
28
OUTPUT:
RESULT:
29
MULTIPLE SELECTION
Ex.No:7
Date:
AIM:
ALGORITHM:
Step1: Start the process.
Step2:Import the necessary file.
Step3:Declare the class extends applet.
Step4:Declaretheobjectforsixlistboxandpopularlist.
Step5: Add list box view in applet window.
Step6:Selectlistindexviewedinmyqualification.
Step7: Execute the program and display the result.
Step8: Stop the process.
30
CODING:
import java.awt.*;
import java.awt.event.*;
class Prg7 extends Frame implements ActionListener
List l;
Button b;
Prg7()
super(“MULTIPLESELECTION
LISTBOX”);
set Layout(new Flow Layout(1));
b=new Button("Exit");
l=new List(4,true);
l.add("SAKTHI");
l.add("SHIVA");
l.add("VELLU");
l.add("AFRITH");
31
add(l);
add(b);
b.addActionListener(this);
public void action Performed(ActionEvente)
if((e.getAction Command()).equals("Exit"));
System.exit(0);
}}
public static void main(Stringarg[])
Prg7 s=newPrg7();
s.setSize(800,600);
s.setVisible(true);
}
}
32
OUTPUT:
RESULT:
33
TEXT DEMO
Ex.No:8
Date:
AIM:
ALGORITHM:
Step 1:Start the process.
Step2:Import the necessary files.
Step 3:Declare the class extends applet.
Step4:Create a newframe and the set the fields in“multiple
lines” for address.
Step5:Create a newobjects for four label.
Step6:Create the current tables and address in the current text
fields.
Step7:Add keywords on window listener on winadapter.
Step 8: Execute the program and display the result.
Step 9:Stop the process.
34
CODING:
import java.awt.*;
import java.awt.event.*;
class Prg8extends Frame implements ActionListener
Button b1;
Label l1,l2,l3,l4;
TextField t1;
TextArea ta;
Prg8()
setBounds(100,100,500,50
0);
setLayout(null);
l1=newLabel("Name");
l2=new Label("Age");
35
l3=newLabel("Qualificatio
n");
l4=newLabel("Address");
t1=newTextField("\n java
\n 20\n bsc");
ta=newTextArea("\n\tD-169\n\tSampathNagar\n\t\n\tErode-
638411");
b1=newButton("Exit");
add(b1);
add(l1);
add(l2);
add(l3);
add(l4);
add(t1);
add(ta);
b1.add ActionListener(thi
s);
36
l1.setBounds(50,50,80,2
0);
l2.setBounds(50,75,80,2
0);
l3.setBounds(50,100,80,
20);
l4.setBounds(50,125,80,
20);
t1.setBounds(200,50,80,
20);
ta.setBounds(200,125,10
0,1000);
b1.setBounds(110,250,8
0,20);
show();
public void actionPerformed(Action Evente)
if(e.getSource()==b1
)
37
{
System.exit(0);
public static void main(Stringarg[])
newPrg8();
38
OUTPUT:
RESULT:
39
MENU BAR AND PULLDOWN MENUS
Ex.No:9
Date:
AIM:
ALGORITHM:
Step 1:Start the process.
Step2:Import the necessaryfiles.
Step3:Declare the class extends applet implements
Actionlistener.
Step4:Create the buttonas”display the menu window”
Step 5: Add the listener to the button.
Step6:When the button is clicked thefilemenu,file
Corresponding text down on applet.
Step7:Execute the program and displaytheresult.
Step 8: Stop the process.
40
CODING:
import java.awt.*;
import java.awt.event.*;
class Menu Demo extends Frame implements ActionListener
Menu m1,m2,m3;
String str;
MenuDemo()
Menu Bar mb=new MenuBar();
setMenuBar(mb);
m1=newMenu("Fruit");
m2=new Menu("Car");
m3=new Menu("Bike");
mb.add(m1);
mb.add(m2);
mb.add(m3);
m1.add(new Menu Item("Apple"));
41
m1.add(new Menu Item("Orange"));
m1.add(new Menu Item("Banana"));
m2.add(new Menu Item("Audi"));
m2.add(new Menu Item("Susiki"));
m3.add(new Menu Item("Honda"));
m3.add(new Menu Item("Yamaha"));
m3.add(new MenuItem("Starcity"));
m1.addActionListener(this);
m2.addActionListener(this);
m3.addActionListener(this);
setTitle("Simple MenuDemo");
setSize(400,400);
setVisible(true);
public void action Performed(ActionEvente)
str="you selected"+e.getAction Command();
repaint();
42
}
public void paint(Graphics g)
g.draw String(str,200,200);
class Menu Demo2
public static void main(String arg[])
new Menu Demo();
43
OUTPUT:
RESULT:
44
MOUSE DEMO
Ex.No:10
Date:
AIM:
ALGORITHM:
Step 1:Start the process.
Step2:Import the necessaryfiles.
Step3:Declare the class and implements the class mouse
listener mouse motion listener.
Step4:Write the necessary methods
Step5:When the mouse pressed the corresponding action to be
performed
Step6:Similarly mouse down,mouse click,mouse entered
Step 7: Execute the program and display the result
Step8:Stop the process
45
CODING:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class prg10 extends Applet implements
MouseListener,MouseMotionListener
TextField t;
public void init()
Frame f=new Frame("click");
t=new TextField(20);
f.setLayout(new FlowLayout());
f.add(t);
f.show();
f.setSize(400,400);
f.addMouseListener(this);
46
public void mousePressed(MouseEvente)
if((e.getModifiers()&InputEvent.BUTTON1_MASK)==InputEvent.B
UTTON1_MASK)
t.setText("Left Mouse button down at"+e.getX()+""+e.getY());
else
t.setText("Right Mouse button down at"+e.getX()+""+e.getY());
public void mouseClicked(Mouse Evente)
t.setText("You click at"+e.getX()+""+e.getY());
public void mouseReleased(MouseEvente)
47
t.setText("mouse went up");
public void mouseDragged(MouseEvente)
t.setText("mouse was Dragged");
public void mouseMoved(MouseEvente)
t.setText("mouse was Moved");
public void mouse Entered(MouseEvente)
t.setText("mouse was Entered");
public void mouse Exited(MouseEvente)
t.setText("mouse was Exited");
48
}
HTMLCODING:
<html>
<head>
</head>
<body>
<appletcode="prg10.java"Height="250"Width="300">
</applet>
</body>
</html>
49
OUTPUT:
RESULT:
50
DRAW SHAPES IN MOUSE CLICK POSITION
Ex.No:11
Date:
AIM:
ALGORITHM:
Step 1:Start the process
Step2:Import the necessary files
Step3:Declare the class extends applet implements
actionlistener
Step4:Declare the necessary variable to the class
Step5:Add the mouse listener when the mouseclicked we get
the corresponding x,y values
Step6:Based on mouseclick position the shapes displayed
Particular position
Step7:Run and verifytheprocess
Step 8: Stop the process
51
CODING:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public classprg11extends Applet
intx=150;
int y=15;
publicvoidinit()
add MouseListener(newMouseAdapter()
public void MouseClicked(MouseEvente)
repaint();
x=e.getX();
y=e.getY();
}
52
});
public void paint(Graphics g)
g.drawRect(x,y,100,300);
g.drawRect(x+50,y=67,100,150);
g.drawOval(x=100,y=60,100,100);
g.drawOval(x,y+150,170,150);
HTMLCODING:
<html>
<head>
</head>
<body>
<appletcode="Prg11.java"Height="250"Width="300">
</applet>
53
</body>
</html>
54
OUTPUT:
RESULT:
55
APPEND TEXT IN A FILE
Ex.No:12
Date :
AIM:
ALGORITHM:
Step 1:Start the process
Step2:Import the necessaryfiles
Step 3:Create the class named as prg12
Step4:Create the randomaccess file named as”prg12.txt”and
write the necessary to that file
Step5:Open an existing file and append our own content to
that file
Step6:Using the function append our own content to that file
Step 7: Execute the program and display the result
Step8:Stop the process
56
CODING:
import java.io.*;
class Prg12
public static voidmain(String args[])throws IOException
Random Access File r=new RandomAccessFile("Random.txt","rw");
r.write Char('a');
r.write Int(12345);
r.writeDouble(12.345678);
r.seek(0);
System.out.println(r.readChar());
System.out.println(r.readInt());
System.out.println(r.readDouble());
r.seek(2);
System.out.println(r.readInt());
r.seek(0);
57
System.out.println(r.readChar());
r.seek(r.length());
r.writeBoolean(true);
r.seek(4);
System.out.println(r.readBoolean());
r.close();
58
OUTPUT:
D:\jdk1.4\bin>javacprg12.java
D:\jdk1.4\bin>java prg12
12345
12.345678
12345
true
RESULT:
59