20jg5a0503 (14exercises and Extra Programs)
20jg5a0503 (14exercises and Extra Programs)
20jg5a0503 (14exercises and Extra Programs)
EXERCISE:1(a)
Write a JAVA program to display default value of all primitive data type of
JAVA
AIM:
Java program to display default value of all primitive data type of JAVA
SOURCE CODE:
class Defaultvalue_of_datatypes
{
static byte a;
static short s;
static float f;
static int i;
static char c;
static double d;
static boolean b;
public static void main(String args[])
{
System.out.println("Datatype value of byte:"+a);
System.out.println("Datatype value of short:"+s);
System.out.println("Datatype value of float:"+f);
System.out.println("Datatype value of int:"+i);
System.out.println("Datatype value of char:' '"+c);
System.out.println("Datatype value of double:"+d);
20JG5A0503 1|Page
|| CSE R19 JAVA PROGRAMMING
EXERCISE:1(b)
20JG5A0503 2|Page
|| CSE R19 JAVA PROGRAMMING
SOURCE CODE:
import java.util.*;
import java.lang.*;
class Quatratic_eq_roots
{
20JG5A0503 3|Page
|| CSE R19 JAVA PROGRAMMING
{
System.out.println("EQUATION IS LINEAR.\nROOTS ARE
NOT DETERMINED.\nMUST a NOTEQUAL TO 0(a!=0) ");
}
20JG5A0503 4|Page
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
Case:1
20JG5A0503 5|Page
|| CSE R19 JAVA PROGRAMMING
Case2:
Case:3
20JG5A0503 6|Page
|| CSE R19 JAVA PROGRAMMING
Case:4
20JG5A0503 7|Page
NAME: CH. Rohitha Anupama REGNO: 20JG5A0503
EXERCISE:1-(c)
Five Bikers Compete in a race such that they drive at a constant
speed which may or may not be the same as the other. To qualify
the race, the speed of a racer must be more than the average
speed of all 5 racers. Take as input the speed of each racer and
print back the speed of qualifying racers.
AIM:
Java program to take input as the speed of each racers and print
back the speed of qualified racer whom containing the speed is
greater than average
SOURCE CODE:
import java.util.*;
import java.lang.*;
class racedemo
{
public static void main(String[] args)
{
float []a;
a=new float[10];
float average;
float num;
int i,sum=0;
20JG5A0503 8|Page
|| CSE R19 JAVA PROGRAMMING
num=r.nextFloat();
//calculating average
average=sum/num;
System.out.println("average speed is:"+average);
INPUT/OUTPUT:
Case:1
20JG5A0503 10 | P a g e
|| CSE R19 JAVA PROGRAMMING
Case:2
20JG5A0503 11 | P a g e
|| CSE R19 JAVA PROGRAMMING
Strings)
EXERCISE:2-(a)
Write a JAVA program to search for an element in a given list of
elements using binary search mechanism.
AIM:
Program to search for an element in a given list of elements using
binary search mechanism.
SOURCE CODE:
import java.util.Scanner;
class binarysearch
{
public static void main(String args[])
{
int n, i,j,temp,num,first, last, middle,k=0;
int a[ ]=new int[20];
//to input an integer value from the user and assign it to the
variable n
n = b.nextInt();
for(i=0;i<n;i++)
{
20JG5A0503 13 | P a g e
|| CSE R19 JAVA PROGRAMMING
//it repeats up to the specified n value minus one(5-1=4) it will reat upt
to 4 times
for(j=0;j<n-1;j++)
{
//it specified up the n value minus one(5-1=4) it will reat upt to 4 times
for(j=0;j<n-1;j++)
{
20JG5A0503 14 | P a g e
|| CSE R19 JAVA PROGRAMMING
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
k=2;
}
}
}
switch(k)
{
case 1:
20JG5A0503 15 | P a g e
|| CSE R19 JAVA PROGRAMMING
//it repeats until the first value is lessthan or equal to last value
while( first <= last )
{
INPUT/OUTPUT:
Case:1
Case:2
20JG5A0503 17 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 18 | P a g e
NAME: CH. Rohitha Anupama REGNO: 20JG5A0503
EXERCISE:2-(b)
Write a JAVA program to sort for an element in a given list of
elements using bubble sort.
AIM:
Program to sort for an element in a given list of elements using
bubble sort.
SOURCE CODE:
import java.util.Scanner;
class bubblesort
{
public static void main(String args[])
{
int i,n,temp,j,k=0;
int a[]=new int[20];
n=bu.nextInt();
System.out.println("Enter the elements in sorted or unsorted
order:");
20JG5A0503 19 | P a g e
|| CSE R19 JAVA PROGRAMMING
//it repeats up to the specified n value minus one(5-1=4) it will reat upt
to 4 times
for(j=0;j<n-1;j++)
{
//it specified up the n value minus one(5-1=4) it will reat upt to 4 times
20JG5A0503 20 | P a g e
|| CSE R19 JAVA PROGRAMMING
for(j=0;j<n-1;j++)
{
}
}
}
INPUT/OUTPUT:
Case:1
Case:2
20JG5A0503 22 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 23 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:(2)-(c)
Write a JAVA program to sort for an element in a given list of
elements using merge sort.
AIM:
Program to sort for an element in a given link of element using
merge sort.
SOURCE CODE:
//to implement mergesort program.
import java.util.Scanner;
public class MergeSort
{
void merge(int arr[], int beg, int mid, int end)
{
20JG5A0503 24 | P a g e
|| CSE R19 JAVA PROGRAMMING
int i = 0, j = 0;
int k = beg;
while (i<l&&j<r)
{
if (LeftArray[i] <= RightArray[j])
{
arr[k] = LeftArray[i];
i++;
}
else
{
arr[k] = RightArray[j];
j++;
}
k++;
}
while (i<l)
{
arr[k] = LeftArray[i];
i++;
k++;
}
while (j<r)
{
arr[k] = RightArray[j];
j++;
20JG5A0503 25 | P a g e
|| CSE R19 JAVA PROGRAMMING
k++;
}
}
int i,n;
Scanner m=new Scanner(System.in);
System.out.println("enter the number of elements in the
array:");
n=m.nextInt();
int arr[]=new int[n];
System.out.println("Enter the elements of the array one by
one:");
20JG5A0503 26 | P a g e
|| CSE R19 JAVA PROGRAMMING
for(i=0;i<n;i++)
{
arr[i]=m.nextInt();
}
System.out.println("\nSorted array");
for(i =0; i<arr.length;i++)
{
System.out.print(“\t”+arr[i]);
}
}
}
INPUT/OUTPUT:
20JG5A0503 27 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 28 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:(2(d))
Write a JAVA program using StringBuffer to delete, remove
character
AIM:
Program to write a JAVA program using StringBuffer to delete,
remove character
SOURCE CODE:
class stringbufferdemo
{
public static void main(String[] args)
{
StringBuffer sb1 = new StringBuffer("Hello Everyone");
sb1.delete(0,6);
System.out.println(sb1);
StringBuffer sb2 = new StringBuffer("Some Content");
System.out.println(sb2);
sb2.delete(0, sb2.length());
System.out.println("----"
+sb2);
StringBuffer sb3 = new StringBuffer("Hello Everyone");
sb3.deleteCharAt(4);
System.out.println(sb3);
}
}
INPUT/OUTPUT:
20JG5A0503 29 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 30 | P a g e
|| CSE R19 JAVA PROGRAMMING
CLASS, OBJECTS
EXERCISE:3(a)
Write a JAVA program to implement class mechanism. Create a
class, methods and invoke them inside main method.
AIM:
Program to implement class mechanism and to create a class ,
method and invoke them inside the main method.
SOURCE CODE:
import java.util.Scanner;
class method
{
void display()
{
int l=50,b=90;
System.out.println("with no return type and no parameter-
list:");
System.out.println("the length is:"+l);
System.out.println("the breath is:"+b);
}
void area_of_rec(int l,int b)
{
20JG5A0503 31 | P a g e
|| CSE R19 JAVA PROGRAMMING
int area=l*b;
System.out.println("the area of rectangle is:"+area);
}
int area_of_tri()
{
System.out.println("with return type and no parameter-list:");
int h=10,b=20;
int area=h*(b/2);
return area;
}
int area_of_sq(int s)
{
System.out.println("with return type and with parameter-list:");
return (s*s);
}
}
class Invoke_method_inside_main
{
public static void main(String args[])
{
int l,b,s;
Scanner mm=new Scanner(System.in);
System.out.println("enter the length:");
l=mm.nextInt();
System.out.println("enter the breath:");
b=mm.nextInt();
20JG5A0503 32 | P a g e
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
20JG5A0503 33 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:3-(b)
Write a JAVA program to implement constructor.
AIM:
Program to implement constructor.
SOURCE CODE:
import java.util.Scanner;
class implement_con
{
int l,b;
implement_con()
{
System.out.println("It is a default constructor");
l=20;
b=30;
}
int area_of_rec()
{
int area=l*b;
return area;
}
int a;
implement_con(int s)
{
System.out.println("it is a parameterized constructor:");
a=s;
20JG5A0503 34 | P a g e
|| CSE R19 JAVA PROGRAMMING
}
int area_of_sq()
{
return a*a;
}
}
class constructor
{
public static void main(String args[])
{
int s;
Scanner con=new Scanner(System.in);
System.out.println("enter the side:");
s=con.nextInt();
implement_con c=new implement_con();
int tir=c.area_of_rec();
System.out.println("the area of rectangle is:"+tir);
implement_con co=new implement_con(s);
int sq=co.area_of_sq();
System.out.println("the area of square is:"+sq);
}
}
INPUT/OUTPUT:
20JG5A0503 35 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 36 | P a g e
|| CSE R19 JAVA PROGRAMMING
(METHODS)
EXERCISE:4-(a)
Write a JAVA program to implement constructor overloading .
AIM:
Program to implement constructor overloading.
SOURCE CODE:
import java.util.Scanner;
class constructor
{
int s;
constructor()
{
System.out.println("It is a default constructor");
s=4;
}
constructor(int a)
{
System.out.println("it is a parameterized constructor:");
s=a;
}
int area_of_sq()
{
return s*s;
}
}
20JG5A0503 37 | P a g e
|| CSE R19 JAVA PROGRAMMING
class con_overloading
{
public static void main(String args[])
{
int side;
Scanner c_over=new Scanner(System.in);
System.out.println("enter the side:");
side=c_over.nextInt();
constructor c=new constructor();
int a1=c.area_of_sq();
System.out.println("the area of square is:"+a1);
constructor co=new constructor(side);
int a2=co.area_of_sq();
System.out.println("the area of square is:"+a2);
}
}
INPUT/OUTPUT:
20JG5A0503 38 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:4-(b)
20JG5A0503 39 | P a g e
|| CSE R19 JAVA PROGRAMMING
AIM:
program to implement method overloading.
SOURCE CODE:
import java.util.Scanner;
class method
{
int l=10,b=20;
int area_of_rec()
{
System.out.println("with return type and no parameter-list:");
return l*b;
}
int area_of_rec(int l,int b)
{
System.out.println("with return type and with parameter-
list:");
return l*b;
}
}
class method_overloading
{
public static void main(String args[])
{
int l,b;
Scanner mo=new Scanner(System.in);
20JG5A0503 40 | P a g e
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
20JG5A0503 41 | P a g e
|| CSE R19 JAVA PROGRAMMING
(INHERITANCE)
EXERCISE:5-(a)
Write a JAVA program to implement Single Inheritance.
AIM:
Program to implement Single Inheritance.
SOURCE CODE:
import java.util.Scanner;
class Single_inheritance
{
20JG5A0503 42 | P a g e
|| CSE R19 JAVA PROGRAMMING
int a=10;
Single_inheritance()
{
System.out.println("the construtor in parent class.");
}
int display1(){
int f=a*a;
return(f);
}
}
class Single extends Single_inheritance
{
int l,b;
Single(int c,int d)
{
l=c;
b=d;
}
int display()
{
System.out.println("I am a child of single_inheritance");
int e=l*b;
return(e);
}
}
class sing_inheri
{
20JG5A0503 43 | P a g e
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
20JG5A0503 44 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 45 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:5-(b)
Write a JAVA program to implement multilevel Inheritance
AIM:
program to implement multilevel Inheritance
SOURCE CODE:
import java.util.Scanner;
import static java.lang.Math.*;
class sq_area
{
int a=10;
sq_area()
{
System.out.println("This is a constructor of parenet sq_area");
}
int reveal()
{
int e=a*a;
return(a);
}
}
class rec_area extends sq_area
{
int l=40;
int b=10;
rec_area
20JG5A0503 46 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
System.out.println("\nThis is a constructor of parenet rec_area");
}
int show()
{
int f=l*b;
return(f);
}
}
class cir_area extends rec_area
{
int r;
cir_area(int r)
{
this.r=r;
System.out.println("\nThis is a constructor is a child of sq_area
and rec_area parent classes");
}
double display()
{
double g=Math.PI*r*r;
return(g);
}
}
class main_area
{
20JG5A0503 47 | P a g e
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
20JG5A0503 48 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:5-(c)
20JG5A0503 49 | P a g e
|| CSE R19 JAVA PROGRAMMING
AIM:
Java program for abstract class to find areas of different shapes
SOURCECODE:
import java.util.Scanner;
abstract class shape
{
abstract double area(double l ,double b,double s);
}
class rectangle extends shape
{
double area(double l , double b,double s)
{
return l*b;
}
}
class triangle extends shape
{
double area(double b, double h,double s)
{
return 0.5*b*h;
}
}
class square extends shape
{
20JG5A0503 50 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
double l,b,s;
Scanner a=new Scanner(System.in);
System.out.println("Enter the length:");
l=a.nextDouble();
System.out.println("Enter the breath:");
b=a.nextDouble();
System.out.println("Enter the side:");
s=a.nextDouble();
rectangle r1=new rectangle();
triangle t1=new triangle();
square s1=new square();
System.out.println("The area of rectangle is:"+r1.area(l,b,s));
System.out.println("The area of triangle is: "+t1.area(l,b,s));
System.out.println("The area of square is: "+s1.area(l,b,s));
}
}
20JG5A0503 51 | P a g e
|| CSE R19 JAVA PROGRAMMING
INPUT/OUTPUT:
INHERITANCE(CONTINUED)
20JG5A0503 52 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:6-(a)
Write a JAVA program give example for “super” keyword
AIM:
JAVA program give example for “super” keyword
SOURCECODE:
import java.util.*;
class super_demo
{
int l,s;
super_demo()
{
System.out.println("\nThis is a non parametarized
constructor-\n which is returning the out of area of rectangle:");
l=10;
}
super_demo(int s)
{
this.s=s;
System.out.println("\nThis is a one parametarized
constructor-\n which is returning the out of area of Square:");
}
}
class super_class extends super_demo
{
int b;
20JG5A0503 53 | P a g e
|| CSE R19 JAVA PROGRAMMING
super_class()
{
super();
b=10;
}
int area()
{
return l*b;
}
super_class(int s)
{
super(s);
}
int area1()
{
return s*s;
}
}
class Superdemo
{
public static void main(String args[])
{
int s;
Scanner a=new Scanner(System.in);
System.out.println("Enter the side :");
s=a.nextInt();
super_class a1=new super_class();
20JG5A0503 54 | P a g e
|| CSE R19 JAVA PROGRAMMING
int r=a1.area();
System.out.println("\nThe area of rectangle is:"+r);
super_class a2=new super_class(s);
int t=a2.area1();
System.out.println("\nThe area of square is:"+t);
}
}
INPUT/OUTPUT:
EXERCISE:6-(b)
20JG5A0503 55 | P a g e
|| CSE R19 JAVA PROGRAMMING
AIM:
JAVA program to implement Interface.
DESCRIPTION:
SOURCE CODE:
import java.util.*;
interface Dimensions
20JG5A0503 56 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
int area(int l,int b);
}
interface Area extends Dimensions
{
void show();
}
class rectangle
{
public int area(int l, int b)
{
return l*b;
}
public void show()
{
System.out.println("this is a interface area ");
}
}
class interface_demo
{
public static void main (String args[])
{
int l,b,e;
Scanner a=new Scanner(System.in);
System.out.println("the length is:");
l=a.nextInt();
20JG5A0503 57 | P a g e
|| CSE R19 JAVA PROGRAMMING
}
}
INPUT/OUTPUT:
20JG5A0503 58 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Exception)
Exercise - 7
Write a JAVA program that describes exception handling
mechanism
AIM:
JAVA program that implements Runtime polymorphism
SOURCE CODE:
class exception_handing
{
public static void main(String args[])
{
try
{
int a=10,b=0;
int c=a/b;
System.out.println(c);
}
catch(ArithmeticException e)
{
System.out.println(e);
}
finally{
20JG5A0503 59 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 60 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:7(b)
write a JAVA program Illustrating Multiple catch
AIM:
JAVA program Illustrating Multiple catch polymorphism
SOURCE CODE:
class multitrydemo
{
public static void main(String args[])
{
try
{
int a=10,b=5;
int c=a/b;
int d[]={0,1};
System.out.println(d[10]);
System.out.println(c);
}
catch(ArithmeticException e)
{
System.out.println(e);
}
catch(ArrayIndexOutOfBoundsException e)
{
20JG5A0503 61 | P a g e
|| CSE R19 JAVA PROGRAMMING
System.out.println(e);
}
System.out.println("After the catch statement");
}
}
INPUT/OUTPUT:
20JG5A0503 62 | P a g e
|| CSE R19 JAVA PROGRAMMING
RUNTIME POLYMORPHISM
EXERCISE:8(a)
Write a JAVA program that implements Runtime polymorphism
AIM:
JAVA program that implements Runtime polymorphism
SOURCE CODE:
class auto
{
void fuel()
{
System.out.println("\nthis is a parent class of both classes");
System.out.println("auto use desiel fuel to work");
}
}
class bike extends auto
{
void fuel()
{
System.out.println("\nthis is a child class of auto");
System.out.println("Bike use petrol fuel to work");
}
}
class car extends auto
{
void fuel()
20JG5A0503 63 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
System.out.println("\nthis is a child class of auto");
System.out.println("Car use both petrol and desiel to work");
}
}
class poly_runtime
{
public static void main(String args[])
{
auto obj0=new auto();
bike obj1=new bike();//upcasting
car obj2=new car();//upcasting
auto var;//create an object for class auto
var=obj0;
var.fuel();
var=obj1;//access the bike object by using auto object
var.fuel();
var=obj2;
var.fuel();
}
}
INPUT/OUTPUT:
20JG5A0503 64 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 65 | P a g e
|| CSE R19 JAVA PROGRAMMING
EXERCISE:8-(b)
AIM:
Case Study:
DESCRIPTION:
Dynamic method dispatch (Runtime-polymorphism) is the mechanism
by which a call to an overridden method is resolved at run time, rather
than compile time.
20JG5A0503 66 | P a g e
|| CSE R19 JAVA PROGRAMMING
UPCASTING
Superclass obj=new Subclass
Superclass
extends
Subclass
Therefore, if a superclass contains a method that is overridden by a
subclass, then when different types of objects are referred to through
a
superclass reference variable, different versions of the method are
executed.
SOURCECODE:(without upcasting)
class Vehicle{
public void move(){
System.out.println("Vehicles can move!!");
}
}
class runtime_polymorphism{
public static void main(String[] args){
Vehicle vh1=new Vehicle();
Vehicle vh=new MotorBike(); //upcasting
vh1.move();
vh.move();
}
}
INPUT/OUTPUT:
class Vehicle{
public void move(){
System.out.println("Vehicles can move!!");
}
}
class MotorBike extends Vehicle{
public void move(){
System.out.println("MotorBike can move and accelerate too!!");
}
}
class runtime_polymorphism{
public static void main(String[] args){
Vehicle vh=new Vehicle();
MotorBike vh1=new MotorBike();
Vehicle var;
var=vh;
var.move();
var=vh1;
var.move();
}
}
INPUT/OUTPUT:
20JG5A0503 69 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 70 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 9
write a JAVA program for creation of Illustrating throw.
AIM:
JAVA program for creation of Illustrating throw
Source code:
class throw_excep
{
public static void main(String args[])
{
try
{
int a=10/0;
throw new Exception ("There is mo value to print.");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Input/output:
20JG5A0503 71 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 72 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 9(b)
write a JAVA program for creation of Illustrating finally.
AIM:
JAVA program for creation of Illustrating finally.
Source code:
Class finally_ex
{
public static void main(String args[])
{
try
{
int a=10,b=0;
int c=a/b;
System.out.println(c);
}
catch(ArithmeticException e)
{
System.out.println(e);
}
finally
20JG5A0503 73 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
System.out.println("This is inside finally
block");
}
}
}
Input/output:
20JG5A0503 74 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 9(c)
write a JAVA program for creation of Java Built-in
Exceptions
AIM:
JAVA program for creation of Java Built-in Exceptions
Source code:
import java.util.Scanner;
class Built_Exceptiondemo
{
public static void main(String args[])
{
try
{
Scanner q= new Scanner(System.in);
System.out.println("Enter the a value:");
int a=q.nextInt() ;
System.out.println("Enter the b value:");
int b=q.nextInt() ;
System.out.println("the a value: "+a);
System.out.println("the b value: "+b);
int c = a/b;
System.out.println ("the value is: "+c);
System.out.println("\nEnter the string value: ");
String f=q.next();
20JG5A0503 75 | P a g e
|| CSE R19 JAVA PROGRAMMING
Input/output:
Case:1
20JG5A0503 76 | P a g e
|| CSE R19 JAVA PROGRAMMING
Case2:
Case3:
20JG5A0503 77 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 78 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 9(d)
write a JAVA program for creation of Java user-defined
Exceptions
AIM:
JAVA program for creation of Java user-defined
Exceptions
Source code:
import java.lang.*;
import java.util.*;
class Stack_over_flowException extends Exception{
Stack_over_flowException(String s){
super(s);
}
}
class Stack_under_flowException extends Exception{
Stack_under_flowException(String s){
super(s);
}
}
class Custom_Exception{
int[] item;
int stackTop;
20JG5A0503 79 | P a g e
|| CSE R19 JAVA PROGRAMMING
if ( stackTop == 0 )
{
throw new Stack_under_flowException("Stack is empty, you
cannot do pop operation.");
}
20JG5A0503 80 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 81 | P a g e
|| CSE R19 JAVA PROGRAMMING
int v=c.nextInt();
while(v>=1){
System.out.println("Enter number");
x = c.nextInt();
s.push(x);
System.out.println("push(" + x + ")");
v--;
}
}
catch ( Exception e )
{
20JG5A0503 82 | P a g e
|| CSE R19 JAVA PROGRAMMING
Input/output:
Case:1(with no exception)
20JG5A0503 83 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 84 | P a g e
|| CSE R19 JAVA PROGRAMMING
Case2(with exception)
20JG5A0503 85 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 86 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Threads)
Exercise – 10(a(i))
write a JAVA program that creates threads by extending
seconds
AIM:
JAVA program that creates threads by extending Thread
Source code:
class Thread1 extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
sleep(1000);
20JG5A0503 87 | P a g e
|| CSE R19 JAVA PROGRAMMING
System.out.println("good morning");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thread2 extends Thread
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
sleep(2000);
System.out.println("hello");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
20JG5A0503 88 | P a g e
|| CSE R19 JAVA PROGRAMMING
c1.start();
}
}
Input/output:
Exercise – 10(a(ii))
20JG5A0503 90 | P a g e
|| CSE R19 JAVA PROGRAMMING
seconds
AIM:
JAVA program that creates threads by extending
seconds
Source code:
class Thread1 implements Runnable
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
Thread.sleep(1000);
System.out.println("good morning");
}
20JG5A0503 91 | P a g e
|| CSE R19 JAVA PROGRAMMING
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thread2 implements Runnable
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
Thread.sleep(2000);
System.out.println("hello");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thread3 implements Runnable
{
20JG5A0503 92 | P a g e
|| CSE R19 JAVA PROGRAMMING
t2.start();
t3.start();
}
}
Input/output:
20JG5A0503 94 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 95 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 10(b)
write a program illustrating isAlive and join ()
AIM:
program illustrating isAlive and join ()
Source code:
class Thread1 extends Thread
{
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
sleep(1000);
System.out.println("Thread1: good morning");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thread2 extends Thread
20JG5A0503 96 | P a g e
|| CSE R19 JAVA PROGRAMMING
{
public void run()
{
try
{
for(int j=1;j<=10;j++)
{
sleep(2000);
System.out.println("Thread2: hello");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Thread3 extends Thread
{
public void run()
{
try
{
for(int k=1;k<=10;k++)
{
sleep(3000);
System.out.println("Thread3: welcome");
20JG5A0503 97 | P a g e
|| CSE R19 JAVA PROGRAMMING
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class isalive_prog
{
public static void main(String args[])
{
Thread1 a1=new Thread1();
Thread2 b1=new Thread2();
Thread3 c1=new Thread3();
a1.start();
b1.start();
c1.start();
System.out.println("the thread is alive or not: "+a1.isAlive());
System.out.println("the thread is alive or not: "+b1.isAlive());
System.out.println("the thread is alive or not: "+c1.isAlive());
try
{
a1.join();
b1.join();
c1.join();
}
20JG5A0503 98 | P a g e
|| CSE R19 JAVA PROGRAMMING
catch(InterruptedException e)
{
System.out.println(e);
}
System.out.println("the thread is alive or not: "+a1.isAlive());
System.out.println("the thread is alive or not: "+b1.isAlive());
System.out.println("the thread is alive or not: "+c1.isAlive());
}
}
Input/output:
20JG5A0503 99 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 100 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 10(c)
write a Program illustrating Daemon Threads
AIM:
Program illustrating Daemon Threads
Source code:
class Thread1 extends Thread
{
public void run()
{
if(Thread.currentThread().isDaemon())
System.out.println("daemon thread is working now");
else
System.out.println("user thread working now");
}
}
class daemondemo
{
public static void main(String[] args)
{
Thread1 a1=new Thread1();
Thread1 a2=new Thread1();
Thread1 a3=new Thread1();
a1.setDaemon(true);
a1.start();
20JG5A0503 101 | P a g e
|| CSE R19 JAVA PROGRAMMING
a2.start();
a3.start();
}
}
Input/output:
20JG5A0503 102 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Threads continuity)
Exercise – 11(a)
Problem
AIM:
Source code:
class use
{
int n;
boolean b=false;
synchronized int get()
{
if(!b)
try
{
wait();
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Got:"+n);
20JG5A0503 103 | P a g e
|| CSE R19 JAVA PROGRAMMING
b=false;
notify();
return n;
}
synchronized void put(int n)
{
if(b)
try
{
wait();
}
catch(Exception e)
{
System.out.println(e);
}
this.n=n;
b=true;
System.out.println("Put:"+n);
notify();
}
}
class producer implements Runnable
{
use a1;
Thread t1;
producer(use a1)
{
20JG5A0503 104 | P a g e
|| CSE R19 JAVA PROGRAMMING
this.a1=a1;
t1=new Thread(this);
t1.start();
}
public void run()
{
for(int i=1;i<=10;i++)
{
a1.put(i);
}
}
}
class consumer implements Runnable
{
use a1;
Thread t1;
consumer(use a1)
{
this.a1=a1;
t1=new Thread(this);
t1.start();
}
public void run()
{
for(int j=1;j<=10;j++)
{
a1.get();
20JG5A0503 105 | P a g e
|| CSE R19 JAVA PROGRAMMING
}
}
}
class produ_consu_demo
{
public static void main(String args[])
{
use a1=new use();
producer p1=new producer(a1);
consumer c1=new consumer(a1);
}
}
Input/output:
20JG5A0503 106 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 11(b)
write a case study on thread Synchronization
problem
AIM:
case study on thread Synchronization after
Source code:
20JG5A0503 107 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 108 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Packages)
Exercise – 12(a)
write a JAVA program illustrate class path
AIM:
JAVA program illustrate class path
Source code:
import java.net.URL;
import java.net.URLClassLoader;
public class App
{
public static void main(String[] args)
{
ClassLoader sysClassLoader=
ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
for(int i=0; i< urls.length; i++)
{
System.out.println(urls[i].getFile());
}
}
}
Input/output:
20JG5A0503 109 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 110 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 12(b)
write a case study on including in class path in
AIM:
case study on including in class path in your os
Source c:
20JG5A0503 111 | P a g e
|| CSE R19 JAVA PROGRAMMING
Step-1:
20JG5A0503 112 | P a g e
|| CSE R19 JAVA PROGRAMMING
Step-2:
20JG5A0503 113 | P a g e
|| CSE R19 JAVA PROGRAMMING
Step-3:
20JG5A0503 114 | P a g e
|| CSE R19 JAVA PROGRAMMING
Step-4:
Step-5:
Click OK
20JG5A0503 115 | P a g e
|| CSE R19 JAVA PROGRAMMING
Click OK
20JG5A0503 116 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 117 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 12(c)
write a JAVA program that import and use the defined
AIM:
Source code:
package Gas.solids;
Input/output:
20JG5A0503 118 | P a g e
|| CSE R19 JAVA PROGRAMMING
class iron{
void show(){
System.out.println("Iron: ");
}
}
class mole{
public static void main(String args[]){
Gas.solids.solid s=new Gas.solids.solid();
iron i=new iron();
20JG5A0503 119 | P a g e
|| CSE R19 JAVA PROGRAMMING
i.show();
s.display();
}
}
Input/output:
20JG5A0503 120 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Applets)
Exercise – 13(a)
write a JAVA program to paint like paint brush in
applet
AIM:
Source code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
addMouseMotionListener(this);
setBackground(Color.red);
20JG5A0503 121 | P a g e
|| CSE R19 JAVA PROGRAMMING
Graphics g=getGraphics();
g.setColor(Color.white);
<html>
</applet>
</html>
Input/output:
20JG5A0503 122 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 123 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 13(b)
write a JAVA program to display analog clock
using Applet.
AIM:
JAVA program to display analog clock using
Applet.
Source code:
import java.applet.Applet;
import java.awt.*;
import java.util.*;
@Override
new Thread() {
@Override
20JG5A0503 124 | P a g e
|| CSE R19 JAVA PROGRAMMING
while (true) {
repaint();
delayAnimation();
}.start();
try {
Thread.sleep(1000);
catch (InterruptedException e) {
e.printStackTrace();
20JG5A0503 125 | P a g e
|| CSE R19 JAVA PROGRAMMING
@Override
// 12 hour format
hour -= 12;
g.setColor(Color.black);
20JG5A0503 126 | P a g e
|| CSE R19 JAVA PROGRAMMING
// Labeling
g.setColor(Color.pink);
double angle;
int x, y;
x = (int)(Math.cos(angle) * 100);
y = (int)(Math.sin(angle) * 100);
g.setColor(Color.red);
20JG5A0503 127 | P a g e
|| CSE R19 JAVA PROGRAMMING
x = (int)(Math.cos(angle) * 80);
y = (int)(Math.sin(angle) * 80);
g.setColor(Color.blue);
x = (int)(Math.cos(angle) * 50);
y = (int)(Math.sin(angle) * 50);
20JG5A0503 128 | P a g e
|| CSE R19 JAVA PROGRAMMING
g.setColor(Color.green);
<html>
</applet>
</html>
Input/output:
20JG5A0503 129 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 130 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 13(c)
Write a JAVA program to create different shapes
AIM:
Source code:
import java.awt.*;
import java.applet.*;
20JG5A0503 131 | P a g e
|| CSE R19 JAVA PROGRAMMING
int x[]={10,220,220};
int y[]={400,400,520};
int n=3;
g.setColor(Color.green);
g.drawLine(10,30,200,30);
g.setColor(Color.blue);
g.drawRect(30,40,200,30);
g.setColor(Color.blue);
g.fillRect(50,80,200,30);
g.setColor(Color.orange);
g.drawRoundRect(70,120,200,30,20,20);
g.setColor(Color.orange);
g.fillRoundRect(90,160,200,30,20,20);
g.setColor(Color.blue);
g.drawOval(110,200,200,30);
g.setColor(Color.pink);
g.fillOval(130,240,40,40);
g.setColor(Color.yellow);
20JG5A0503 132 | P a g e
|| CSE R19 JAVA PROGRAMMING
g.drawArc(150,290,200,30,0,180);
g.setColor(Color.yellow);
g.fillArc(170,330,200,30,0,180);
g.setColor(Color.pink);
<html>
</applet>
</html>
Input/output:
20JG5A0503 133 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 134 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Event Handling)
Exercise – 14(a)
Write a JAVA program that display the x and y
AIM:
Source code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
int x, y;
String str="";
20JG5A0503 135 | P a g e
|| CSE R19 JAVA PROGRAMMING
addMouseListener(this);
addMouseMotionListener(this);
x = e.getX();
y = e.getY();
repaint();
x = e.getX();
y = e.getY();
repaint();
x = e.getX();
20JG5A0503 136 | P a g e
|| CSE R19 JAVA PROGRAMMING
y = e.getY();
repaint();
x = e.getX();
y = e.getY();
repaint();
x = e.getX();
y = e.getY();
repaint();
20JG5A0503 137 | P a g e
|| CSE R19 JAVA PROGRAMMING
x = e.getX();
y = e.getY();
repaint();
x = e.getX();
y = e.getY();
repaint();
20JG5A0503 138 | P a g e
|| CSE R19 JAVA PROGRAMMING
<html>
</applet>
</html>
Input/output:
20JG5A0503 139 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 140 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 141 | P a g e
|| CSE R19 JAVA PROGRAMMING
Exercise – 14(b)
Write a JAVA program that display the x and y
AIM:
Source code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
int x,y;
addKeyListener(this);
requestFocus();
x=100;
y=200;
repaint();
x=100;
y=400;
repaint();
s1=s1+ke.getKeyChar();
repaint();
g.drawString(s1,x,y);
20JG5A0503 143 | P a g e
|| CSE R19 JAVA PROGRAMMING
<html>
</applet>
</html>
Input/output:
20JG5A0503 144 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 145 | P a g e
|| CSE R19 JAVA PROGRAMMING
(STRINGS)
(Extra Programs-1)
functions
AIM:
functions
Source code:
import java.lang.*;
String str="Hello,Hi";
20JG5A0503 146 | P a g e
|| CSE R19 JAVA PROGRAMMING
System.out.println("toCharArray()");
System.out.println(c);
System.out.println("getBytes()");
System.out.println(b);
//comparing strings
String s1="rohi";
String s2="anu";
String s3="anu";
System.out.println("s1.equals(s2)::"+s1.equals(s2));
//equals()
System.out.println("s2.equals(s3)::"+s2.equals(s3));
System.out.println("s2==s4::"+s2==s4);
20JG5A0503 147 | P a g e
|| CSE R19 JAVA PROGRAMMING
System.out.println("s2.compareTo(s3)::"+s2.compareTo(s3));
//compareTo()
System.out.println("s1.compareTo(s2)::"+s1.compareTo(s2));
System.out.println("s2.compareTo(s1)::"+s2.compareTo(s1));
//modifying strings
System.out.println("s1.concat(s2)::"+s1.concat(s2));
//concat()
System.out.println("s1.replace('o','r')::"+s1.replace('o','r'));
//replace()
System.out.println("s1.substring(1,3)::"+s1.substring(1,3));
//substring()
//searching strings
System.out.println("First occurance:"+first_i);
System.out.println("Last occurance:"+last_i);
Input/output:
20JG5A0503 148 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 149 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Extra Program-2)
functions
AIM:
Source code:
import java.lang.Exception;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
throws Exception
StringBuilder str
20JG5A0503 150 | P a g e
|| CSE R19 JAVA PROGRAMMING
// print string
System.out.println("String = "
+ str.toString());
// print string
+ reverseStr.toString
());
str.appendCodePoint(44);
+ str);
// get capacity
20JG5A0503 151 | P a g e
|| CSE R19 JAVA PROGRAMMING
+ capacity);
Input/output:
20JG5A0503 152 | P a g e
|| CSE R19 JAVA PROGRAMMING
(This usage)
(Extra Program-3(a))
AIM:
Source code:
import java.util.Scanner;
class this_currentclass_instance{
int id;
String name;
int marks;
this.id=id;
this.name=name;
this.marks=marks;
void display(){
20JG5A0503 153 | P a g e
|| CSE R19 JAVA PROGRAMMING
class thisdemo1{
String name=s.nextLine();
int id=s.nextInt();
int marks=s.nextInt();
this_currentclass_instance s1=new
this_currentclass_instance(id,name,marks);
Input/output:
20JG5A0503 154 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 155 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Extra Program-3(b))
AIM:
Source code:
import java.util.Scanner;
class this_invokecurrent_class{
int id;
String name;
int marks;
id=idno;
name=s_name;
marks=s_marks;
void show(){
20JG5A0503 156 | P a g e
|| CSE R19 JAVA PROGRAMMING
String name=s.nextLine();
int id=s.nextInt();
int marks=s.nextInt();
void display(){
this.show();
class thisdemo2{
String name=s.nextLine();
int id=s.nextInt();
20JG5A0503 157 | P a g e
|| CSE R19 JAVA PROGRAMMING
int marks=s.nextInt();
this_invokecurrent_class s1=new
this_invokecurrent_class(id,name,marks);
s1.display();
Input/output:
20JG5A0503 158 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Extra Program-3(c))
AIM:
Source code:
import java.util.Scanner;
class this_currentclass_constructor{
int id;
String name;
int marks;
this_currentclass_constructor(){
String name=s.nextLine();
int id=s.nextInt();
20JG5A0503 159 | P a g e
|| CSE R19 JAVA PROGRAMMING
int marks=s.nextInt();
this();
class thisdemo3{
String name=s.nextLine();
int id=s.nextInt();
int marks=s.nextInt();
this_currentclass_constructor s1=new
this_currentclass_constructor(id,name,marks);
20JG5A0503 160 | P a g e
|| CSE R19 JAVA PROGRAMMING
Input/output:
20JG5A0503 161 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Jdbc connection)
(Extra Program-4)
AIM:
Source code:
import java.sql.*;
// Database credentials
20JG5A0503 162 | P a g e
|| CSE R19 JAVA PROGRAMMING
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn =
DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
20JG5A0503 163 | P a g e
|| CSE R19 JAVA PROGRAMMING
//Display values
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
20JG5A0503 164 | P a g e
|| CSE R19 JAVA PROGRAMMING
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample
Input/output:
20JG5A0503 165 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 166 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Extra Program-5)
process
AIM:
Source code:
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.sql.*;
/**
*/
20JG5A0503 167 | P a g e
|| CSE R19 JAVA PROGRAMMING
parameterizedBatchUpdate();
if (e instanceof SQLException) {
e.printStackTrace(System.err);
Throwable t = ex.getCause();
while (t != null) {
t = t.getCause();
20JG5A0503 168 | P a g e
|| CSE R19 JAVA PROGRAMMING
.getConnection("jdbc:mysql://localhost:3306/studentdetails",
"root", "");
PreparedStatement preparedStatement =
connection.prepareStatement(INSERT_USERS_SQL)) {
connection.setAutoCommit(false);
preparedStatement.setString(1, "Rohitha");
preparedStatement.setInt(2, 102);
preparedStatement.setInt(3, 96);
preparedStatement.addBatch();
int[] cou1=preparedStatement.executeBatch();;
20JG5A0503 169 | P a g e
|| CSE R19 JAVA PROGRAMMING
preparedStatement.setString(1, "Rohitha");
preparedStatement.setInt(2, 102);
preparedStatement.setInt(3, 96);
preparedStatement.addBatch();
int[] cou2=preparedStatement.executeBatch();;
preparedStatement.setString(1, "Rohi");
preparedStatement.setInt(2, 103);
preparedStatement.setInt(3, 96);
preparedStatement.addBatch();
int[] cou3=preparedStatement.executeBatch();;
20JG5A0503 170 | P a g e
|| CSE R19 JAVA PROGRAMMING
preparedStatement.setString(1, "hitha");
preparedStatement.setInt(2, 104);
preparedStatement.setInt(3, 95);
preparedStatement.addBatch();
int[] cou4=preparedStatement.executeBatch();;
connection.commit();
connection.setAutoCommit(true);
printBatchUpdateException(batchUpdateException);
} catch (SQLException e) {
printSQLException(e);
System.err.println("----BatchUpdateException----");
20JG5A0503 171 | P a g e
|| CSE R19 JAVA PROGRAMMING
Input/output:
20JG5A0503 172 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 173 | P a g e
|| CSE R19 JAVA PROGRAMMING
(Extra Program-6)
managemant
AIM:
Source code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
20JG5A0503 174 | P a g e
|| CSE R19 JAVA PROGRAMMING
Boolean autoCommit;
Statement statemnt1=conn.createStatement();
rs1 = statemnt1.executeQuery(QUERY);
displayData(rs1);
rs1 = statemnt1.executeQuery(QUERY1);
displayData(rs1);
20JG5A0503 175 | P a g e
|| CSE R19 JAVA PROGRAMMING
conn.setAutoCommit(false);
autoCommit = conn.getAutoCommit();
statemnt1 = conn.createStatement();
Connection conn1 =
DriverManager.getConnection("jdbc:mysql://localhost:3306/studentdetai
ls", "root", "");
ResultSet rs;
rs = statement2.executeQuery(QUERY);
20JG5A0503 176 | P a g e
|| CSE R19 JAVA PROGRAMMING
displayData(rs);
conn.commit();
Savepoint s1 = conn.setSavepoint();
rs = statement2.executeQuery(QUERY);
displayData(rs);
rs = statemnt1.executeQuery(QUERY);
rs1 = statemnt1.executeQuery(QUERY1);
displayData(rs1);
statemnt1.executeUpdate(update_query1);
rs1 = statemnt1.executeQuery(QUERY1);
statemnt1.executeUpdate(update_query1);
20JG5A0503 177 | P a g e
|| CSE R19 JAVA PROGRAMMING
rs1 = statemnt1.executeQuery(QUERY1);
displayData(rs1);
conn.rollback(s1);
rs1 = statemnt1.executeQuery(QUERY1);
displayData(rs1);
catch (SQLException e) {
e.printStackTrace();
while(rs1.next())
20JG5A0503 178 | P a g e
|| CSE R19 JAVA PROGRAMMING
Input/output:
20JG5A0503 179 | P a g e
|| CSE R19 JAVA PROGRAMMING
20JG5A0503 180 | P a g e