Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 68

JAVA Lab.

Copy

 Name - Abir Pal


 Dept. - CSE/B.tech-3rd Year/5th Sem.
 Roll No. - 123200803201
 Reg. No. - 201230100120005
 Subject - JAVA Lab. Copy
 Subject Code - CS 594A

1
Sl. Page Sign. Remarks
Name of the Experiment No. Date Of
No. faculty
1. Compile and Run a simple 4 05/08/2021
JAVA program
create class Object 5 07/08/2021
2.
Create and print array 6 10/08/2021
3.
in java
Array Addition using 7 10/08/2021
4.
for loop
Array addition & find
5.
Max array using for 8 10/08/2021
loop
JAVA programs for
6.
implementing single 9-10 23/08/2021
inheritance
JAVA programs for
7.
implementing Multilevel 11-12 23/08/2021
inheritance
JAVA programs for
8.
implementing Hierarchical 11-13 23/08/2021
inheritance
JAVA program for printing
9.
numbers of an array using
for-each loop 14 24/08/2021
JAVA program for
10. printing numbers of
an array using Label- 15 24/08/2021
for loop
JAVA program for
11. printing numbers of
an array using if- 24/08/2021
else
Downward triangle
12. Star Pattern Program 24/08/2021

Write a JAVA program


13. for default 24/08/2021
constructor
Sl. Page Sign. Remarks
Name of the Experiment No. Date Of
No. faculty
JAVA program for
14. calculation of area
of a rectangle using 24/08/2021
Parameterized
constructor
Write a JAVA program
15. for constructor 24/08/2021
overloading
Write a JAVA program
16. for implementing call 28/08/2021
by value
Write a Java program
17 using this keyword to
refer current class 31/08/2021
instance variable.
Write a Java program by
18 not using this
keyword to refer current 31/08/2021
class instance
variable.
Write a JAVA code using
19 this keyword to 31/08/2021
invoke current class
method.
Write a Java Program
20 Calling Default
Constructor from 31/08/2021
Parameterized
Constructor.
Write a Java Program
21 Calling Parameterized 31/08/2021
Constructor from Default
Constructor.
Write a Program to
22 demonstrate the use of 31/08/2021
static variable
Write a JAVA program for 04/09/2021
23 abstract keyword.
Write a JAVA program for
24 Multiplication of 07/09/2021
2D Array or Matrix
Sl. Page Sign. Remarks
Name of the Experiment No. Date Of
No. faculty

Write a JAVA program for 07/09/2021


25 Shorting of Array
Write a JAVA program for
26 printing your
name using command line 14/09/2021
argument

Write a JAVA program for


27 finding out the
factorial of a number 14/09/2021
using command line
Argument.
Write a JAVA program to
28 find prime number 14/09/2021
using command line
argument
Write a JAVA program to
29 generate Fibonacci 14/09/2021
series using command line
argument.
Write a JAVA program to
30 implement 14/09/2021
Multiple Inheritance
using Interface.
Write a JAVA program to
31 Implement the rate 14/09/2021
of interest of various
banks using Interface.
Write a JAVA program to 21/09/2021
32 implement String.

Write a JAVA program for


33 printing 1st
character & last 21/09/2021
character of the string
using
charAt();
Write a JAVA program for
34 printing the
characters at odd
positions & even
21/09/2021
positions
of a string using
charAt() method.
Sl. Page Sign. Remarks
Name of the Experiment No. Date Of
No. faculty

Write a JAVA program for


35 Comparing the 21/09/2021
String using compareTo()
method.
Write a JAVA program for
36 Concatenating the 21/09/2021
String using concat()
method.
Write a JAVA program for
37 Indexing the String 21/09/2021
using indexOf() method.
Write a JAVA program for
38 Implementing the 23/09/2021
getChars() method.
Write a JAVA program for
39 Implementing the 28/09/2021
indexOf() method.
Write a JAVA program for
40 Implementing the 28/09/2021
insert() method.
Write a JAVA program for
41 Implementing the 28/09/2021
length() method.
Write a JAVA program for 28/09/2021
42 Implementing the
setCharAt() method.

Write a JAVA program for


43 Implementing the 28/09/2021
setLength() method.
Write a JAVA program for
44 Implementing the 28/09/2021
substring() method.
Write a JAVA program for
45 Implementing the 28/09/2021
toString() method.
Write JAVA program for
46. implementing the 04/10/2021
following string methods
append()
Sl. Page Sign. Remarks
Name of the Experiment No. Date Of
No. faculty

Write JAVA program for


47. implementing the 04/10/2021
following string methods
delete()
Write JAVA program for
48. implementing the 04/10/2021
following string methods
deleteCharAt()
Write JAVA program for
49. implementing the 04/10/2021
following string methods
capacity()
Write a JAVA program for
50. handling 05/10/2021
ArithmeticException using
try-catch block.
Write a JAVA program for
51. handling 05/10/2021
ArrayIndexOutOfBounds
Exception.
Write a JAVA program to
52. implement throw 05/10/2021
keyword.
Write a JAVA program to
53. implement throws 05/10/2021
keyword.
Write a JAVA program for
54. creating your own 05/10/2021
package.
Write a JAVA program to
55. implement private O8/11/2021
Access modifier.
Write a JAVA program to
56. implement Default 08/11/2021
Access modifier.
Write a JAVA program to
57. implement Protected 08/11/2021
Access modifier.
Experiment No. - 01

 Experiment Name :
