0% found this document useful (0 votes)
35 views82 pages

Advanced Java Programming Lab Record

The document is a practical record for the Advanced Java Programming Lab at Sarah Tucker College for the academic year 2025-2026. It includes various exercises demonstrating Java programming concepts such as palindrome checking, factorial calculation, array manipulation, constructor overloading, method overloading, and multilevel inheritance. Each exercise contains an aim, algorithm, coding examples, output, and results indicating successful execution.

Uploaded by

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

Advanced Java Programming Lab Record

The document is a practical record for the Advanced Java Programming Lab at Sarah Tucker College for the academic year 2025-2026. It includes various exercises demonstrating Java programming concepts such as palindrome checking, factorial calculation, array manipulation, constructor overloading, method overloading, and multilevel inheritance. Each exercise contains an aim, algorithm, coding examples, output, and results indicating successful execution.

Uploaded by

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

SARAH TUCKER COLLEGE (AUTONOMOUS)

TIRUNELVELI - 627 007


NATIONALLY ASSESSED AND RE-ACCREDITED WITH ‘A+’ GRADE

MASTER OF COMPUTER APPLICATIONS

ADVANCED JAVA PROGRAMMING LAB


()

PRACTICAL RECORD

DEPARTMENT OF COMPUTER APPLICATIONS


AND RESEARCH CENTRE
2025 – 2026
SARAH TUCKER COLLEGE (AUTONOMOUS), TIRUNELVELI - 7
DEPARTMENT OF COMPUTER APPLICATIONS AND
RESEARCH CENTRE

Name of Student :

Register Number :

Date :

ADVANCED JAVA PROGRAMMING LAB ()


CERTIFICATE

This is to certify that __________________________________________, I MCA,


SARAH TUCKER COLLEGE, TIRUNELVELI-7 has done this practical work in
ADVANCED JAVA PROGRAMMING LAB during the Third Semester of the
Academic year 2025-2026.

Head of the Department Staff in-Charge

External Examiner Internal Examiner


INDEX

[Link] Date Topic Page No

1 26-06.2025 Palindrome

2 26-06-2025 Factorial

3 01-07-2025 Array

4 04-07-2025 Constructor

5 10-07-2025 Method Overloading

6 16-07-2025 Multilevel Inheritance

7 16-07-2025 Multiple Inheritance

8 22-07-2025 Package

9 08-08-2025 Exception Handling

10 13-08-2025 Multithreading

11 18-08-2025 String Manipulation

12 21-08-2025 Abstract Class

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

19 22-09-2025 Forward Action Tag

20 26-09-2025 System Information

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:

To create a Java program demonstrating the concept of constructor overloading in a class


Box, where different constructors are used to initialize the dimensions of a box, and calculate
its volume.

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

 Define method sum(int a, int b)


→ Displays the sum of two integers: a + b
 Define method sum(int a, int b, int c)
→ Displays the sum of three integers: a + b + c

3. In Main Method

a) Create a DataInputStream object to read user input

b) Display "Enter the value for a, b, c:"

c) Read three integers a, b, and c from the user input

d) Create an object s of class Overloading

e) Call [Link](a, b) → Calculates and displays the sum of a and b

f) Call [Link](a, b, c) → Calculates and displays the sum of a, b, and c

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.

9. Override Method display():

a) Calculate:
da = 50% of salary

hra = 10% of salary

tax = 5% of salary

netpay = salary + da + hra - tax

b) Display:
Salary, DA, HRA, Tax, Net Pay

10. In Main Method (EmployeeDemo)


a) Read from user:

Employee Name (ename)

Employee Number (eno)

Department Name (dname)

Designation (desgn)

Salary (sal)

b) Create Salary object s using constructor with the above inputs.

c) Call [Link]() → Displays all details including computed salary components.

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);

3. Define Interface StudentName

 Declare method:
void displayName(String name);

4. Define Class MultipleInherit that Implements Both Interfaces

 Implement method displayAge(int age) → Displays:


"Age: " + age
 Implement method displayName(String name) → Displays:
"Name: " + 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:

Step 1: Class Balance (in Package Pack1)

1. Define instance variables:

 name (String): Account holder’s name


 acno (int): Account number
 amt (double): Account balance

2. Define Constructor:
Accepts name, acno, amt and initializes instance variables.
3. Define Method withdraw(double val):

 Calculate rem = amt - val


 If rem > 1000, update amt ← rem
 Else, print "Amount insufficient"

4. Define Method deposit(double val):

 Update amt ← amt + val

5. Define Method show():


Print Name, Account Number, and Amount.

Step 2: Main Class Accountbalance

1. Import [Link] and necessary I/O classes.


2. Read from user:

 myname (String)
 acno (int)
 amt (double)

3. Create Balance object b using the constructor.


4. Repeat until user enters choice >= 3:

 Display Menu:

1. Withdraw
2. Deposit
3. Exit

 Read user choice ch.


 If choice = 1 (Withdraw):
a) Read withdrawal amount
b) Call [Link](amt)
c) Call [Link]()

 Else if choice = 2 (Deposit):


a) Read deposit amount
b) Call [Link](amt)
c) Call [Link]()

5. Program ends when user enters choice 3 or greater.

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:

Step 1: Define User-Defined Exception Class Nage

1. Extend [Link].
2. Create a constructor that takes a String message and passes it to the superclass
constructor.

Step 2: In Exception Class Main Method

1. Use try block:

 Read the first command-line argument: s1 ← s[0].


 Convert s1 to integer: n1 ← [Link](s1).
 Calculate n2 ← n1 / n1 (will throw ArithmeticException if n1 == 0).
 Display "Division value: n2".
 Check if n1 < 18:

 If yes → Create and throw user-defined exception Nage("You have


entered invalid age.").
 Else → Print "You are eligible".
2. Catch Blocks:

 Catch ArithmeticException ae:


Print "Don't enter zero for denominator".
 Catch NumberFormatExceptionnfe:
Print "Pass only integer values".
 Catch ArrayIndexOutOfBoundsExceptionaie:
Print "Pass data from command prompt".
 Catch Nage e:
Print exception message.

3. Finally Block:

 Print "I am from finally" (executes regardless of exception).


Step 3: End

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

1. Declare instance variable num (integer).


2. Constructor Threading(int num):

 Initialize [Link] ← num.

3. Define synchronized method printTable():

 Loop i from 1 to 10:

Print:
"i x num = (i * num) [Thread Name]"
 Pause execution for 500 milliseconds using [Link](500).
4. Override run() method:

 Call printTable().

Step 2: In Class Testing Main Method

1. Use a try-catch block to handle InterruptedException.


2. Loop i from 1 to 3:
a) Create a new Thread object t by passing a new Threading(i) instance to the Thread
constructor.

b) Start the thread: [Link]().

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:

Step 1: Input String from User

1. Create DataInputStream object to read input from the user.


2. Display message: "Enter a String :".
3. Read user input string na.
4. Create a String object s ← new String(na).
5. Define another string s1 ← "Hello ".

Step 2: Perform String Operations

1. Display String Length


Print: "String Length : " + [Link]()
2. Display Character at 3rd Position
Print: "Character at 3rd Position : " + [Link](3)
3. Display Substring Starting from 5th Index
Print: "Substring : " + [Link](5)
4. Concatenate Strings
Print: "Concatenated String : " + [Link](s)
5. Change to Lower Case
Print: "Changing to Lower Case : " + [Link]()
6. Change to UPPER Case
Print: "Changing to UPPER Case : " + [Link]()
7. Compare Strings
Compare [Link](s) →

 If true, print "String is Equal"


 Else, print "String is not Equal"

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 1: Define Abstract Class Figure

1. Declare integer variables x and y.


2. Create Constructor Figure(int a, int b)
→ Initialize x ← a, y ← b.
3. Declare Abstract Method void area()
→ No implementation in Figure.

Step 2: Define Class Rectangle Extending Figure

1. Constructor Rectangle(int a, int b) → Calls super(a, b).


2. Implement method area():

 Compute and print:


"Area of rectangle: " + (x * y).

Step 3: Define Class Triangle Extending Figure

1. Constructor Triangle(int a, int b) → Calls super(a, b).


2. Implement method area():

 Compute and print:


"Area of triangle: " + (x * y / 2).

Step 4: In All Class Main Method

1. Create object t of type Triangle with dimensions (10, 10).


2. Create object r of type Rectangle with dimensions (2, 3).
3. Declare a reference of type Figure named f.
4. Assign t to f → Call [Link]() → Displays area of triangle.
5. Assign r to f → Call [Link]() → Displays area of rectangle.

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:

Step 1: UDP Client ([Link])

1. Initialize:

 DatagramSocket cs (client socket).


 DatagramPacketdp.
 BufferedReader dis to read input from the console.
 InetAddressia → Localhost address.
 Byte buffer buf[].

2. Set:

 Client port (cport) = 789


 Server port (sport) = 790

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.

b) Convert str to bytes → buf.

c) If str equals "STOP":

 Send a final packet to the server.


 Print "Terminated..." and break the loop.

d) Send DatagramPacket containing str to server at port sport.

e) Receive a response packet from the server.

f) Convert received data to string str2 and display:


"Server: " + str2
Step 2: UDP Server ([Link])

1. Initialize:

 DatagramSocket ss (server socket).


 DatagramPacketdp.
 BufferedReader dis to read input from console.
 InetAddressia → Localhost address.
 Byte buffer buf[].

2. Set:

 Client port (cport) = 789


 Server port (sport) = 790

3. Display message:
"Server is Running..."
4. Create DatagramSocket bound to sport.
5. Loop indefinitely:
a) Receive a packet from client.

