0% found this document useful (0 votes)
3 views59 pages

25PMCA21 - Java Practical

The document is a record notebook for the Java Programming Lab course at the School of Computing Sciences for the M.C.A. program during the academic year 2025-2026. It includes a certification section, an index of practical exercises, and detailed descriptions of various Java programs covering topics such as addition, multiplication, simple interest, and object-oriented programming concepts. Each exercise includes the aim, procedure, coding, output, and result of the program executed.

Uploaded by

h9686711
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)
3 views59 pages

25PMCA21 - Java Practical

The document is a record notebook for the Java Programming Lab course at the School of Computing Sciences for the M.C.A. program during the academic year 2025-2026. It includes a certification section, an index of practical exercises, and detailed descriptions of various Java programs covering topics such as addition, multiplication, simple interest, and object-oriented programming concepts. Each exercise includes the aim, procedure, coding, output, and result of the program executed.

Uploaded by

h9686711
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

SCHOOL OF COMPUTING SCIENCES

DEPARTMENT OF COMPUTER APPLICATIONS-PG

25PMCA21 - JAVA PROGRAMMING LAB

RECORD NOTE BOOK

2025 - 2026

M.C.A.-MASTER OF COMPUTER APPLICATIONS

First Year – II Semester

NAME :
REG. NO :

April 2026
DEPARTMENT OF COMPUTER APPLICATIONS-PG

CERTIFICATE
Certified that this is a bonafide record of practical work done by
Mr./Ms.________ _____ . [Link]. _______________ in
the M.C.A.-(Master of Computer Application) Laboratory during the Year
2025-2026.

STAFF IN-CHARGE HEAD OF THE DEPARTMENT

Submitted for M.C.A., Degree practical examination held on _____ ___


in the Department of Computer Applications-PG at VISTAS.
Examiners
DATE : 1.
PLACE : Chennai-600117
2.
INDEX

[Link]. DATE CONTENTS PAGE NO. SIGNATURE


SIMPLE PROGRAMS

A. ADDITION OF TWO
12-01-2026 1
NUMBERS
B. PRODUCT OF THREE
19-01-2026 NUMBERS
2

1 22-01-2026 C. SIMPLE INTEREST 3

D. CONVERISON OF
29-01-2026 5
CENTIGRADE TO FARENHEIT

E. CONVERSION OF
02-02-2026 FARENHEIT TO CENTIGRADE
7

2 09-02-2026 FACTORIAL OF A NUMBER 9

IMPLEMENTATION OF A
3 16-02-2026
CLASS USING INTERFACE
11

SUM AND AVERAGE OF


4 20-02-2026
NUMBERS USING ARRAY
13

5 23-02-2026 PALINDROME 15

6 26-02-2026 CONSTRUCTOR 17

METHOD OVERLOADING

A. CHANGING NUMBER OF
02-03-2026 19
7 ARGUMENTS

B. CHANGING THE DATA


06-03-2026 TYPE OF THE ARGUMENTS
21

8 09-03-2026 INHERTANCE 23

9 12-03-2026 METHOD OVERRIDING 26

ABSTRACTION
10 A. ABSTRACTION USING AN
16-03-2026 28
ABSTRACT CLASS
B. ABSTRACTION USING
20-03-2026 30
INTERFACE

11 23-03-2026 MULTITHREADING 32

12 27-03-2026 THREAD PRIOPRITY 35

EXCEPTION HANDLING
13 02-04-2026 ARITHMETIC EXCEPTION
37

APPLET PROGRAMMING

06-04-2026 LIFECYCLE OF APPLET 38

10-04-2026 PARAMETER PASSING 40


14
13-04-2026 DRAWING SHAPES 42

17-04-2026 THREE CIRCLES 44

17-04-2026 CONCENTRIC CIRCLES 46

NETWORK PROGRAMMING

18-04-2026 SOCKET PROGRAMMING 48

15 18-04-2026 COMPONENTS OF URL 50

READING CONTENTS OF
18-04-2026 51
WEBSITES USING URL CLASS

CALCULATOR APPLICATION
16 18-04-2026 USING SWING COMPONENTS
53
1

Ex. No. 01(A)


ADDITION OF TWO NUMBERS
Date:12-01-2026

AIM: To add two given numbers in a java program.

PROCEDURE:

Step 1: Start the program.


Step 2: Declare two variables a & b and store two values in it.
Step 3: Calculate the sum using the formula: sum = a+b.
Step 4: Display the result (the sum).
Step 5: End the program.

CODING:

class Add
{
public static void main (String args[])
{
int a = 10, b =
20, sum; sum =
a + b;
[Link]("Sum of " +a+ " and " +b+ " is " +sum);
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


2

Ex. No. 01(B)


PRODUCT OF THREE NUMBERS
Date:19-01-2026

AIM: To find the product of three given numbers using java.

PROCEDURE:

Step 1: Start the program.


Step 2: Declare three variables to store three numbers a,b,c. Declare one more variable
product.
Step 3: Assign values to the variables.
Step 4: Calculate the product using the formula: product = a × b ×c.
Step 5: Display the result (the product).
Step 6: End the program.

CODING:

class Product1
{
public static void main(String args[])
{
int a = 3, b = 5, c = 8, product;
product = a*b*c;
[Link]("Product of " +a+ ", " +b+ " and " +c+ " is " +product);
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


3

Ex. No. 01(C)


SIMPLE INTEREST
Date:22-01-2026

AIM: To calculate the simple interest of the given principle amount, number of years and

rate of interest using java program.

PROCEDURE:

Step 1: Start the program and import the required package [Link] to read input

from the user.

Step 2: Declare the class SimpleInterest and define the main() method. Declare variables

p, n, r, and si of type double.

Step 3: Create a Scanner object to accept input from the user through the keyboard.

Step 4: Get the principal amount, number of years, and rate of interest from the user using

nextDouble() method.

Step 5: Calculate the simple interest using the formula

SI = (P × N × R) / 100 and display the result using [Link]().

Step 6: Stop the program.


4

CODING:

import [Link].*;
class SimpleInterest1
{
public static void main(String args[])
{
double p,n,r,si;
Scanner sc=new Scanner([Link]);
[Link]("Enter the principle amount:");
p = [Link]();
[Link]("Enter the [Link] years:");
n = [Link]();
[Link]("Enter the rate of interest:");
r = [Link]();
si = (p*n*r)/100;
[Link]("Simple Interest=" +si);
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


5

Ex. No. 01(D) CONVERISON OF CENTIGRADE TO


Date:29-01-2026 FARENHEIT

AIM: To convert a given value of celcius to farenheit using java program.

PROCEDURE:

Step 1: Start the program and import the package [Link] to take input from the

user.

Step 2: Declare the class Farenheit and create the main() method. Declare two variables

c and f of type double.

Step 3: Create a Scanner object sc to read input from the keyboard.

Step 4: Ask the user to enter the temperature in Celsius and read the value using

[Link]().

Step 5: Convert Celsius to Fahrenheit using the formula

F = (C × 9/5) + 32 and display the result using [Link]().

Step 6: Stop the program.

CODING:

import [Link];
class Fahrenheit1
{
public static void main(String args[])
{
double c,f;
Scanner sc=new Scanner([Link]);
[Link]("Enter the value of celcius:");
c = [Link]();
f = (c * 9.0/5) + 32;
[Link]("Fahrenheit = " +f);
}
}
6

OUTPUT:

RESULT: Thus the program has been executed successfully.


7

Ex. No. 01(E) CONVERSION OF FARENHEIT TO


Date:02-02-2026 CENTIGRADE

AIM: To convert a given value of farenheit to centigrade using java program.

PROCEDURE:

Step 1: Start the program and import the package [Link] to read input

from the user.

Step 2: Declare the class Celcius and define the main() method. Declare two

variables c and f of type double.

Step 3: Create a Scanner object sc to get input from the keyboard.

Step 4: Ask the user to enter the temperature in Fahrenheit and read the value using

[Link]().

Step 5: Convert Fahrenheit to Celsius using the formula

C = (F − 32) × 5/9 and display the result using [Link]().

Step 6: Stop the program.

CODING:

import [Link];
class Celsius1
{
public static void main(String args[])
{
double c,f;
Scanner sc=new Scanner([Link]);
[Link]("Enter the value of farenheit:");
f = [Link]();
c = (f - 32) * 5.0/9 ;
[Link]("Celsius = " +c);
}
}
8

OUTPUT:

RESULT: Thus the program has been executed successfully.


9

Ex. No. 02
FACTORIAL OF A NUMBER
Date:09-02-2026

AIM: To write a Java program to find the factorial of a given number.

PROCEDURE:

Step 1: Start the program.


Step 2: Import the Scanner class and create a Scanner object.
Step 3: Declare variables n, i, and fact, and initialize fact = 1.
Step 4: Get the input number n from the user.
Step 5: Use a for loop from i = 1 to n and calculate fact = fact * i.
Step 6: Display the factorial value.
Step 7: Stop the program

CODING:

import [Link];
class Factorial
{
public static void main(String args[])
{
int fact,i,n;
fact=1;
Scanner s=new Scanner([Link]);
[Link]("Enter a number"); n=[Link]();
for(i=1;i<=n;i++)
{
fact=fact*i
}
[Link]("Factorial of the given number is " +fact);
}
}
10

OUTPUT:

RESULT: Thus the program has been executed successfully.


11

Ex. No. 03 IMPLEMENTATION OF A CLASS USING


Date:16-02-2026 INTERFACE

AIM: To illustrate the concept of implementation of class using java.

PROCEDURE:

Step 1: Define a class with the classkeyword and give it a name.


Step 2: Inside the class, declare the attributes (fields) that represent the properties of the
object.
Step 3: Define a constructor to initialize the object with values for its attributes.
Step 4: Create methods (functions) inside the class that define the behavior of the object
(e.g., actions it can perform).
Step 5: Create an object of the class in the main()method to use the class and its methods.

CODING:

class StudentMark
{
public static void main(String args[])
{
Student s1=new Student();
[Link](123,"Raja",75,88,90);
[Link]();
[Link]();
Student s2=new Student();
[Link](124,"Harini",85,98,90);
[Link]();
[Link]();
Student s3=new Student();
[Link](125,"Brindha",99,96,80);
[Link]();
[Link]();
}
}
class Student
{
int rno;
String Stname;
int m1,m2,m3,total;
double avg;
void getData(int no, String name,int x,int y, int z)
{
12

rno=no; Stname=name;
m1=x;
m2=y;
m3=z;
}
void calculate()
{
total=m1+m2+m3; avg=total/3.0;
}
void display()
{
[Link]("Reg no: " +rno);
[Link]("Name: " +Stname);
[Link]("Mark1: " +m1);
[Link]("Mark2: " +m2);
[Link]("Mark3: " +m3);
[Link]("Total: " +total);
[Link]("Average: " +avg);
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


13

Ex. No. 04 SUM AND AVERAGE OF NUMBERS USING


Date:20-02-2026 ARRAY

AIM: To write a java program to find the sum and average of n numbers.

PROCEDURE:

Step 1: Start the program.


Step 2: Declare an array to store the N numbers.
Step 3: Input the value of N (the number of elements).
Step 4: Input the N numbers and store them in the array.

Step 5: Calculate the sum of the numbers by iterating through the array.
Step 6: Calculate the average using the formula: average = sum / N
Step 7: Display the sum and average.
Step 8: End the program.

CODING:

import [Link];
public class Arraysum
{
public static void main(String args[])
{
int
n,sum=0;
float avg;
Scanner s=new Scanner([Link]);
[Link]("Enter limit of array:");
n=[Link]();
int a[]=new int[n];
[Link]("Enter all the elements:");
for(int i=0;i<n;i++){
a[i]=[Link](); }
for(int i=0;i<n;i++)
{sum=sum+a[i]; avg=sum/n;}
14

[Link]("Sum="+sum);
[Link]("Average="+avg);
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


15

Ex. No. 05
PALINDROME
Date:23-02-2026

AIM: To generate and check whether the given word is a palindrome or not using java
program.

PROCEDURE:

Step 1: Start the program.


Step 2: Declare a variable to store the input string.
Step 3: Input the string.
Step 4: Reverse the string. This can be done by iterating over the string from the end to
the start.
Step 5: Compare the original string with the reversed string.
• If both are the same, it is a palindrome.
• If both are different, it is not a palindrome.
Step 6: Display the result (whether the string is a palindrome or not).
Step 7: End the program.

CODING:

import [Link].*;
class Palindrome
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner([Link]);
[Link]("Enter a string/number to check if it is a palindrome");
original = [Link]();
int length = [Link]();
for ( int i = length - 1; i >= 0; i-- ) {
reverse = reverse + [Link](i);
}
if ([Link](reverse)) {
16

[Link](original +" is a palindrome.");


}
else
[Link](original +" isn't a palindrome.");
}
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


17

Ex. No. 06
CONSTRUCTOR
Date:26-02-2026

AIM: To write a Java program to create an employee class, initialize objects using a
constructor, and display employee details.

PROCEDURE:

Step 1:Start the program.

Step 2:Create a class (e.g., Employee) with data members to store object information.

Step 3: Define a constructor in the class with parameters to initialize the data members.

Step 4:Define a method (e.g., info()) to display the object details.

Step 5: Inside the main() method, create objects of the class and pass values to the

constructor.

Step 6: Call the method (e.g., info()) on each object to display details.

Step 7: Ensure all object data is correctly displayed.

Step 8: End the program.

CODING:

class Employee {
int empid;
String empName;
Employee(int id, String name)
{
[Link]=id;
[Link]=name;
}
void info() {
[Link]("ID: "+empid+ "Name: "+empName);
}
public static void main(String args[]) {
Employee obj1=new Employee(10245,"Chaitanya");
Employee obj2=new Employee(92232,"Negan");
[Link]();
[Link]();
}
}
18

OUTPUT:

RESULT: Thus the program has been executed successfully.


19

Ex. No. 07(A) METHOD OVERLOADING


Date:02-03-2026 CHANGING NUMBER OF ARGUMENTS

AIM: To implement the concept of method overloading by changing the number of arguments.

PROCEDURE:

Step 1: Define the Class


Create a class where you will define the overloaded methods.
Step 2: Create Methods with the Same Name
Define multiple methods with the same name but different number of arguments.
Each method should perform a similar operation, but they may differ in how many
arguments they take.
Step 3: Use Different Numbers of Arguments
Overload methods by varying the number of parameters in the method signature.
For example, one method could take two arguments, while another could take
three.
Step 4: Implement the Method Logic
In each overloaded method, implement the logic that you want to perform. The
methods may differ in how they process the arguments due to the number or type
of parameters.
Step 5: Call the Overloaded Methods
In the main method (or another class), create objects of the class and call the
overloaded methods with different arguments. The Java compiler will
automatically choose the correct method based on the number and type of
arguments passed.
20

CODING:

class Adder
{
static int add(int a,int b)
{
return a+b;
}
static int add(int a,int b,int c)
{
return a+b+c;
}
}
class MethodOverloading
{
public static void main(String args[])
{
[Link]([Link](11,11)); [Link]([Link](11,11,11));
}
}
OUTPUT:

RESULT: Thus the program has been executed successfully.


21

Ex. No. 07(B) CHANGING THE DATA TYPE OF THE


Date:06-03-2026 ARGUMENTS

AIM: To implement the concept of method overloading by changing the datatype of


arguments.

PROCEDURE:

Step 1: Define a class where the overloaded methods will be created.

Step 2: Create methods with the same name but different argument data types.

Step 3: Overload the methods by changing the data type of the arguments.

Step 4: Implement the method logic based on the data types of the arguments.

Step 5: In the main method, create an object and call the overloaded methods
with different argument types.

CODING:

class Adder
{
static int add(int a,int b)
{
return a+b;
}
static double add(double a,double b)
{
return a+b;
}
}
class MethodOverloading1
{
public static void main(String args[])
{
[Link]([Link](11,11)); [Link]([Link](12.3,12.6));
}
}
22

OUTPUT:

RESULT: Thus the program has been executed successfully.


23

Ex. No. 08
INHERTANCE
Date:09-03-2026

AIM: To implement inheritance for calculating the gross pay and net pay for employees
using java.

PROCEDURE:

Step 1: Define a base (parent) class that will contain common attributes and methods.
Step 2: Create a derived (child) class that extends the base class.
Step 3: In the child class, you can inherit the methods and variables from the parent class.
Step 4: Optionally, you can override methods in the child class to provide specific behavior.
Step 5: In the main method, create an object of the child class and access the inherited methods
and attributes.

CODING:

class Inheritance
{
public static void main(String args[])
{
pay p1=new pay();
[Link](101,"Saravanan","Manager");
[Link](45000);
[Link]();
[Link]();
[Link]();
pay p2=new pay();
[Link](102,"Hubert","General Manager");
[Link](400000);
[Link]();
[Link]();
[Link]();
}
}
class employee
{
int empid;
String name;
String desig;
void getdetails(int e, String s, String d)
{
empid = e;
name = s;
desig = d;
24

}
void putdetails()
{
[Link]("Empid:"+empid);
[Link]("Name:"+name);
[Link]("Designation:"+desig);
}
}
class pay extends employee
{
double bp;
double hra;
double da;
double pf;
double grosspay;
double netpay;
void getpay(double p)
{
bp=p;
}
void calculate()
{
da = bp * 120/100;
hra = bp * 20/100;
pf = bp * 12/100;
grosspay = bp + hra + da;
netpay = grosspay - pf;
}
void display()
{
[Link]("Basic Pay: "+bp);
[Link]("DA: "+da);
[Link]("HRA: "+hra);
[Link]("PF: "+pf);
[Link]("Gross Pay: "+grosspay);
[Link]("Net Pay: "+netpay);
}
}
25

OUTPUT:

RESULT: Thus the program has been executed successfully.


26

Ex. No. 09
METHOD OVERRIDING
Date:12-03-2026

AIM: To implement the concept of method overriding using java.

PROCEDURE:

Step 1: Define a parent (Animal) class with a method that you want to override
in the child class.
Step 2: Create a child (Dog) class that extends the parent class.
Step 3: In the child class, define a method with the same signature as the one in the
parent class.
Step 4: Implement the logic in the child class method, which replaces the behavior
of the parent class method.
Step 5: In the main method, create an object of the child class and call the
overridden method.

CODING:

class Animal{
public void displayinfo(){
[Link]("I am an animal.");
}
}
class Dog extends Animal
{
public void displayinfo(){
[Link]("I am a dog.");
}
}
class Main{
public static void main(String args[])
{
Dog d1=new Dog();
[Link]();
}
}
27

OUTPUT:

RESULT: Thus the program has been executed successfully.


28

Ex. No. 10(A) ABSTRACTION


Date:16-03-2026 ABSTRACTION USING AN ABSTRACT CLASS

AIM: To implement the concept of abstraction using an abstract class.

PROCEDURE:

Step 1: Define an abstract class (SHAPE) with the abstract keyword.


Step 2: Create abstract methods(DRAW) in the abstract class
Step 3: Create a subclass(RECTANGLE) and (CIRCLE) that extends the abstract
class.

Step 4: In the subclass, implement the abstract methods from the abstract class
with the required logic.
Step 5: In the main method, create an object of the subclass and call the
implemented methods.

CODING:

abstract class Shape


{
abstract void draw();
}
class Rectangle extends Shape
{
void draw()
{
[Link]("Drawing Rectangle");
}
}
class Circle1 extends Shape
{
void draw()
{
[Link]("Drawing Circle");
}
29

}
class Abstraction
{
public static void main(String args[])
{
Shape s=new
Circle1(); Shape
s1=new Rectangle();
[Link]();
[Link]();
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


30

Ex. No. 10(B)


ABSTRACTION USING INTERFACE
Date:20-03-2026

AIM: To implement the concept of abstraction using an interface.

PROCEDURE:

Step 1: Define an interface using the interface keyword, which can only contain abstract
methods (methods without a body).
Step 2: Create methods in the interface that represent the behaviors that classes
implementing the interface must define.
Step 3: Create a class that implements the interface using the implements keyword.
Step 4: In the implementing class, provide the method implementations for all abstract
methods declared in the interface.
Step 5: In the main method, create an object of the implementing class and call the
methods defined in the interface.

CODING:

class Main1
{
public static void main(String args[])
{
Rectangle r1=new Rectangle();
[Link](5,6);
}
}
interface Polygon
{
void getArea(int length, int breadth);
}
class Rectangle implements Polygon
{
public void getArea(int length, int breadth)
31

{
[Link]("The area of a rectangle is " +(length*breadth));
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


32

Ex. No. 11
MULTITHREADING
Date:23-03-2026

AIM: To implement the concept of multi threading using java.

PROCEDURE:

Step 1: Define a class that extends the Thread class or implements the Runnable interface.
Step 2: Override the run() method in the class to define the code that will execute in the
thread.
Step 3: Create an instance of the class (either Thread or Runnable) in the main method.
Step 4: Start the thread using the start() method to invoke the run() method concurrently.
Step 5: Optionally, manage multiple threads by using [Link]() or other
synchronization mechanisms to ensure proper execution.

CODING:

class ThreadTest
{
public static void main(String args[])
{
A t1 = new A();
B t2 = new B();
C t3 = new C();
try
{
[Link]();
[Link](); // wait until A finishes
[Link]();
[Link](); // wait until B finishes
[Link](); // C starts only after B exits
}
catch(Exception e)
{
[Link](e);
33

}
}
}
class A extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
[Link]("\t From thread A :=" + i);
}
[Link]("Exit from A");
}
}
class B extends Thread
{
public void run()
{
for(int j=1;j<=5;j++)
{
[Link]("\t From thread B:= " + j);
}
[Link]("Exit from B");
}}
class C extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
[Link]("\t From thread C:= " + k);
}
[Link]("Exit from C");
}}
34

OUTPUT:

RESULT: Thus the program has been executed successfully.


35

Ex. No. 12
THREAD PRIOPRITY
Date:27-03-2026

AIM: To implement the concept of thread priority in multi-threading using java.

PROCEDURE:

Step 1: Start the program.


Step 2: Create a class that extends the Thread class or implements the Runnable
interface.
Step 3: Override the run() method to define the task the thread will perform.
Step 4: Set the thread priority using the setPriority() method. Thread priorities range
from Thread.MIN_PRIORITY (1) to Thread.MAX_PRIORITY (10), with the
default being Thread.NORM_PRIORITY (5).
Step 5: Create an instance of the thread class and set the desired priority using the
setPriority() method.
Step 6: Start the thread using the start() method. The thread with higher priority is given
preference by the scheduler, but it is not guaranteed to execute first.
Step 7: End the program.

CODING:

class thrun implements Runnable


{
Thread t;
thrun(String st, int p)
{
t = new Thread(this, st);
[Link](p);
[Link]();
}
public void run()
{
[Link]("Thread name: " + [Link]());
[Link]("Thread priority: " + [Link]());
}
}
class Priority1
{
public static void main(String args[])
{
36

[Link]().setPriority(Thread.MAX_PRIORITY);
thrun t1 = new thrun("Thread1", Thread.NORM_PRIORITY + 2);
thrun t2 = new thrun("Thread2", Thread.NORM_PRIORITY - 2);
[Link]("Main Thread: " + [Link]());
[Link]("Main Thread Priority: " +
[Link]().getPriority());
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


37

Ex. No. 13 EXCEPTION HANDLING ARITHMETIC


Date:02-04-2026 EXCEPTION

AIM: To illustrate the concept of Exception Handling in java program.

PROCEDURE:

Step 1: Define a block of code where an exception might occur, such as dividing by
zero or performing an invalid arithmetic operation.
Step 2: Use a try block to write the code that might throw an ArithmeticException.
Step 3: Catch the exception using a catch block to handle the error gracefully.
The catch block will specify the type of exception,such as
ArithmeticException.
Step 4: Inside the catch block, implement the code to handle the exception
(e.g., displaying an error message or providing an alternative action).
Step 5: Optionally, use a finally block to execute code that should run whether
or not an exception was thrown (e.g., closing resources).

CODING:

class JavaException1{
public static void main(String args[]){
try{
int d=0,n=20;
int fraction=n/d;
}catch(ArithmeticException e){
[Link]("In the catch block due to Exception = " +e);}
[Link]("End of Main");
}}

OUTPUT:

RESULT: Thus the program has been executed successfully.


38

Ex. No. 14(A) APPLET PROGRAMMING


Date:06-04-2026 LIFECYCLE OF APPLET

AIM: To illustrate the concept of applet using java program.

PROCEDURE:

Step 1: Initialization (init() method)


The init() method is called once when the applet is first loaded. It is used to
initialize the applet, such as setting up resources and initializing variables.
Step 2: Start (start() method)
The start() method is called after init() and whenever the applet becomes visible or
active. It is used to start any animation or threads.
Step 3: Paint (paint() method)
The paint() method is called whenever the applet needs to be redrawn (e.g., when
the window is resized or the applet is exposed after being hidden). It is used to
display content on the applet’s graphical interface.
Step 4: Stop (stop() method)
The stop() method is called when the applet is no longer visible or active. It is used
to stop any activities that should not continue while the applet is inactive (such as
stopping threads or animations).
Step 5: Destroy (destroy() method)
The destroy() method is called when the applet is unloaded. It is used for clean-up,
such as releasing resources (e.g., closing files, stopping background processes).

CODING:

import [Link].*;
import [Link].*;
public class SampleApp extends Applet
{
public void paint(Graphics g)
{
[Link]("Welcome to Java Applet",400,200);
39

}
}
/*<applet code="[Link]" WIDTH="500" HEIGHT="500">
</applet> */

OUTPUT:

APPLET VIEWER:

RESULT: Thus the program has been executed successfully.


40

Ex. No. 14(B)


PARAMETER PASSING
Date:10-04-2026

AIM: To pass parameters with the concept of Applet in java.

PROCEDURE:

Step 1: Define the Applet Class


Create a class that extends Applet or JApplet and override the init() method to
initialize the applet.
Step 2: Use Tag in HTML
In the HTML file (or applet viewer), use the tag to pass parameters to the applet.
These parameters are passed as key-value pairs within the <applet> tag
Step 3: Retrieve Parameters in Applet
In the applet's init() method, use the getParameter() method to retrieve the
parameters. The getParameter(String name) method retrieves the value of a
parameter based on its key.
Step 4: Use the Retrieved Parameters
After retrieving the parameters in the applet, use them to modify the applet's
behavior, such as changing the display, text, or other functionalities
Step 5: Handle Missing Parameters
Handle cases where the expected parameters may not be provided by checking for
null values when calling getParameter(). You can provide default values if
necessary.

CODING:

import [Link].*;
import [Link].*;
/*
<applet code="ParamDemo" width="300" height="300">
<param name="A" value="20">
<param name="B" value="30">
</applet> */
41

public class ParamDemo extends Applet


{
int x,y,sum;
public void init()
{
x=[Link](getParameter("A"));
y=[Link](getParameter("B"));
}
public void paint(Graphics g)
{
sum=x+y;
[Link]("Total Sum is "+sum,100,100);
}
}

OUTPUT:

APPLET VIEWER:

RESULT: Thus the program has been executed successfully.


42

Ex. No. 14(C)


DRAWING SHAPES
Date:13-04-2026

AIM: To draw different shapes in applet using java.

PROCEDURE:

Step 1: Create a class that extends Applet and override the paint() method.
Step 2: Use the Graphics object provided in the paint() method.
Step 3: Use drawing methods like drawLine(), drawRect(), drawOval(), etc. to draw
shapes.
Step 4: Specify the shape's coordinates and dimensions in the drawing methods.
Step 5: Compile and run the applet to see the shapes drawn in the applet window.

CODING:

import [Link];
import [Link].*;
public class GraphicsDemo extends Applet
{
public void paint(Graphics g)
{
[Link]([Link]);
[Link]("Welcome",50,50);
[Link]([Link]);
[Link](20,30,20,300);
[Link](70,100,30,30);
[Link](170,100,30,30);
[Link](70,200,30,30);
[Link]([Link]);
[Link](170,200,30,30);
}}
/* <applet code="[Link]" width="300" height="300">
</applet> */
43

OUTPUT:

APPLET VIEWER:

RESULT: Thus the program has been executed successfully.


44

Ex. No. 14(D)


THREE CIRCLES
Date:17-04-2026

AIM: To display three circles in an applet using java.

PROCEDURE:

Step 1: Create a class that extends Applet and override the paint() method.
Step 2: Inside the paint() method, use the Graphics object to draw three circles using the
drawOval() method.
Step 3: Set different positions and sizes for each circle by adjusting the parameters of
the drawOval() method.
Step 4: Compile the applet and run it to display the circles in the applet window.

CODING:

import [Link];
import [Link];
import [Link];
public class ThreeCircleApplet extends Applet {
public void paint(Graphics g) {
//First circle filled with BLUE color
[Link]([Link]);
[Link](50,50,50,50);
//First circle filled with GREEN color
[Link]([Link]);
[Link](50,100,50,50);
//First circle filled with YELLOW color
[Link]([Link]);
[Link](50,150,50,50);
}
}
/*<applet code="ThreeCircleApplet" width=200 height=250>
</applet>*/
45

OUTPUT:

APPLET VIEWER:

RESULT: Thus the program has been executed successfully.


46

Ex. No. 14(E)


CONCENTRIC CIRCLES
Date:17-04-2026

AIM: To display concentric circles in applet using java.

PROCEDURE:

Step 1: Create a class that extends Applet and override the paint() method.
Step 2: Inside the paint() method, use the Graphics object to draw multiple circles using
drawOval() method.
Step 3: For concentric circles, ensure all circles have the same center but different radii
(sizes).
Step 4: Adjust the circle’s dimensions by changing the width and height parameters in
drawOval().
Step 5: Compile and run the applet to display concentric circles in the applet window.

CODING:

import [Link].*;
import [Link].*;

public class ConcentricCircles extends Applet


{
public void paint(Graphics g)
{
[Link]([Link]);
[Link](20,20,45,45);
[Link]([Link]);
[Link](10,10,65,65);
[Link]([Link]);
[Link](30,30,25,25);
[Link]([Link]);
[Link](new Font("Times New Roman", [Link] | [Link], 20));
[Link]("Concentric Circles",100,20);
47

}
}
/* <applet code=ConcentricCircles width=300 height=300>
</applet> */

OUTPUT:

APPLET VIEWER:

RESULT: Thus the program has been executed successfully.


48

Ex. No. 15(A) NETWORK PROGRAMMING


Date:18-04-2026 SOCKET PROGRAMMING

AIM: To display the components in a given URL using java.

PROCEDURE:

Step 1: A URL consists of the following components:


➢ Protocol (e.g., http, https)
➢ Host (e.g., [Link])
➢ Port (optional, e.g., 8080)
➢ File Path (e.g., /[Link])
➢ Query String (optional, e.g., ?id=123)
➢ Fragment (optional, e.g., #section1)
Step 2: Create a URL object using new URL("url_string").
Step 3: Use methods like getProtocol(), getHost(), getPort(), etc., to access
URL components

CODING:

import [Link].*;
public class URLDemo
{
public static void main(String[] args)
{
try
{
URI uri = new URI("[Link]
URL url = [Link]();
[Link]("Protocol: "+[Link]());
[Link]("Host Name: "+[Link]());
[Link]("Port Number: "+[Link]());
[Link]("File Name: "+[Link]());
}
catch(Exception e)
{
[Link](e);
}
}
}
49

OUTPUT:

RESULT: Thus the program has been executed successfully.


50

Ex. No. 15(B)


COMPONENTS OF URL
Date:18-04-2026

AIM: To read the contents in a website using URL class in java.

PROCEDURE:

Step 1: Create a “URL” object with the website's URL as a string.


Step 2: Open a connection to the website using “[Link]()”.
Step 3: Cast the connection to “HttpURLConnection” if needed.
Step 4: Use an “InputStreamReader” to read data from the website.
Step 5: Read the content using a “BufferedReader” and display it.

CODING:

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ReadingWebPage1 {


public static void main(String args[]) throws IOException, URISyntaxException {
URI uri = new URI("[Link]
URL url = [Link]();
Scanner sc = new Scanner([Link]());
StringBuffer sb = new StringBuffer();
while([Link]()) {
[Link]([Link]());
}
String result = [Link]();
[Link](result);
[Link]();
}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


51

Ex. No. 15(C) READING CONTENTS OF WEBSITES USING


Date:18-04-2026 URL CLASS

AIM: To Demonstrate the Socket Program using the Java.

PROCEDURE:

Step 1:Server Side


➢ Create a ServerSocket to listen for incoming client connections.
➢ Accept client connections using accept().
➢ Create input/output streams to send/receive data.
Step 2:Client Side

➢ Create a Socket object to connect to the server.


➢ Use input/output streams to send/receive data to/from the server.

CODING:

[Link]
import [Link].*;
import [Link].*;
public class MyServer {
public static void main(String[] args){ try{
ServerSocket ss=new ServerSocket(6666);
Socket s=[Link]();
DataInputStream dis=new DataInputStream([Link]());
String str=(String)[Link]();
[Link]("message= "+str);
[Link](); }
catch(Exception e)

{
[Link](e);

}}}
[Link]
52

import [Link].*;
import [Link].*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream([Link]());
[Link]("Hello Server");
[Link]();
[Link]();
[Link]();
}catch(Exception e){[Link](e);}

}
}

OUTPUT:

RESULT: Thus the program has been executed successfully.


53

Ex. No. 16 CALCULATOR APPLICATION USING SWING


Date:18-04-2026 COMPONENTS

AIM: To write the servlet program for Calculator

PROCEDURE:

Step 1:Start
Step 2:Create JFrame and set properties
Step 3:Create JTextField for display
Step 4:Create buttons and add to panel
Step 5:Add ActionListener to buttons
Step 6:On button click:
a. Append numbers/operators to expression
b. Perform calculation on ‘=’
c. Clear on ‘C’
Step 7:Display result
Step 8:Stop

CODING:

import [Link].*;
import [Link].*;
import [Link].*;
public class SimpleCalculator extends JFrame implements ActionListener {
JTextField textField;
double num1 = 0, num2 = 0, result = 0;
char operator;
String expression = "";
public SimpleCalculator() {
setTitle("Simple Calculator");
setSize(300, 450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
setLocationRelativeTo(null);
textField = new JTextField();
[Link](new Font("Times New Roman", [Link], 20));
[Link]([Link]);
[Link](new Dimension(120, 80));
add(textField, [Link]);
JPanel panel = new JPanel();
[Link](new GridLayout(5, 4, 5, 5));
String[] buttons = {
"7","8","9","/",
54

"4","5","6","*",
"1","2","3","-",
"0",".","=","+",
"C"
};
for (String text : buttons) {
JButton btn = new JButton(text);
[Link](new Font("Times New Roman", [Link], 18));
[Link](this);
[Link](btn);
}
add(panel, [Link]);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String command = [Link]();
if (([Link](0) >= '0' && [Link](0) <= '9') || [Link](".")) {
expression += command;
[Link](expression);
}
else if ([Link]("C")) {
expression = "";
[Link]("");
num1 = num2 = result = 0;
}
else if ([Link]("+") || [Link]("-") ||
[Link]("*") || [Link]("/")) {
operator = [Link](0);
expression += command;
[Link](expression);
}
else if ([Link]("=")) {
try {
String[] parts = [Link]("[+\\-*/]");
num1 = [Link](parts[0]);
num2 = [Link](parts[1]);
switch (operator) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
}
[Link](expression + " = " + result);
expression = [Link](result); // allow further calculation
} catch (Exception ex) {
[Link]("Error");
}
}
}
public static void main(String[] args) {
55

new SimpleCalculator();
}
}
OUTPUT:

RESULT: Thus the program has been executed successfully.

You might also like