- Compile and Run a simple JAVA program

 Source Code :
// First JAVA Program - 05/08/2021
class Main
{
public static void main (String ary[])
{
System.out.println (" What is your name? ");
System.out.println (" My name is Abir Pal.");
System.out.println (" JIS College of Engineering ");
System.out.println (" B.tech/CSE/3rd Year ");
}
}

 Output :
Experiment No. - 02

 Experiment Name :
- Create Class Object

 Source Code :
// java 2nd program - 07/08/2021
// create Object

class Simple
{
public static void main(String args[])
{
Simple sim =new Simple();
System.out.println("sim instanceof simple");
}
}

 Output :
Experiment No. - 03

 Experiment Name :
- Create and print array in java (Array Declaar)

 Source Code :
// java 4th program - 10/08/2021
// Array Declear

class TestArray
{
public static void main(String ary[])
{
double[] arr={2.9, 3.9, 4.9, 5.9};
for(int i=0;i<arr.length;i++)
System.out.println(arr[i] + " ");
}

 Output :
Experiment No. - 04

 Experiment Name :
- Array addition using for loop

 Source Code :
// java 5th program - 10/08/2021
// Array Addition using for loop
class TestArray
{
public static void main(String ary[])
{
double[] arr={2.9, 3.9, 4.9, 5.9};
for(int i=0;i<arr.length;i++)
System.out.println(arr[i] + " ");
double total=0;
for(int i=0;i<arr.length;i++)
total=total+arr[i];

System.out.println("Total=" + total);

}
}

 Output :
Experiment No. - 05
 Experiment Name :
- Array addition & find Max array using for loop
 Source Code :
// java 6th program - 10/08/2021
//Array addition & find Max array using for loop

class TestArray
{
public static void main(String ary[])
{
double[] arr={2.9, 3.9, 4.9, 5.9};
for(int i=0;i<arr.length;i++)
System.out.println(arr[i] + " ");
double total=0;
for(int i=0;i<arr.length;i++)
total=total+arr[i];
System.out.println("Total is :" + total);
double max=arr[0];
for(int i=1;i<arr.length;i++)
{
if(arr[i] > max)
max=arr[i];
}
System.out.println("Max is :" + max);

}
}
 Output :
Experiment No. - 06
 Experiment Name :
-JAVA programs for implementing single inheritance
 Source Code :
// JAVA programs for implementing single inheritance - 23/08/2021
// Single Inheritance

class Student
{
public void print_Sname()
{
System.out.println (" ABIR PAL ");
}
}
class College extends Student
{
public void print_collegeInfo()
{
System.out.println (" Student of JISCE, 3rd Year ");
System.out.println (" Computer Science & Engineering ");
}
}
class Main
{
public static void main (String ary[])
{
College c = new College();
c.print_Sname();
c.print_collegeInfo();
}
}
 Output :
Experiment No. - 07
 Experiment Name :
- JAVA programs for implementing Multilevel inheritance
 Source Code :
// JAVA programs for implementing multilevel inheritance - 23/08/2021
// Multilevel inheritance

class College
{
public void display_collegeName()
{
System.out.println(" ---JIS College of Engineering--- ");
}
}

class Dept extends College


{
public void display_DeptClass()
{
System.out.println(" CSE/3B/5th Semester ");
}
}

class Student extends Dept


{
public void display_StudentInfo()
{
System.out.println(" ABIR PAL, Roll.No.- 123200803201 ");
}
}
class Data
{
public static void main(String ary[])
{
Student s = new Student();
s.display_collegeName();
s.display_DeptClass();
s.display_StudentInfo();
}
}

 Output :
Experiment No. - 08
 Experiment Name :
- JAVA programs for implementing Hierarchical inheritance

 Source Code :
// JAVA programs for implementing Hierarchical inheritance - 23/08/2021
// Hierarchical inheritance
class A
{
public void aaa()
{
System.out.println("Parent class");
}
}
class B extends A
{
public void bbb()
{
System.out.println("Sub class B");
}
}
class C extends A
{
public void ccc()
{
System.out.println("Sub class C");
}
}
class hier
{
public static void main(String args[])
{
B b=new B();
b.aaa();
b.bbb();
C c=new C();
c.aaa();
c.ccc();
}
}

 Output :

 Experiment Name : II)


- JAVA programs for implementing Hierarchical inheritance

 Source Code :
// JAVA programs for implementing hierarchical inheritance - 23/08/2021
//Hierarchical inheritance

class Student
{
public void print_sname()
{
System.out.println("My name is Abir Pal");
}
}

class College extends Student


{
public void print_collegeName()
{
System.out.println("JIS College of Engineering");
}
}
class Class extends Student
{
public void print_class()
{
System.out.println("CSE/3rd Year/5th Semester");
}
}

class Subject extends Student


