INDEX
[Link] NAME OF THE PROGRAM DATE [Link]
Welcome Program
1. 02-07-
2025
Arithmetic operations
2. 09-07-
2025
Factorial Number 16-07-
3. 2025
Fibonacci sequence
4. 23-07-
2025
Employee details using scanner
5. class
30-07-
2025
Palindrome Number
6. 06-08-
2025
Area and perimeter of rectangle by
using scanner class
7. 13-08-
2025
Matrix Multiplication
8. 20-08-
2025
String Handling Function
9. 03-09-
2025
Area and Perimeter of Square on
Declaring an object
10. 10-09-
2025
11. Inheritance 17-09-
2025
Polymorphism
12. 08-10-
2025
1. Welcome Program
class Bsc
{
public static void main(String args[])
{
[Link]("welcome to java language");
[Link]("welcome to java lab");
}
}
output:-
welcome to java language
welcome to java lab
2. Arithamatic operations
class AOP
{
public static void main(String args[])
{
int a=50,b=25;
[Link]("a="+a);
[Link]("b="+b);
[Link]("a+b="+(a+b));
[Link]("a-b="+(a-b));
[Link]("a*b="+(a*b));
[Link]("a/b="+(a/b));
}
}
output:-
a=50
b=25
a+b=75
a-b=25
a*b=1250
a/b=2
3. Factorial Number
class FACT
{
public static void main(String args[])
{
int number=10;
int factorial=number;
for (int i=(number-1);i>1;i--)
{
factorial=factorial*1;
}
[Link]("factorial of a number is:"+factorial);
}
}
output:-
factorial of a number is:10
4. Fibonacci sequence
import [Link];
class Fibonacci
{
public static void main(String arg[])
{
int n,a=0,b=0,c=1;
Scanner s=new Scanner ([Link]);
[Link]("enter value of n:");
n=[Link]();
[Link]("Fibonacci series:");
for (int i=1;i<n;i++);
a=b;
b=c;
c=a+b;
[Link](a+" ");
}
}
output:-
enter value of n:
10
Fibonacci series:
0,1,1,2,3,5,8,13,21,34
5. Employee details using scanner class
import [Link];
class Employee
{
public static void main (String args[])
{
Scanner scemp=new Scanner ([Link]);
[Link]("enter employee id number:");
int empid=[Link]();
[Link]("enter employee name:");
String empname=[Link]();
[Link]("empid:"+empid+"empname:"+empname);
}
}
output:-
enter employee id number:
145
enter employee name:
bsc
empid:145empname:bsc
6. Palindrome Number
import [Link];
class palindromenumber
{
public static void main(String args[])
{
int number,reversed,original;
Scanner sc=new Scanner([Link]);
[Link]("enter the number");
number=[Link]();
original=number;
reversed=0;
while(number!=0)
{
int digit=number%10;
reversed=reversed*10+digit;
number=number/10;
}
if(original==reversed)
{
[Link](original+"is a palindrome number");
}
else
{
[Link](original+"is not a palindrome number");
}
}
}
output:-
enter the number
25
25is not a palindrome number
[Link] and perimeter of rectangle by using
scanner class
import [Link];
class Rectangle
{
public static void main(String args[])
{
int length,breath,area,perimeter;
Scanner sc=new Scanner([Link]);
[Link]("length of the rectangle=");
length=[Link]();
[Link]("breath of the rectangle=");
breath=[Link]();
area=length*breath;
perimeter=2*(length+breath);
[Link]("area of rectangle="+(area));
[Link]("perimeter of rectangle="+(perimeter));
}
}
output:-
length of the rectangle=
24
breath of the rectangle=
20
area of rectangle=480
perimeter of rectangle=88
8. Matrix Multiplication
import [Link];
public class MatrixMultiplication
{
public static void main(String arg[])
{
Scanner sc=new Scanner([Link]);
int[][] matrixA = new int [3][3];
int[][] matrixB = new int[3][3];
int[][] product= new int [3][3];
[Link] ("Enter elements of 3x3 MatirxA:");
for (int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
matrixA[i][j]=[Link]();
}
}
[Link]("Enter elements of 3x3 MatrixB:");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
matrixB[i][j]=[Link]();
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
product[i][j]=0;
for(int k=0;k<3;k++)
{
product[i][j]+=matrixA[i][k]*matrixB[k][j];
}
}
}
[Link]("resultant matrix(A*B):");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
[Link](product[i][j]+" ");
}
[Link]();
} } }
output:-
Enter elements of 3x3 MatirxA:
123
456
789
Enter elements of 3x3 MatrixB:
987
654
321
resultant matrix(A*B):
30 84 138
24 69 114
18 54 90
9. String Handling Function
class StringTest
{
public static void main(String args[]) {
String s1 = "Dravidian";
String s2 = new String("university");
char array[] = {'K', 'U', 'P', 'P', 'A', 'M'};
String s3 = new String(array);
String s4 = [Link](s2);
[Link]("The concatenation of string1 and
string2 is: " + s4);
[Link]("The length of string1 is: " +
[Link]());
[Link]("The comparison of two strings is: " +
[Link](s2));
[Link]("The substring of string1 is: " +
[Link](3, 7));
[Link]("The replaced string2 is: " +
[Link]('v', 'a'));
[Link]("The lower case string3 is: " +
[Link]());
[Link]("The specified character of string1 is: "
+ [Link](3));
[Link]("The upper case string3 is: " +
[Link]());
[Link]("The trimmed string2 is: " + [Link]());
}
}
output:-
The concatenation of string1 and string2 is: Dravidianuniversity
The length of string1 is: 19
The comparison of two strings is: -49
The substring of string1 is: vidi
The replaced string2 is: university
The lower case string3 is: kuppam
The specified character of string1 is: v
The upper case string3 is: KUPPAM
The trimmed string2 is: university
10. area and perimeter of square on
declaring an object
// [Link]
class Square
{
// Property: side of the square
double side;
// Constructor to initialize the side
Square(double side)
{
[Link] = side;
}
// Method to calculate area
double getArea()
{
return side * side;
}
// Method to calculate perimeter
double getPerimeter()
{
return 4 * side;
}
}
// Main class to run the program
public class SquareMain
{
public static void main(String[] args)
{
// Create an object of Square with side length 5
Square square = new Square(5.0);
// Calculate area and perimeter
double area = [Link]();
double perimeter = [Link]();
// Print the results
[Link]("Side of the square: " + [Link]);
[Link]("Area of the square: " + area);
[Link]("Perimeter of the square: " + perimeter);
}
}
output:-
Side of the square: 5.0
Area of the square: 25.0
Perimeter of the square: 20.0
11. Inheritance
class Animal
{
void eat()
{
[Link]("Animal: Eating...");
}
}
class Dog extends Animal
{
void bark() {
[Link]("Dog: Barking...");
}
}
class Puppy extends Dog
{
void weep()
{
[Link]("Puppy: Weeping...");
}
}
class Cat extends Animal
{
void meow()
{
[Link]("Cat: Meowing...");
}
}
interface Pet
{
void play();
}
interface Guard
{
void protect();
}
class GermanShepherd implements Pet, Guard
{
public void play()
{
[Link]("German Shepherd: Playing with owner...");
}
public void protect()
{
[Link]("German Shepherd: Guards the house...");
}
}
public class Inheritance
{
public static void main(String args[])
{
[Link]("=== Single Inheritance ===");
Dog d = new Dog();
[Link]();
[Link]();
[Link]("\n=== Multilevel Inheritance ===");
Puppy p = new Puppy();
[Link]();
[Link]();
[Link]();
[Link]("\n=== Hierarchical Inheritance ===");
Cat c = new Cat();
[Link]();
[Link]();
[Link]("\n=== Multiple Inheritance (Using
Interfaces) ===");
GermanShepherd gs = new GermanShepherd();
[Link]();
[Link]();
}
}
output:-
=== Single Inheritance ===
Animal: Eating...
Dog: Barking...
=== Multilevel Inheritance ===
Animal: Eating...
Dog: Barking...
Puppy: Weeping...
=== Hierarchical Inheritance ===
Animal: Eating...
Cat: Meowing...
=== Multiple Inheritance (Using Interfaces) ===
German Shepherd: Playing with owner...
German Shepherd: Guards the house...
12. Polymorphism
[Link] overloading:
class SampleOne
{
// Method 1
void add(int a, int b)
{
[Link]("The sum is: " + (a + b));
}
// Method 2
void add(int x, int y, int z)
{
[Link]("The sum of three numbers is: " + (x + y +
z));
}
}
class test
{
public static void main(String args[])
{
SampleOne s = new SampleOne(); // Object creation
[Link](10, 20);
[Link](20, 30, 40);
} }
output:-
The sum is: 30
The sum of three numbers is: 90
[Link] overriding:
// Example program for Method Overriding
class Sample
{
void calculate(double x)
{
[Link]("The square of x is: " + (x * x));
}
}
class One extends Sample
{
void calculate(double x)
{
[Link]("The square root of x is: " + [Link](x));
}
}
class MTest
{
public static void main(String args[])
{
One o = new One();
[Link](25);
} }
output:-
The square root of x is: 5.0