Advanced Java Programming Lab Record
Advanced Java Programming Lab Record
PRACTICAL RECORD
Name of Student :
Register Number :
Date :
1 26-06.2025 Palindrome
2 26-06-2025 Factorial
3 01-07-2025 Array
4 04-07-2025 Constructor
8 22-07-2025 Package
10 13-08-2025 Multithreading
13 26-08-2025 Network
14 04-09-2025 Swings
15 09-09-2025 Applet
16 12-09-2025 Quiz
17 16-09-2025 Cookies
18 19-09-2025 Session
Staff in-Charge
Ex. No: 1 Page No:
Date: 26-06-2025
PALINDROME
AIM:
To write a Java program to check whether a given number is a palindrome number or not.
ALGORITHM:
1. Start
2. Input
Display message: "Enter a number:"
Read an integer number n from the user.
3. Initialize variables
4. temp = n (to store original number for comparison)
5. newn = 0 (to store the reversed number)
6. r = 0 (to store remainder)
7. Reverse the number
WHILE n > 0 DO
a) r = n % 10 (get last digit of n)
b) newn = newn * 10 + r (build the reversed number)
c) n = n / 10 (remove the last digit from n)
8. Check for palindrome
IF temp == newn THEN
→ Print "It is a palindrome"
ELSE
→ Print "It is not a palindrome"
9. End
CODING:
import [Link].*;
class Palindrome
{
public static void main(String s[])throws IOException
{
[Link]("Enter a number: ");
DataInputStream ds=new DataInputStream([Link]);
int n=[Link]([Link]());
int r=0,newn=0;
int temp=n;
while(n>0)
{
r=n%10;
newn=newn*10+r;
n=n/10;
}
if(temp==newn)
[Link]("It is a palindrome");
else
[Link]("It is not a palindrome");
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java Palindrome
Enter a number:
121
It is a palindrome
Enter a number:
123
It is not a palindrome
RESULT:
Thus, the above program was executed successfully.
Ex. No: 2 Page No:
Date: 26-06-2025
FACTORIAL
AIM:
To develop a Java program that calculates the factorial of a given positive integer number
entered by the user.
ALGORITHM:
1. Start
2. Display"Factorial Program" and "*****************"
3. Input
Prompt the user: "Enter a number:"
Read integer n
4. Initialize Variables
5. fact ← 1 (to store factorial result)
6. i ← 1 (loop counter)
7. Calculate Factorial using For Loop
FOR i from 1 to n DO
fact ← fact × i
8. Display Output
Print "Factorial of n is: fact"
9. End
CODING:
import [Link].*;
class Factorial
{
public static void main(String args[])throws IOException
{
[Link]("Factorial Program");
[Link]("*****************");
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter a number: ");
int n=[Link]([Link]());
int fact=1,i;
for(i=1;i<=n;i++)
{
fact=i*fact;
}
[Link]("Factorial of "+n+" is: " +fact);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java Factorial
Factorial Program
*****************
Enter a number:
5
Factorial of 5 is: 120
RESULT:
Thus, the above program was executed successfully.
Ex. No: 3 Page No:
Date: 01-07-2025
ARRAY
AIM:
To write a Java program that takes a list of numbers as command-line arguments, calculates
and displays the sum, maximum, minimum, average, and also displays the sorted array in
ascending order.
ALGORITHM:
1. Start
2. Input
3. Read numbers from command-line arguments as string array s[].
4. Initialize
5. Create integer array a[] of size [Link].
6. Initialize sum ← 0.
7. Convert String Arguments to Integers and Calculate Sum
FOR i = 0 to [Link] - 1 DO
a) a[i] ← [Link](s[i])
b) Add a[i] to sum
c) Print a[i]
8. Find Maximum and Minimum Values
9. Initialize max ← a[0] and min ← a[0].
FOR i = 1 to [Link] - 1 DO
a) If a[i] > max, then max ← a[i]
b) If a[i] < min, then min ← a[i]
10. Sort the Array in Ascending Order (Bubble Sort)
FOR i = 0 to [Link] - 1 DO
FOR j = i+1 to [Link] - 1 DO
If a[i] > a[j] THEN
Swap a[i] and a[j]
11. Display Results
12. Print "Maximum: " + max
13. Print "Minimum: " + min
14. Print "Sum: " + sum
15. Print "Average: " + (double) sum / [Link]
16. Print "After Sorting" and print each element of sorted array a[]
17. End
CODING:
class Array
{
public static void main(String s[])
{
int a[]=new int[[Link]];
[Link]("The given numbers are");
int sum=0;
for(int i=0;i<[Link];i++)
{
a[i]=[Link](s[i]);
sum=sum+a[i];
[Link](a[i]);
}
int max=a[0],min=a[0],t;
for(int i=1;i<[Link];i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
for(int i=0;i<[Link];i++)
{
for(int j=i+1;j<[Link];j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
[Link]("Maximum: "+max);
[Link]("Minimum: "+min);
[Link]("Sum: "+sum);
[Link]("Average: "+(double)(sum)/[Link]);
[Link]("After Sorting");
for(int i=0;i<[Link];i++)
{
[Link](a[i]);
}
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java Array 8 5 9 3 2
The given numbers are
8
5
9
3
2
Maximum: 9
Minimum: 2
Sum: 27
Average: 5.4
After Sorting
2
3
5
8
9
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 4 Page No:
Date: 04-07-2025
CONSTRUCTOR
AIM:
ALGORITHM:
1. Start
2. Define Class Box with Variables
3. Instance variables: w (width), h (height), d (depth)
4. Create Constructors
a) Default Constructor:
Initializes w = 0, h = 0, d = 0
b) Single Parameter Constructor:
Accepts x and sets w = h = d = x
c) Three Parameter Constructor:
Accepts w, h, and d and initializes corresponding variables
5. Define Method volume()
6. Returns the volume: w × h × d
7. In BoxDemo Class Main Method
a) Create a Box b object using the default constructor
b) Read integer x from user (for box1 dimension)
c) Create Box b1 using constructor with one parameter x
d) Read integers w, h, d from user (for box2 dimensions)
e) Create Box b2 using three-parameter constructor w, h, d
8. Calculate and Display Volumes
9. Compute and print volume of Box b → Should be 0 (since default dimensions are
zero)
10. Compute and print volume of Box b1 → Volume of cube with dimensions x × x ×
x
11. Compute and print volume of Box b2 → Volume of box with given dimensions
12. End
CODING:
import [Link].*;
class Box
{
int w,h,d;
Box()
{
w=h=d=0;
}
Box(int x)
{
w=h=d=x;
}
Box(int w,inth,int d)
{
this.w=w;
this.h=h;
this.d=d;
}
int volume()
{
return(w*h*d);
}
}
class BoxDemo
{
public static void main(String args[])throws IOException
{
Box b=new Box();
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter the dimension of the box1: ");
int x=[Link]([Link]());
Box b1=new Box(x);
[Link]("Enter the width, height and depth of the box2: ");
int w=[Link]([Link]());
int h=[Link]([Link]());
int d=[Link]([Link]());
Box b2=new Box(w,h,d);
int rv=[Link]();
[Link]("Box 1 volume: "+rv);
[Link]("Box 2 volume: "+[Link]());
[Link]("Box 3 volume: "+[Link]());
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java BoxDemo
Enter the dimension of the box1:
80
Enter the width, height and depth of the box2:
50
54
25
Box 1 volume: 0
Box 2 volume: 512000
Box 3 volume: 67500
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 5 Page No:
Date: 10-07-2025
METHOD OVERLOADING
AIM:
To write a Java program that demonstrates method overloading by creating multiple methods
named sum to calculate the sum of two and three integers.
ALGORITHM:
1. Start
2. Define Class Overloading
3. In Main Method
4. End
CODING:
import [Link].*;
class Overloading
{
void sum(int a,int b)
{
[Link]("Sum of two integers: "+(a+b));
}
void sum(int a,intb,int c)
{
[Link]("Sum of three integers:"+(a+b+c));
}
public static void main(String args[])throws IOException
{
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter the value for a,b,c: ");
int a=[Link]([Link]());
int b=[Link]([Link]());
int c=[Link]([Link]());
Overloading s=new Overloading();
[Link](a,b);
[Link](a,b,c);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java Overloading
Enter the value for a,b,c:
10
50
30
Sum of two integers: 60
Sum of three integers:90
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 6 Page No:
Date: 16-07-2025
MULTILEVEL INHERITANCE
AIM:
To develop a Java program that demonstrates multilevel inheritance by creating an Employee
management system where Employee details, Department information, and Salary calculation
are handled through a chain of inheritance.
ALGORITHM:
1. Start
2. Define Class Employee
a) Instance Variables:
ename (Employee Name), eno (Employee Number)
b) Constructor:
Accepts e and no, initializes ename and eno.
c) Method display():
Displays Employee Name and Employee Number.
d) Define Class Department (Inherits Employee)
3. Instance Variables:
dname (Department Name), desgn (Designation)
4. Constructor:
Accepts e, no, d, des → Calls super(e, no) and initializes dname and desgn.
5. Override Method display():
Calls [Link]() and displays Department Name and Designation.
6. Define Class Salary (Inherits Department)
7. Instance Variable:
salary (Base Salary)
8. Constructor:
Accepts e, no, d, des, s → Calls super(e, no, d, des) and initializes salary.
a) Calculate:
da = 50% of salary
tax = 5% of salary
b) Display:
Salary, DA, HRA, Tax, Net Pay
Designation (desgn)
Salary (sal)
11. End
CODING:
import [Link].*;
class Employee
{
String ename;
int eno;
Employee(String e,int no)
{
ename=e;
eno=no;
}
void display()
{
[Link]("Employee Name: "+ename);
[Link]("Employee Number: "+eno);
}
}
class Department extends Employee
{
String dname;
String desgn;
Department(String e,intno,Stringd,String des)
{
super(e,no);
dname=d;
desgn=des;
}
void display()
{
[Link]();
[Link]("Department Name: "+dname);
[Link]("Designation: "+desgn);
}
}
class Salary extends Department
{
double salary;
Salary(String e,intno,Stringd,Stringdes,double s)
{
super(e,no,d,des);
salary=s;
}
void display()
{
[Link]();
double da=(50.0/100)*salary;
double hra=(10/(double)100)*salary;
double tax=(5.0/100)*salary;
double netpay=salary+da+hra-tax;
[Link]("Salary: "+salary);
[Link]("DA: "+da);
[Link]("HRA: "+hra);
[Link]("Tax: "+tax);
[Link]("Net Pay: "+netpay);
}
}
class EmployeeDemo
{
public static void main(String str[])throws IOException
{
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter the name and emp number: ");
String ename=[Link]();
int x=[Link]([Link]());
[Link]("Enter the department and designation");
String dname=[Link]();
String des=[Link]();
[Link]("Enter the salary: ");
double sal=[Link]([Link]());
Salary s=new Salary(ename,x,dname,des,sal);
[Link]();
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java EmployeeDemo
Enter the name and emp number:
Roopa
19101
Enter the department and designation
MBA
HR
Enter the salary:
120000
Employee Name: Roopa
Employee Number: 19101
Department Name: MBA
Designation: HR
Salary: 120000.0
DA: 60000.0
HRA: 12000.0
Tax: 6000.0
Net Pay: 186000.0
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 7 Page No:
Date: 16-07-2025
MULTIPLE INHERITANCE
AIM:
To develop a Java program that demonstrates multiple inheritance using interfaces, where the
class implements two interfaces to display a student's name and age.
ALGORITHM:
1. Start
2. Define Interface StudentAge
Declare method:
void displayAge(int age);
Declare method:
void displayName(String name);
5. In Main Method
a) Create object obj of class MultipleInherit
b) Call [Link]("Riya") → Displays student name
c) Call [Link](25) → Displays student age
6. End
CODING:
interface StudentAge
{
void displayAge(int age);
}
interface StudentName
{
void displayName(String name);
}
public class MultipleInherit implements StudentAge,StudentName
{
public void displayAge(int age)
{
[Link]("Age: "+age);
}
public void displayName(String name)
{
[Link]("Name: "+name);
}
public static void main(String args[])
{
MultipleInheritobj=new MultipleInherit();
[Link]("Riya");
[Link](25);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java MultipleInherit
Name: Riya
Age: 25
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 8 Page No:
Date: 22-07-2025
PACKAGE
AIM:
To develop a Java program that demonstrates the use of classes and packages by managing a
bank account system where a user can perform deposit and withdraw operations while
maintaining account balance.
ALGORITHM:
2. Define Constructor:
Accepts name, acno, amt and initializes instance variables.
3. Define Method withdraw(double val):
myname (String)
acno (int)
amt (double)
Display Menu:
1. Withdraw
2. Deposit
3. Exit
CODING:
[Link]
package Pack1;
public class Balance
{
String name;
int acno;
double amt;
public Balance(String name,intacno,double amt)
{
[Link]=name;
[Link]=acno;
[Link]=amt;
}
public void withdraw(double val)
{
double rem=amt-val;
if(rem>1000)
{
amt=rem;
}
else
{
[Link]("Amount insufficient");
}
}
public void deposit(double val)
{
amt=amt+val;
}
public void show()
{
[Link]("Name: "+name);
[Link]("Account: "+acno);
[Link]("Amount: "+amt);
}
}
[Link]
import [Link];
import [Link].*;
class Accountbalance
{
public static void main(String s[])throws IOException
{
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter name,acno,amount: ");
String myname=[Link]();
int acno=[Link]([Link]());
double amt=[Link]([Link]());
int ch;
Balance b=new Balance(myname,acno,amt);
do
{
[Link]("****************************");
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("Enter your choice: ");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]("Enter the amount to withdraw: ");
amt=[Link]([Link]());
[Link](amt);
[Link]();
break;
case 2:
[Link]("Enter the amount to deposit: ");
amt=[Link]([Link]());
[Link](amt);
[Link]();
break;
}
}
while(ch<3);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java Accountbalance
Enter name,acno,amount:
Harish
54302
80000
****************************
[Link]
[Link]
[Link]
Enter your choice:
1
Enter the amount to withdraw:
5000
Name: Harish
Account: 54302
Amount: 75000.0
****************************
[Link]
[Link]
[Link]
Enter your choice:
2
Enter the amount to deposit:
600
Name: Harish
Account: 54302
Amount: 75600.0
****************************
[Link]
[Link]
[Link]
Enter your choice:
3
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 9 Page No:
Date: 08-08-2025
EXCEPTION HANDLING
AIM:
To write a Java program that demonstrates user-defined exception handling along with
predefined exceptions such as ArithmeticException, NumberFormatException, and
ArrayIndexOutOfBoundsException, by checking the eligibility of age entered from the
command line.
ALGORITHM:
1. Extend [Link].
2. Create a constructor that takes a String message and passes it to the superclass
constructor.
3. Finally Block:
CODING:
class Nage extends [Link] {
Nage(String a) {
super(a);
}
}
public class Exception {
public static void main(String s[]) {
try {
String s1 = s[0];
int n1 = [Link](s1);
int n2 = n1 / n1;
[Link]("Division value: " + n2);
if (n1 < 18) {
Nagena = new Nage("You have entered invalid age.");
throw na;
} else {
[Link]("You are eligible");
}
} catch (ArithmeticException ae) {
[Link]("Don't enter zero for denominator");
} catch (NumberFormatExceptionnfe) {
[Link]("Pass only integer values");
} catch (ArrayIndexOutOfBoundsExceptionaie) {
[Link]("Pass data from command prompt");
} catch (Nage e) {
[Link](e);
} finally {
[Link]("I am from finally");
}
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java Exception
Pass data from command prompt
I am from finally
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 10 Page No:
Date: 13-08-2025
MULTITHREADING
AIM:
To develop a Java program that demonstrates multithreading by creating multiple threads to
print the multiplication table of numbers using thread synchronization.
ALGORITHM:
Step 1: Define Class Threading Extending Thread
Print:
"i x num = (i * num) [Thread Name]"
Pause execution for 500 milliseconds using [Link](500).
4. Override run() method:
Call printTable().
c) Call [Link]() → Waits for the current thread to finish before starting the next thread.
Step 3: End
CODING:
class Threading extends Thread {
int num;
Threading(int num) {
[Link] = num;
}
synchronized public void printTable() {
int n = [Link];
for (int i = 1; i<= 10; i++) {
[Link](i + " x " + n + " = " + (i * n) + " " +
[Link]().getName());
try {
[Link](500);
} catch(InterruptedException e) {
[Link](e);
}
}
}
public void run() {
printTable();
}
}
class Testing {
public static void main(String s[]) {
try {
for(int i = 1; i<= 3; i++) {
Thread t = new Thread(new Threading(i));
[Link]();
[Link](); // Remove this if you want true multithreading
}
} catch(InterruptedException e) {
[Link](e);
}
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java Testing
1 x 1 = 1 Thread-1
2 x 1 = 2 Thread-1
3 x 1 = 3 Thread-1
4 x 1 = 4 Thread-1
5 x 1 = 5 Thread-1
6 x 1 = 6 Thread-1
7 x 1 = 7 Thread-1
8 x 1 = 8 Thread-1
9 x 1 = 9 Thread-1
10 x 1 = 10 Thread-1
1 x 2 = 2 Thread-3
2 x 2 = 4 Thread-3
3 x 2 = 6 Thread-3
4 x 2 = 8 Thread-3
5 x 2 = 10 Thread-3
6 x 2 = 12 Thread-3
7 x 2 = 14 Thread-3
8 x 2 = 16 Thread-3
9 x 2 = 18 Thread-3
10 x 2 = 20 Thread-3
1 x 3 = 3 Thread-5
2 x 3 = 6 Thread-5
3 x 3 = 9 Thread-5
4 x 3 = 12 Thread-5
5 x 3 = 15 Thread-5
6 x 3 = 18 Thread-5
7 x 3 = 21 Thread-5
8 x 3 = 24 Thread-5
9 x 3 = 27 Thread-5
10 x 3 = 30 Thread-5
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 11 Page No:
Date: 18-08-2025
STRING MANIPULATION
AIM:
To write a Java program that demonstrates various String class methods such as length,
charAt, substring, concatenation, case conversion, comparison, and string copying.
ALGORITHM:
8. Copy String
Copy string using [Link](s) and print:
"Copy String : " + strCopy
Step 3: End
CODING:
import [Link].*;
class Sstring
{
public static void main(String[] args)throws IOException
{
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter a String : ");
String na=[Link]();
String s=new String(na);
String s1="Hello ";
[Link]("String Length : "+[Link]());
[Link]("Character at 3rd Position : "+[Link](3));
[Link]("Substring : "+[Link](5));
[Link]("Concatenated String : "+[Link](s));
[Link]("Changing ti Lower Case : "+[Link]());
[Link]("Changing to UPPER Case : "+[Link]());
boolean out=[Link](s);
if(out==true)
{
[Link]("Strring is Equal");
}
else
{
[Link]("String is not Equal");
}
String strCopy=[Link](s);
[Link]("Copy String : "+strCopy);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>java Sstring
Enter a String :
World
String Length : 5
Character at 3rd Position : l
Substring :
Concatenated String : Hello World
Changing ti Lower Case : world
Changing to UPPER Case : WORLD
String is not Equal
Copy String : World
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 12 Page No:
Date: 21-08-2025
ABSTRACT CLASS
AIM:
To develop a Java program that demonstrates the concept of abstract classes and method
overriding by calculating the area of different geometric figures (Rectangle and Triangle).
ALGORITHM:
Step 5: End
CODING:
abstract class Figure
{
int x,y;
Figure(int a,int b)
{
x=a;
y=b;
}
abstract void area();
}
class Rectangle extends Figure
{
Rectangle(int a,int b)
{
super(a,b);
}
void area()
{
[Link]("Area of rectangle: "+x*y);
}
}
class Triangle extends Figure
{
Triangle(int a,int b)
{
super(a,b);
}
void area()
{
[Link]("Area of triangle: "+x*y/2);
}
}
class All
{
public static void main(String args[])
{
Triangle t=new Triangle(10,10);
Rectangle r=new Rectangle(2,3);
Figure f;
f=t;
[Link]("Area of calculation using abstract class");
[Link]("----------------------------------------");
[Link]();
[Link]();
f=r;
[Link]();
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java All
Area of calculation using abstract class
----------------------------------------
Area of triangle: 50
Area of rectangle: 6
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 13 Page No:
Date: 26-08-2025
NETWORK
AIM:
To develop a Java program that demonstrates communication between a client and a server
using UDP (User Datagram Protocol) sockets, where the client sends messages to the server,
and the server responds back.
ALGORITHM:
1. Initialize:
2. Set:
3. Display message:
"Client is Running...Type 'STOP' to Quit"
4. Create DatagramSocket bound to cport.
5. Loop indefinitely:
a) Read string str from user input.
1. Initialize:
2. Set:
3. Display message:
"Server is Running..."
4. Create DatagramSocket bound to sport.
5. Loop indefinitely:
a) Receive a packet from client.
d) Display:
"Client: " + str
CODING:
[Link]
import [Link].*;
import [Link].*;
class UDPClient
{
public static void main(String args[])throws IOException
{
DatagramSocket cs;
DatagramPacketdp;
BufferedReader dis;
InetAddressia;
byte buf[]=new byte[1024];
int cport=789,sport=790;
[Link]("Client is Running...Type 'STOP' to Quit");
ia=[Link]();
[Link](ia);
cs=new DatagramSocket(cport);
dp=new DatagramPacket(buf,[Link]);
dis=new BufferedReader(new InputStreamReader([Link]));
while(true)
{
String str=new String([Link]());
buf=[Link]();
if([Link]("STOP"))
{
[Link]("Terminated...");
[Link](new DatagramPacket(buf,[Link](),ia,sport));
break;
}
[Link](new DatagramPacket(buf,[Link](),ia,sport));
[Link](dp);
String str2=new String([Link](), 0,[Link]());
[Link]("Server: " +str2);
}
}
}
[Link]
import [Link].*;
import [Link].*;
class UDPServer
{
public static DatagramSocket ss;
public static DatagramPacketdp;
public static BufferedReader dis;
public static InetAddressia;
public static byte buf[]=new byte [1024];
public static int cport=789,sport=790;
public static void main(String args[])throws IOException
{
ss=new DatagramSocket(sport);
dp=new DatagramPacket(buf,[Link]);
dis=new BufferedReader(new InputStreamReader([Link]));
ia=[Link]();
[Link]("Server is Running...");
while(true)
{
[Link](dp);
String str=new String([Link](),0,[Link]());
if([Link]("STOP"))
{
[Link]("Terminated...");
break;
}
[Link]("Client: "+str);
String str1=new String([Link]());
buf=[Link]();
[Link](new DatagramPacket(buf,[Link](),ia,cport));
}
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java UDPClient
Client is Running...Type 'STOP' to Quit
DESKTOP-L5VPBJV/[Link]
Hello
Server: Hii
Welcome to Java Programming
Server: This is UDPServer.
IamUDPClient.
Server: Thankyou
STOP
Terminated...
C:\Users\LENOVO\Documents\AdvancedJava>
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
C:\Users\LENOVO\Documents\AdvancedJava>java UDPServer
Server is Running...
Client: Hello
Hii
Client: Welcome to Java Programming
This is UDPServer.
Client: IamUDPClient.
Thankyou
Terminated...
C:\Users\LENOVO\Documents\AdvancedJava>
RESULT:
Thus, the above program was executed successfully.
Ex. No: 14 Page No:
Date: 04-09-2025
SWINGS
AIM:
To develop a Java Swing application that demonstrates the use of JButton with ImageIcon
and ActionListener, where clicking on a button displays a corresponding text in a JTextField.
ALGORITHM:
[Link](this)
[Link](this)
[Link](this)
CODING:
import [Link].* ;
import [Link].*;
import [Link].*;
public class MySwing implements ActionListener
{
ImageIcon i1;
ImageIcon i2;
ImageIcon i3;
JButton l1;
JButton l2;
JButton l3;
JTextFieldtx;
public MySwing()
{
JFramejf=new JFrame("Flag Demo");
[Link](new FlowLayout());
i1=new ImageIcon("[Link]");
i2=new ImageIcon("[Link]");
i3=new ImageIcon("[Link]");
l1=new JButton(i1);
l2=new JButton(i2);
l3=new JButton(i3);
tx=new JTextField(50);
[Link](this);
[Link](this);
[Link](this);
[Link](l1);
[Link](l2);
[Link](l3);
[Link](tx);
[Link](400,500);
[Link](true);
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==l1)
[Link]("Smiley");
else
if([Link]()==l2)
[Link]("Man");
else
if([Link]()==l3)
[Link]("Cake");
}
public static void main(String s[])
{
new MySwing();
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>set path="C:\Program Files\java\jdk1.6\bin"
C:\Users\LENOVO\Documents\AdvancedJava>java MySwing
RESULT:
Thus, the above program was executed successfully.
Ex. No: 15 Page No:
Date: 09-09-2025
APPLET
AIM:
To develop a Java Applet that demonstrates the use of AWT components such as Button,
TextField, List, and Label, where a user can enter a text in the TextField and add it to a List
by clicking a Button.
ALGORITHM:
add(la)
add(l)
add(tx)
add(b)
[Link](this)
Step 5: End
CODING:
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="SampleApplet" width=300 height=150>
</applet>
*/
public class SampleApplet extends Applet implements ActionListener
{
Button b;
TextFieldtx;
List l;
Label la;
public void init()
{
b=new Button("ADD ITEM");
tx=new TextField(20);
l=new List();
la=new Label("Country: ");
add(la);
add(l);
add(tx);
add(b);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
String temp=[Link]();
[Link](temp);
}
}
OUTPUT:
C:\Users\LENOVO\Documents\AdvancedJava>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\LENOVO\Documents\AdvancedJava>appletviewer [Link]
RESULT:
Thus, the above program was executed successfully.
Ex. No: 16 Page No:
Date: 12-09-2025
QUIZ
AIM:
To develop a simple quiz application using JSP that accepts answers from the user through
an HTML form, evaluates the answers, and displays the number of correct answers along
with the score.
ALGORITHM:
1. Start
When the user submits the form, the answers are sent to [Link] using the
POST method.
4. Display Result
5. Stop
CODING:
[Link]:
<html>
<body bgcolor="white">
<form method="post" action="[Link]">
<b>Who is the Father of Java?<br>
<input type="radio" name="q1" value="James Gosling">James Gosling<br>
<input type="radio" name="q1" value="Dennis Ritchie">Dennis Ritchie<br>
<input type="radio" name="q1" value="Herbert">Herbert<br>
<input type="radio" name="q1" value="Redmann">Redmann<br>
<b>Which of the following is a OOPs Language?<br>
<input type="radio" name="q2" value="C">C<br>
<input type="radio" name="q2" value="HTML">HTML<br>
<input type="radio" name="q2" value="COBOL">COBOL<br>
<input type="radio" name="q2" value="JAVA">JAVA<br>
<input type="submit" value="Check Ur Answer">
</form>
</body>
</html>
[Link]:
<%@page import="[Link].*" %>
<%
int ca=0;
String s1=[Link]("q1");
String s2=[Link]("q2");
int score=0;
if([Link]("James Gosling"))
{
score+=10;
ca++;
}
if([Link]("JAVA"))
{
score+=10;
ca++;
}
%>
<html>
<body bgcolor="#D5E8D4">
<center>
<h2>Quiz Result</h2>
<p><b>No. Of Correct Answer : </b><%=ca%></p>
<p><b>Your Score : </b><%=score%>/20</p>
</center>
</body>
</html>
OUTPUT:
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>startup
Using CATALINA_BASE: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_HOME: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_TMPDIR: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108\temp"
Using JRE_HOME: "C:\Program Files\ojdkbuild\java-1.8.0-openjdk-[Link]-1"
Using CLASSPATH: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\
bin\[Link];C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin\tomcat-
[Link]"
Using CATALINA_OPTS: ""
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>shutdown
RESULT:
Thus, the above program was executed successfully.
Ex. No: 17 Page No:
Date: 16-09-2025
COOKIES
AIM:
To write a JSP program that demonstrates the concept of cookies by storing a user’s first
name and last name in cookies and displaying them on the response page.
ALGORITHM:
1. Start
Create an HTML form ([Link]) to take user input: First Name and Last Name.
On submission, send the data to [Link].
4. Display Information
Display the entered First Name and Last Name on the webpage using JSP
expressions.
5. Stop
CODING:
[Link]:
<html>
<body>
<form action="[Link]" method="GET"><br/>
FIRST NAME : <input type="text" name="first_name">
<br/>
LAST NAME : <input type="text" name="last_name">
<br/>
<input type="Submit" value="SUBMIT">
</form>
</body>
</html>
[Link]:
<%
Cookie firstName=new Cookie("first_name",[Link]("first_name"));
Cookie lastName=new Cookie("last_name",[Link]("last_name"));
[Link](60*60*24);
[Link](60*60*24);
[Link](firstName);
[Link](lastName);
%>
<html>
<head>
<title>Setting Cookies</title>
</head>
<body>
<center>
<h1>Setting Cookies</h1>
</center>
<ul style="list-style-type:none;padding:0;">
<li><p><b>First Name: </b>
<%=[Link]("first_name")%></p></li>
<li><p><b>Last Name : </b>
<%=[Link]("last_name")%></p></li>
</ul>
</body>
</html>
OUTPUT:
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>startup
Using CATALINA_BASE: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_HOME: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_TMPDIR: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108\temp"
Using JRE_HOME: "C:\Program Files\ojdkbuild\java-1.8.0-openjdk-[Link]-1"
Using CLASSPATH: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\
bin\[Link];C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin\tomcat-
[Link]"
Using CATALINA_OPTS: ""
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>shutdown
RESULT:
Thus, the above program was executed successfully.
Ex. No: 18 Page No:
Date: 19-09-2025
SESSION
AIM:
To develop a JSP program that demonstrates the use of the session implicit object to count
and display the number of times a user has visited a page during the current session.
ALGORITHM:
1. Start
3. Update Counter
4. Display Result
5. Stop
CODING:
<%@page import="[Link].*,[Link].*"%>
<html>
<head>
<title>Session Implicit</title>
</head>
<body>
<%
Integer counter1=(Integer)[Link]("NumberOfVisits");
int counter;
if(counter1==null)
{
counter=1;
}
else
{
counter=[Link]();
counter=counter+1;
}
[Link]("NumberOfVisits",new Integer(counter));
%>
<h3>Total Number Of Hits To This Page is : <%=counter%></h3>
</body>
</html>
OUTPUT:
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>startup
Using CATALINA_BASE: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_HOME: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_TMPDIR: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108\temp"
Using JRE_HOME: "C:\Program Files\ojdkbuild\java-1.8.0-openjdk-[Link]-1"
Using CLASSPATH: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\
bin\[Link];C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin\tomcat-
[Link]"
Using CATALINA_OPTS: ""
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>shutdown
RESULT:
Thus, the above program was executed successfully.
Ex. No: 19 Page No:
Date: 22-09-2025
FORWARD ACTION TAG
AIM:
To write a JSP program that demonstrates the use of the <jsp:forward> action tag. The
program forwards the request to different HTML pages ([Link] or [Link])
depending on the user’s selected input value.
ALGORITHM:
1. Start
5. Stop
CODING:
[Link]:
<html>
<form method="POST" action="[Link]">
Choose the value: <select name="mvalue">
<option>1
<option>2
</select>
<input type="submit" value="Submit">
</form>
</html>
[Link]:
<html>
<head>
<title>DEMO OF JSP FORWARD ACTION TAG</title>
</head>
<body>
<h3>JSP PAGE: DEMO FORWARD</h3>
<% int n=[Link]([Link]("mvalue"));
if(n==1)
{
%>
<jsp:forward page="[Link]"/>
<%}
else
{%>
<jsp:forward page="[Link]"/>
<% }
%>
</body>
</html>
[Link]:
<html>
<body text="blue">
<center><h1> SYSTEM INFORMATION</h1></center>
<hr>
Copyright - Sarah Tucker College @ 2023
</body>
</html>
[Link]:
<html>
<body>
<h1><center> E-CART </h1>
<img src="Images/[Link]" height="100" width="500">
</center>
</body>
</html>
OUTPUT:
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>startup
Using CATALINA_BASE: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_HOME: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_TMPDIR: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108\temp"
Using JRE_HOME: "C:\Program Files\ojdkbuild\java-1.8.0-openjdk-[Link]-1"
Using CLASSPATH: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\
bin\[Link];C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin\tomcat-
[Link]"
Using CATALINA_OPTS: ""
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>shutdown
RESULT:
Thus, the above program was executed successfully.
Ex. No: 20 Page No:
Date: 26-09-2025
SYSTEM INFORMATION
AIM:
To develop a JSP program that accepts a color from the user through an HTML form and
dynamically sets the page background color, while also displaying the system information
such as system address, system name, server port, and protocol.
ALGORITHM:
1. Start
4. Display Results
Set the background color of the page dynamically using the selected color.
Display the System Address, System Name, System Port, and System
Protocol in a formatted table.
5. Stop
CODING:
[Link]:
<html>
<body bgcolor="white">
<form method="POST" action ="[Link]">
color:<select name="mycolor">
<option>Pink
<option>Green
<option>Blue
<input type="Submit" value = "Click Me">
</form>
</body>
</html>
[Link]:
<%@ page import="[Link].*" %>
<%
InetAddress i = [Link]();
String color = [Link]("mycolor");
if (color == null || [Link](""))
{
color = "white";
}
%>
<body bgcolor="<%=[Link]("mycolor")%>">
<center>
<h2>System Info</h2>
<table border="1">
<tr>
<td>System Address:</td>
<td><%=[Link]()%></td>
</tr>
<tr>
<td>System Name:</td>
<td><%=[Link]()%></td>
</tr>
<tr>
<td>System Port:</td>
<td><%=[Link]()%></td>
</tr>
<tr>
<td>System Protocol:</td>
<td><%=[Link]()%></td>
</tr>
</table>
</center>
</body>
OUTPUT:
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>startup
Using CATALINA_BASE: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_HOME: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108"
Using CATALINA_TMPDIR: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-
9.0.108\temp"
Using JRE_HOME: "C:\Program Files\ojdkbuild\java-1.8.0-openjdk-[Link]-1"
Using CLASSPATH: "C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\
bin\[Link];C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin\tomcat-
[Link]"
Using CATALINA_OPTS: ""
C:\apache-tomcat-9.0.108-windows-x64\apache-tomcat-9.0.108\bin>shutdown
RESULT:
Thus, the above program was executed successfully.