{
public void print_subject()
{
System.out.println("JAVA lab. Class");
}
}
class Main
{
public static void main(String ary[])
{
College c = new College();
c.print_sname() ;
c.print_collegeName();

Class cl = new Class();


cl.print_sname() ;
cl.print_class();

Subject s = new Subject();


s.print_sname();
s.print_subject();
}
}

 Output :
Experiment No. - 09
 Experiment Name :
- JAVA program for printing numbers of an array using for-each loop

 Source Code :
// JAVA program for printing numbers of an array using for-each loop - 24/08/2021
//for loop and for-each loop
class Main
{
public static void main(String ary[])
{
int[] intary = { 1,2,3,4};
forDisplay(intary);
foreachDisplay(intary);
}
public static void forDisplay(int[] a)
{
System.out.println("Display an array using for loop");
for (int i = 0; i < a.length; i++)
{
System.out.print(a[i] + " ");
}
System.out.println();
}
public static void foreachDisplay(int[] data)
{
System.out.println("Display an array using for-each loop");
for (int a : data)
{
System.out.print(a+ " ");
}
}
}

 Output :
Experiment No. - 10
 Experiment Name :
- JAVA program for printing numbers of an array using Label-for loop
 Source Code :
// JAVA program for printing numbers of an array using Label-for loop - 24/08/2021
// Labeled For loop - 24/08/2021

import java.util.*;
class LevelForloop
{
public static void main(String ary[])
{
num:
for(int i=1;i<=5;i++)
{
num2:
for(int j = 1 ; j<=5;j++)
{
if(i==2 && j==2)
{
break num;
}
System.out.println(i+ " " +j);
}
}

}
}

 Output :
Experiment No. - 11
 Experiment Name :
- JAVA program for printing numbers of an array using if-else
 Source Code :
// JAVA program for printing numbers of an array using if-else - 24/08/2021
//for loop and if-else