b) Convert packet data to string str.

c) If str equals "STOP":

 Print "Terminated..." and break the loop.

d) Display:
"Client: " + str

e) Read string str1 from console (server’s response).

f) Convert str1 to bytes → buf.

g) Send DatagramPacket containing str1 back to client at port cport.

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:

Step 1: Import Required Packages

1. Import [Link].* for layout and components.


2. Import [Link].* for Swing components.
3. Import [Link].* for event handling.

Step 2: Define Class MySwing Implementing ActionListener

1. Declare instance variables:

 ImageIcon i1, i2, i3 → For images.


 JButton l1, l2, l3 → Buttons with images.
 JTextFieldtx → To display text when a button is clicked.

Step 3: Constructor MySwing()

1. Create JFramejf with title "Flag Demo".


2. Set layout of jf to FlowLayout.
3. Load images into i1, i2, i3 using ImageIcon("[Link]"), etc.
4. Create buttons l1, l2, l3 with respective icons.
5. Initialize text field tx with 50 columns.
6. Add ActionListener to all buttons:

 [Link](this)
 [Link](this)
 [Link](this)

7. Add buttons and text field to the frame:


[Link](l1); [Link](l2); [Link](l3); [Link](tx);
8. Set frame size: [Link](400,500)
9. Make frame visible: [Link](true)

Step 4: Implement actionPerformed(ActionEvent e)

1. Check the source of the event:


 If [Link]() == l1 → [Link]("Smiley")
 Else if [Link]() == l2 → [Link]("Man")
 Else if [Link]() == l3 → [Link]("Cake")

Step 5: Main Method

1. Create object of MySwing → new MySwing();

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:

Step 1: Import Required Packages

1. Import [Link].* → For creating the applet.


2. Import [Link].* → For AWT components (Button, TextField, List, Label).
3. Import [Link].* → For event handling (ActionListener).

Step 2: Define Class SampleApplet

1. Extend Applet and implement ActionListener.


2. Declare AWT components:

 Button b → For adding items


 TextFieldtx → To input text
 List l → To display items
 Label la → To label the List

Step 3: Initialize Components in init()

1. Create Button → b = new Button("ADD ITEM")


2. Create TextField → tx = new TextField(20)
3. Create List → l = new List()
4. Create Label → la = new Label("Country: ")
5. Add components to applet:

 add(la)
 add(l)
 add(tx)
 add(b)

6. Register ActionListener for button:

 [Link](this)

Step 4: Implement actionPerformed(ActionEvent e)

1. Read text from TextField: temp = [Link]()


2. Add text to List: [Link](temp)

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

 Create an HTML page ([Link]) with multiple-choice questions.


 Provide radio button options for each question and a submit button.

2. Submit and Pass Data

 When the user submits the form, the answers are sent to [Link] using the
POST method.

3. Process Answers in JSP

 Retrieve the selected answers using [Link]().


 Initialize variables ca (correct answers) and score.
 Compare each answer with the correct one:
 If correct → increase score by 10 and increment ca.

4. Display Result

 Print the number of correct answers.


 Print the total score out of 20.

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].

2. Retrieve User Input

 In [Link], retrieve the values of first_name and last_name using


[Link]().

3. Create and Store Cookies

 Create cookie objects for first_name and last_name.


 Set the maximum age of cookies (e.g., 24 hours).
 Add cookies to the response using [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

 Open a JSP page.


 Use the session implicit object to track visits.

2. Check Session Attribute

 Get the attribute "NumberOfVisits" from the session.


 If it is null (first visit), set counter = 1.

3. Update Counter

 If not null, convert it to integer, increment the counter by 1.


 Store the updated counter back into the session with setAttribute().

4. Display Result

 Print the total number of hits (counter value) on the webpage.

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

 Create an HTML input page ([Link]) with a form containing a dropdown


(select) to choose a value (1 or 2).
 On form submission, send the selected value to [Link].

2. Retrieve Input in JSP

 In [Link], retrieve the selected value using


[Link]("mvalue").
 Convert the value to an integer.

3. Decision Making (Forwarding)

 If the value entered is 1, forward the request to [Link].


 If the value entered is 2, forward the request to [Link].

4. Display Forwarded Content

 If forwarded to [Link], display the heading “SYSTEM


INFORMATION” and copyright details.
 If forwarded to [Link], display the heading “E-CART” along with an
image.

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

 Create an HTML file with a <form> element.


 Provide a <select> dropdown for choosing colors (Pink, Green, Blue).
 On submission, send the selected color to [Link].

2. Retrieve User Input in JSP

 In [Link], import [Link].*.


 Retrieve the selected color using [Link]("mycolor").
 If no color is selected, assign a default background color (white).

3. Fetch System Information

 Get the system’s IP address and hostname using [Link]().


 Get the server port using [Link]().
 Get the protocol using [Link]().

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.

You might also like