import java.util.*;
import java.util.Scanner;
class Grade
{
public static void main(String ary[])
{
int num;
Scanner Sc = new Scanner(System.in);
System.out.println("Enter The Value: ");
num = Sc.nextInt();
if (num < 50){
System.out.println("Fail");
}
else if(num>=50&& num<60){
System.out.println("D Grade");
}
else if(num>=60&& num<70){
System.out.println("C Grade");
}
else if(num>=70&& num<80){
System.out.println("B Grade");
}
else if(num>=80&& num<90){
System.out.println("A Grade");
}
else if(num>=90&& num<=100){
System.out.println("O Grade");
}
else{
System.out.println("Invalid Data Given");
}

 Output :

Experiment No. - 12
 Experiment Name :
- JAVA program for printing Downward triangle Star Pattern
Program.

 Source Code :
// Downward triangle Star Pattern Program - 24/08/2021
// Downward Triangle Star Pattern

class DownwardTrianglePattern
{
public static void main(String ary[])
{
int rows=5;
for (int i= rows-1; i>=0 ; i--)
{
for (int j=0; j<=i; j++)
{
System.out.print("*" + " ");
}
System.out.println();
}
}
}

 Output :

Experiment No. - 13
 Experiment Name :
- JAVA program for calling default constructor

 Source Code :
// JAVA program for default constructor - 28/04/2021
// Default constructer

class DefaultConstructer
{
DefaultConstructer()
{
System.out.println(" This is DefaultConstructer program using JAVA ");
}
public static void main(String ary[])
{
DefaultConstructer dc = new DefaultConstructer();
}
}
 Output :
Experiment No. - 14
 Experiment Name :
- JAVA program for calculation of area of a rectangle using
Parameterized constructor.

 Source Code :
// JAVA program for calculation of area of a rectangle using Parameterized constructor -
28/04/2021
// Rectangle Area using Parameterized constructer

class Rectangle
{
int length;
int width;
Rectangle(int a, int b)
{
length=a;
width=b;
}
int cal()
{
return (length*width);
}
}
class RectCal
{
public static void main(String args[])
{
Rectangle r = new Rectangle(100, 50);
int area=r.cal();
System.out.println("AREA= "+area);
}
}
 Output :

Experiment No. - 15
 Experiment Name :
- Write a Java Program for Constructer Overloading.
 Source Code :
// Write a JAVA program for constructor overloading - 26/08/2021
// Constructor Overloading

class Box
{
double width, height, depth;
Box(double w, double h, double d)
{
width = w;
height = h;
depth = d;
}
Box()
{
width = height = depth = 0;
}
Box(double len)
{
width = height = depth = len;
}
double volume()
{
return width * height * depth;
}
}
class Test
{
public static void main(String args[])
{
Box mybox1 = new Box(10, 20, 15);
Box mybox2 = new Box();
Box mycube = new Box(7);

double vol;
vol = mybox1.volume();
System.out.println(" Volume of mybox1 is " + vol);
vol = mybox2.volume();
System.out.println(" Volume of mybox2 is " + vol);
vol = mycube.volume();
System.out.println(" Volume of mycube is " + vol);
}
}

 Output :

Experiment No. - 16
 Experiment Name :
- Write a Java Program for implementing call by value.
 Source Code :
// Write a JAVA program for implementing call by value - 24/08/2021
// Call by value

class CallByValue
{
int Change(int x)
{
++x;
return x;
}
public static void main(String ary[])
{
int a = 10;
System.out.println("Before Method Call Variable a = " +a);
CallByValue Obj = new CallByValue();
int y = Obj.Change(a);
System.out.println("After Method Call Variable a =" +a);
System.out.println("After Method Call Variable y =" +y);
}
}

 Output :

Experiment No. - 17
 Experiment Name :
- Write a Java program using this keyword to refer current class
instance variable.

 Source Code :
// Write a Java program using this keyword to refer current class instance variable.
// 31/08/2021
class CSE
{
int RollNumber;
String NameStudent;
float PriceFee;
CSE(int Roll, String Name, float Price)
{
RollNumber = Roll;
NameStudent = Name;
PriceFee = Price;
}
void Display()
{
System.out.println("Name = " +NameStudent + " Roll = "+RollNumber+ " Price = " +
PriceFee);
}
}
class Main
{
public static void main(String ary[])
{
CSE Obj1 = new CSE(100,"Abir Pal",(float)2500.00);
CSE Obj2 = new CSE(200,"Rahul Pal",(float)2600.00);
Obj1.Display();
Obj2.Display();
}
}

 Output :
Experiment No. - 18
 Experiment Name :
- Write a JAVA code not use this keyword to invoke current class
method.

 Source Code :
//Write a JAVA code not use this keyword to invoke current class method.
//31/08/2021
class CSE
{
int RollNumber;
String NameStudent;
float PriceFee;
CSE(int Roll, String Name, float Price)
{
RollNumber = Roll;
NameStudent = Name;
PriceFee = Price;
}
void Display()
{
System.out.println("Name = " +NameStudent + " Roll = "+RollNumber+ " Price = " +
PriceFee);
}
}
class Main
{
public static void main(String ary[])
{
CSE Obj1 = new CSE(100,"Abir Pal",(float)2500.00);
CSE Obj2 = new CSE(200,"Rahul Pal",(float)2600.00);
Obj1.Display();
Obj2.Display();
}
}

 Output :

Experiment No. - 19
 Experiment Name :
- Write a JAVA code using this keyword to invoke current class
method.

 Source Code :
//Write a JAVA code using this keyword to invoke current class method.
//31/08/2021
class CSE
{
void display()
{
System.out.println("Hello! I am Abir pal");
}
void display1()
{
System.out.println("JIS College of Engineering, Kalyani");
this.display();
}
}
class Main
{
public static void main(String ary[])
{
CSE Obj = new CSE();
Obj.display1();
}
}

 Output :

Experiment No. - 20
 Experiment Name :
- Write a Java Program Calling Default Constructor from
Parameterized Constructor.
 Source Code :
//Write a Java Program Calling Default Constructor from Parameterized Constructor.
// 31/08/2021
class ParameterizedConstructer
{
ParameterizedConstructer()
{
System.out.println("Hello! This is ParameterizedConstructer");
}
ParameterizedConstructer(int x)
{
this();
System.out.println(x);
}
ParameterizedConstructer(int x,int y)
{
this();
System.out.println(+ x + " " + y);
}}
class DefaultConstructor
{
public static void main(String ary[])
{
ParameterizedConstructer Obj = new ParameterizedConstructer(25);
ParameterizedConstructer Obj1 = new ParameterizedConstructer(25,30);
}}

 Output :

Experiment No. - 21
 Experiment Name :
- Writea Java Program Calling Parameterized Constructor from Default
Constructor.

 Source Code :
//Write a Java Program Calling Parameterized Constructor from Default Constructor.
// 31/08/2021
class CSE
{
CSE()
{
this(55);
System.out.println("JISCE");
}
CSE(int x)
{
System.out.println(x);
}
}
class DefaultConstructor
{
public static void main(String ary[])
{
CSE Obj = new CSE();
}
}

 Output :

Experiment No. - 22
 Experiment Name :
- Write a Program to demonstrate the use of static variable.

 Source Code :
//Write a Program to demonstrate the use of static variable.
//30/08/2021
class StaticVarriable
{
int roll1;
String name;
static String Col="JISCE";
StaticVarriable(int r1,String n)
{
roll1 = r1;
name = n;
}
void dis()
{
System.out.println("Name :"+name+";"+" Roll :" +roll1+";"+" College :"+Col);
}
public static void main(String ary[])
{
StaticVarriable Obj1 = new StaticVarriable(2021,"Abir Pal");
StaticVarriable Obj2 = new StaticVarriable(2022,"Rahul Pal");
Obj1.dis();
Obj2.dis();
}
}

 Output :

Experiment No. - 23
 Experiment Name :
- Write a JAVA program for abstract keyword.

 Source Code :
//Write a JAVA program for abstract keyword.
//04/09/2021
abstract class Bank
{
abstract int interest();
}
class axis extends Bank
{
@Override
int interest()
{
return 9;
}
}
class pnb extends Bank
{
@Override
int interest()
{
return 10;
}}
class SBI extends Bank
{
@Override
int interest()
{
return 20;
}
}
class AbstarctClass
{
public static void main(String ary[])
{
Bank B;
B = new axis();
System.out.println("The Interest of the Bank is " +B.interest()+ "%");
B = new pnb();
System.out.println("The Interest of the Bank is " +B.interest()+ "%");
B = new SBI();
System.out.println("The Interest of the Bank is " +B.interest()+ "%");
}
}

 Output :
Experiment No. - 24
 Experiment Name :
- Write a JAVA program for Multiplication of 2D Array or Matrix

 Source Code :
// Write a JAVA program for multiplication of two two dimensional arrays.
// 07/09/2021

import java.io.*;

class GFG
{

static void printMatrix(int M[][],


int rowSize,
int colSize)
{
for (int i = 0; i < rowSize; i++)
{
for (int j = 0; j < colSize; j++)
System.out.print(M[i][j] + " ");

System.out.println();
}
}
static void multiplyMatrix(
int row1, int col1, int A[][],
int row2, int col2, int B[][])
{
int i, j, k;

System.out.println("\nMatrix A:");
printMatrix(A, row1, col1);
System.out.println("\nMatrix B:");
printMatrix(B, row2, col2);

// Check if multiplication is Possible


if (row2 != col1) {

System.out.println(
"\nMultiplication Not Possible");
return;
}
int C[][] = new int[row1][col2];
for (i = 0; i < row1; i++)
{
for (j = 0; j < col2; j++)
{
for (k = 0; k < row2; k++)
C[i][j] += A[i][k] * B[k][j];
}
}
System.out.println("\nResultant Matrix:");
printMatrix(C, row1, col2);
}
public static void main(String ary[])
{

int row1 = 4, col1 = 3, row2 = 3, col2 = 4;

int A[][] = { { 1, 1, 1 },
{ 2, 2, 2 },
{ 3, 3, 3 },
{ 4, 4, 4 } };

int B[][] = { { 1, 1, 1, 1 },
{ 2, 2, 2, 2 },
{ 3, 3, 3, 3 } };

multiplyMatrix(row1, col1, A,
row2, col2, B);
}
}

 Output :
Experiment No. - 25
 Experiment Name :
- Write a JAVA program for Shorting of Array.

 Source Code :
// Write a JAVA program for Shorting of Array
// 07/09/2021
import java.util.Scanner;
class ArrayShorting
{
public static void main(String ary[])
{
Scanner Sc = new Scanner(System.in);
int Size;
System.out.println("Abir ! Hay ! Please Input The Size of the Array");
Size=Sc.nextInt();
int[] array1 = new int[Size];
int temp;
System.out.println("Abir ! Hay ! Please Give Values");
for (int i = 0; i < array1.length; i++)
{
array1[i]=Sc.nextInt();
}
System.out.println("Abir your Given Values are");
for (int i = 0; i < array1.length; i++)
{
System.out.println(array1[i] + " ");
}
for (int i = 0; i < array1.length; i++)
{
for (int j = i + 1; j < array1.length; j++)
{
if (array1[i] > array1[j]) {
temp = array1[i];
array1[i] = array1[j];
array1[j] = temp;
}
}
}
System.out.println("After Sorting ......");
for (int i = 0; i < array1.length; i++)
{
System.out.println(array1[i] + " ");
}
}
}

 Output :
Experiment No. - 26
 Experiment Name :
- Write a JAVA program for printing your name using command line
argument.

 Source Code :
//Write a JAVA program for printing your name using command line argument.
// 14/09/2021
class ComandLineArgument
{
public static void main(String ary[])
{
for(int i=0;i<args.length;i++)
{
System.out.println(args[i]);
}
}
}

 Output :

Experiment No. - 27
 Experiment Name :
- Write a JAVA program for finding out the factorial of a number using
command line argument.
 Source Code :
/* Write a JAVA program for finding out the factorial of a number using command line
argument.*/
// 14/09/2021
class ComandLineFact {
public static void main(String ary[])
{
int result = 1;
int Number = Integer.parseInt(ary[0]);
for (int i=1;i<=Number;i++)
{
result *= i;
}
System.out.println("Factorial of Number = " +Number+ " is = " +result);
}
}

 Output :

Experiment No. - 28
 Experiment Name :
- Write a JAVA program to find prime number using command line
argument.

 Source Code :
// Write a JAVA program to find prime number using command line argument.
// 14/09/2021
class ComandLinePrime
{
public static void main(String[] args)
{
int temp = 0;
int Number = Integer.parseInt(args[0]);
for (int i=2;i<Number;i++)
{
if(Number%i == 0)
{
System.out.println("Number = " +Number+ " IS NOT PRIME");
temp = 1;
break;
}
}
if (temp == 0)
{
System.out.println("Number = " + Number + " IS a PRIME Number");
}
temp = 0;
}}

 Output :

Experiment No. - 29
 Experiment Name :
- Write a JAVA program to generate Fibonacci series using command
line argument.

 Source Code :
// Write a JAVA program to generate Fibonacci series using command line argument.
// 14/09/2021

class ComandLineFibonacci
{
public static void main(String ary[])
{
int Value = Integer.parseInt(ary [0]);
int a = 0;
int b = 1;
int result = 0;
System.out.println(a);
System.out.println(b);
for(int i=2;i<=Value;++i)
{
result = a + b;
System.out.println(result);
a = b;
b = result;
}
}
}

 Output :

Experiment No. - 30
 Experiment Name :
- Write a JAVA program to implement Multiple Inheritance using
Interface.

 Source Code :
// Multiple Inheritance using Interface - Example 2
// 14/09/2021

interface abc
{
void print();
}
interface cba
{
void show();
}
interface rrr
{
void display();
}
class aaa1 implements abc,cba,rrr
{
public void print()
{
System.out.println("HELLO I AM FROM JISCE");
}
public void show()
{
System.out.println("WELLCOME YOU ALL IN JISCE");
}
public void display()
{
System.out.println("WELLCOME YOU ALL IN JISCE IN THIS RAINY DAY");
}
public static void main(String args[])
{
aaa1 a=new aaa1();
a.print();
a.show();
a.display();
}
}

 Output :

Experiment No. - 31
 Experiment Name :
- Write a JAVA program to implement the rate of interest of various
banks using Interface.
 Source Code :
//Implement the rate of interest of various banks using interface
// 14/09/2021

interface bank
{
float interest_rate();
}
class axis implements bank
{
public float interest_rate()
{
return 9.5f;
}
}
class ubi implements bank
{
public float interest_rate()
{
return 8.5f;
}
}
class test12345
{
public static void main(String [] args)
{
bank b =new axis();
System.out.println("rate of interest of axis: =" +b.interest_rate());
bank b1 =new ubi();
System.out.println("rate of interest of ubi: =" +b1.interest_rate());
}
}

 Output :
Experiment No. - 32
 Experiment Name :
- Write a JAVA program to implement String.

 Source Code :
// Write a JAVA program to implement String
// 21/09/2021
class StringJava
{
public static void main(String ary[])
{
String Str = "JISCE";
String Str1 = new String("CSE");
char chara[] = {'I',' ','a','m',' ','A','b','i','r',' ','P','a','l'};
String Str2 = new String(chara);
System.out.println(Str);
System.out.println(Str1);
System.out.println(Str2);
}
}

 Output :
Experiment No. - 33
 Experiment Name :
- Write a JAVA program for printing 1st character & last character of
the string using charAt();

 Source Code :
// Write a JAVA program for printing 1st character & last character of the string using
charAt();
// 21/09/2021
class StringCharAt
{
public static void main(String ary[])
{
String Abir = "Abir Pal JISCE";
int length = Abir.length();
char c = Abir.charAt(length-1);
char l = Abir.charAt(0);
System.out.println(c);
System.out.println(l);
}
}

 Output :
Experiment No. - 34
 Experiment Name :
- Write a JAVA program for printing the characters at odd positions &
even positions of a string using charAt() method.

 Source Code :
/*Write a JAVA program for printing the characters at odd positions & even positions of a
string using charAt() method */
// 21/09/2021
class CharAtEvenOdd
{
public static void main(String ary[])
{
String Strr1 = "i am Abir Pal";
char[] ArrODD = new char[500];
char[] ArrEVEN = new char[500];
int j=0,k=0;
for (int i=1;i<Strr1.length();i++)
{
if(i%2==0)
{
ArrEVEN[j] = Strr1.charAt(i);
j++;
}
else
{
ArrODD[k]= Strr1.charAt(i);
k++;
}
}
System.out.println("Even Characters");
for(int i=0;i< 10;i++)
{
System.out.println(ArrEVEN[i]);
}
System.out.println("Odd Characters");
for(int i=0;i< 10;i++)
{
System.out.println(ArrODD[i]);
}
}
}

 Output :
Experiment No. - 35
 Experiment Name :
- Write a JAVA program for Comparing the String using compareTo()
method.

 Source Code :
//Write a JAVA program for Comparing the String using compareTo() method
// 21/09/2021

import java.util.Scanner;
class CompereString
{
public static void main(String ary[])
{
System.out.println("Enter The First String");
Scanner Sc = new Scanner(System.in);
String Str1=Sc.nextLine();
System.out.println("Enter The Second String");
String Str2=Sc.nextLine();
System.out.println(Str1.compareTo(Str2));
}
}

 Output :

Experiment No. - 36
 Experiment Name :
- Write a JAVA program for Concatenating the String using concat() method.

 Source Code :

//Concatination ()
// 21/09/2021
class Concatination
{
public static void main(String args[])
{
String s1="Hello";
String s2="Student";
String s3=s1.concat(" ").concat(s2).concat(".....");
System.out.println(s3);
}
}
 Output :
Experiment No. - 37
 Experiment Name :
- Write a JAVA program for Indexing the String using indexOf() method.

 Source Code :

// 2- indexOf()
// 21/09/2021

class IndexOf
{
public static void main(String args[])
{
String r1="i am from jisce";
int i1=r1.indexOf("jis",8);
int i4=r1.indexOf("jis",16);
int i2=r1.indexOf("a");
int i3=r1.indexOf("zin");
System.out.println("The index of JISCE" +i1);
System.out.println("The index of JISCE" +i4);
}
}

 Output :
Experiment No. - 38
 Experiment Name :
- Write a JAVA program for Implementing the getChars() method.

 Source Code :

// Java program getChars() method - 28/09/2021

class GetChar
{
public static void main(String ary[])
{
String str = "Welcome! to getChars()";

char[] destArray = new char[20];


try
{

str.getChars(7, 18, destArray, 0);


System.out.println(destArray);
}
catch (Exception ex)
{
System.out.println(ex);
}
}
}

 Output :
Experiment No. - 39
 Experiment Name :
- Write a JAVA program for Implementing the indexOf() method

 Source Code :
// Java code indexOf( ) - 28/09/2021

class IndexOf
{
public static void main(String ary[])
{

String wti = new String("Welcome to indexOf()");

System.out.print("Found O after 13th index at position : ");

System.out.println(wti.indexOf('O', 13));
}
}

 Output :
Experiment No. - 40
 Experiment Name :
- Write a JAVA program for Implementing the insert() method.

 Source Code :

// Java code insert() - 28/09/2021

class Insert
{

public static void main(String ary[])


{
StringBuffer sb = new StringBuffer("It is insert()");
sb.insert(3, "123");
System.out.println(sb);
}
}

 Output :
Experiment No. - 41
 Experiment Name :
- Write a JAVA program for Implementing the length() method.

 Source Code :

// java code length() - 28/09/2021


import java.util.*;
class StringLength
{
public static void main(String ary[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string :");
String str = sc.nextLine();
int len = str.length();
System.out.println("string contains " +len+ " characters");

 Output :
Experiment No. - 42
 Experiment Name :
- Write a JAVA program for Implementing the setCharAt() method

 Source Code :

// java code SetCharAt() - 28/09/2021


class SetCharAt
{
public static void main(String ary[])
{
StringBuffer sb = new StringBuffer("abc");
System.out.println("string: " + sb);

System.out.println("character at index 1: " + sb.charAt(1));

sb.setCharAt(1, 'x');
System.out.println("new string: " + sb);

System.out.println("character at index 1: " + sb.charAt(1));


}
}

 Output :
Experiment No. - 43
 Experiment Name :
- Write a JAVA program for Implementing the setLength() method

 Source Code :

//Write a JAVA program for Implementing the setLength() method - 28/09/2021


class SetLength
{
public static void main(String ary[])
{
StringBuffer Demo = new StringBuffer("I am Abir Pal");
System.out.println("Before SetLength: "+Demo.length());
Demo.setLength(20);
System.out.println("After SetLength increase: "+Demo.length()+" "+Demo);
Demo.setLength(6);
System.out.println("After SetLength Decrease: "+Demo.length()+" "+Demo);
}
}

 Output :
Experiment No. - 44
 Experiment Name :
- Write a JAVA program for Implementing the substring() method.

 Source Code :

// Write a JAVA program for Implementing the substring() method - 28/09/2021


class SubString
{
public static void main(String ary[])
{
String SS = new String ("I AM Abir Pal"+","+" Student Of JIS College of Engineering
"+","+"Kalyani");
System.out.println(SS.substring(28));
System.out.println(SS.substring(4,17));
}
}

 Output :
Experiment No. - 45
 Experiment Name :
- Write a JAVA program for Implementing the toString() method.

 Source Code :

// Write a JAVA program for Implementing the toString() method - 28/09/2021


class ToStringJava
{
public static void main(String ary[])
{
int i = 500;
float f = 5015.50F;
String S = Integer.toString(i);
String S1 = Float.toString(f);
System.out.println(i+500);
System.out.println(S+500);
System.out.println(f+500.0050);
System.out.println(S1+500.020);
}
}

 Output :
Experiment No. - 46
 Experiment Name :
- Write JAVA program for implementing the following string methods
append()

 Source Code :
// Write JAVA program for implementing the following string methods append()
// 05/10/2021
class StringMethodAppend
{
public static void main(String ary[])
{
StringBuilder sb = new StringBuilder("The Name of the Student having Id.- JIS/2020/0727 is :
");
System.out.println("\n Before Append() Applied\n");
System.out.println(sb);
sb.append(" Abir Pal ");
System.out.println("\n After Append() Applied\n");
System.out.println(sb);
sb.append(true);
System.out.println("\n Again After Append() Applied\n");
System.out.println(sb);
}
}

 Output :
Experiment No. - 47
 Experiment Name :
- Write JAVA program for implementing the following string methods
delete()

 Source Code :
// Write JAVA program for implementing the following string methods delete()
// 05/10/2021
import java.util.Scanner;
class DeleteMehod
{
public static void main(String ary[])
{
StringBuffer SSS = new StringBuffer("I am From Purba Burdwan");
int x , y;
Scanner scanner = new Scanner(System.in);
System.out.println("\n Before delete() Applied\n");
System.out.println(SSS);
System.out.println("\n Enter The Starting Index:\n");
x=scanner.nextInt();
System.out.println("\n Enter The Ending Index:\n");
y=scanner.nextInt();
SSS.delete(x,y);
System.out.println("\n After delete() Applied\n");
System.out.println(SSS);
}
}

 Output :
Experiment No. - 48
 Experiment Name :
- Write JAVA program for implementing the following string methods
deleteChatAt()

 Source Code :
// Write JAVA program for implementing the following string methods deleteChatAt()
// 05/10/2021

import java.util.Scanner;
class DeleteCharAtMethod {
public static void main(String ary[])
{
StringBuffer SSS = new StringBuffer("I am From India");
int x;
Scanner scanner = new Scanner(System.in);
System.out.println("\n Before deleteCharAt() Applied\n");
System.out.println(SSS);
System.out.println("\n Enter The Char index to be deleted:\n");
x=scanner.nextInt();
SSS.deleteCharAt(x);
System.out.println("\n After deleteCharAt() Applied\n");
System.out.println(SSS);
}}

 Output :
Experiment No. - 49
 Experiment Name :
- Write JAVA program for implementing the following string methods
capacity()

 Source Code :
// Write JAVA program for implementing the following string methods capacity()
// 05/10/2021

import java.util.Scanner;
class capacityMethod
{
public static void main(String ary[])
{
StringBuffer SSS = new StringBuffer();
System.out.println("Default Capacity of StringBuffer SSS: " + SSS.capacity());
SSS= new StringBuffer("K");
System.out.println("After Data Insertion Capacity of StringBuffer SSS: " +
SSS.capacity());
SSS= new StringBuffer("JIS College of Engineering");
System.out.println("After Data Insertion Capacity of StringBuffer SSS: " +
SSS.capacity());
}
}

 Output :
Experiment No. - 50
 Experiment Name :
- Write a JAVA program for handling ArithmeticException using try-
catch block.

 Source Code :
// Write a JAVA program for handling ArithmeticException using try-catch block
// 05/10/2021
class TryCatch
{
public static void main(String ary[])
{
try
{
int data=50/0;
}
catch(ArithmeticException ex)
{
System.out.println(ex);
}
System.out.println("Rest of the code");
}
}

 Output :
Experiment No. - 51
 Experiment Name :
- Write a JAVA program for handling ArrayIndexOutOfBounds
Exception.

 Source Code :
// Write a JAVA program for handling ArrayIndexOutOfBounds Exception.
// 05/10/2021

class ArrayIndexOutOfBounds
{
public static void main(String ary[])
{
int[] myArray = {897, 56, 78, 90, 12, 123, 75};
try{
System.out.println(myArray[20]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println(e);
}
System.out.println("\n Rest of the Code:" + myArray[2]);
}
}
 Output :

Experiment No. - 52
 Experiment Name :
- Write a JAVA program to implement throw keyword.

 Source Code :
// Write a JAVA program to implement throw keyword.
// 05/10/2021

import java.util.Scanner;
class ThrowKeyword
{
public static void main(String ary[])
{
int a=45, b=0, rs;
Scanner scanner = new Scanner(System.in);
b=scanner.nextInt();
try{
if(b==0)
{
throw(new ArithmeticException ("Can not devide by 0"));
}
else
{
rs=a/b;
System.out.println(rs);
}
}
catch(ArithmeticException ex)
{
System.out.println("\n Error: " +ex.getMessage());
}
System.out.println("End the Program");
}
}

 Output :

Experiment No. - 53
 Experiment Name :
- Write a JAVA program to implement throws keyword.

 Source Code :
// Write a JAVA program to implement throws keyword.
// 05/10/2021

class Throws
{
void Divition() throws ArithmeticException
{
int a=45,b=0,rs;
rs=a/b;
System.out.println("\n\t Result is: "+rs);
}
public static void main(String[] args)
{
Throws t = new Throws();
try
{
t.Divition();
}
catch(ArithmeticException Ex)
{
System.out.println("\n Exception Error :"+Ex.getMessage());
}
System.out.println("\n End or Rest of the Program");
}
}

 Output :

Experiment No. - 54
 Experiment Name :
- Write a JAVA program for creating your own package.

 Source Code :
// Write a JAVA program for creating your own package.
// 08/10/2021
// /Creation Of Package in Java

package mypack;
class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}

 Output :
//Implementation Of the User defined Package in Java

import javaNewPack.JavaPackage;
public class JavaPackageImplemention {
public static void main(String[] args)
{
JavaPackage Obj = new JavaPackage();
Obj.show();
Obj.view();
}}

 Output :

Experiment No. - 55
 Experiment Name :
- Write a JAVA program to implement private Access modifier.

 Source Code :
// Write a JAVA program to implement private Access modifier.
// 08/11/2021

class student
{
private int a=50;
private void aaa()
{
System.out.println("we are CSE student");
}
}
class AccessModPrivate
{
public static void main(String args[])
{
student obj=new student();
System.out.println(obj.a);
obj.aaa();
}
}

 Output :
Experiment No. - 55
 Experiment Name :
- Write a JAVA program to implement Default Access modifier.

 Source Code :
// Write a JAVA program to implement default Access modifier.
// 08/11/2021

class student
{
int a=50;
void aaa()
{
System.out.println("we are CSE student");
}
}
class AccessModPrivate
{
public static void main(String args[])
{
student obj=new student();
System.out.println(obj.a);
obj.aaa();
}
}

 Output :

You might also like