You are on page 1of 72

CSEP207 Programming Lab II (Operating Systems and DBMS)

OPE!"I#$ S%S"EM
1. CPU Scheduling Algorithms
a. First Come First Served Scheduling
b. Shortest Job First Scheduling
c. Priority Scheduling
d. Round Robin Scheduling
2. Producer Consumer Problem
3. atri! ulti"lication using ultithreading
#. $an%ers Algorithm
&. Paging
'. Segmentation
(. )ynamic Storage Allocation Problem
*. )is% Scheduling
+. File anagement
DBMS
1. Student management system using S,- commands
2. .m"loyee management using P-/S,- 0unctions
3. Creation o0 1nde! and 2rigger
#. Creation o0 2able Partition
&.3)$C and J)$C Connectivity
&
SC'ED(LI#$ !L$OI"'M
E)*no+&a ,IS"-COME. ,IS"-SE/ED SC'ED(LI#$
!im+
Allocate the "rocesses in the ready 4ueue to the CPU5 giving "re0erence to early arrival.
!0gorit1m+
6ith this scheme5 the "rocess that re4uests the CPU 0irst is allocated the CPU 0irst. 2he
im"lementation o0 the FCFS "olicy is easily managed 7ith a F1F3 4ueue. 6hen a "rocess enters the
ready 4ueue5 its "rocess control bloc% is lin%ed onto the tail o0 the 4ueue. 6hen the CPU is 0ree5 it is
allocated to the "rocess at the head o0 the 4ueue. 2he running "rocess is then removed 0rom the 4ueue.
Program+
22 programming ,C,S s31ed40ing a0gorit1m
im"ort 8ava.util.9:
"ublic class FCFS
;
"ublic static void main<String=> args?
;
Scanner in"ut @ ne7 Scanner<System.in?:
int inde! @ 1:
Array-istA2as%B tas%s @ ne7 Array-istA2as%B<?: // storage 0or the tas%s
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
7hile <in"ut.hasDe!t1nt<?? // read CPU burst times o0 tas%s
;
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
int burst @ in"ut.ne!t1nt<?:
tas%s.add<ne7 2as%<inde!5 burst??: // add a ne7 tas% to the array
inde!EE:
F
int num2as%s @ tas%s.siGe<?: // total number o0 tas%s
int 7aiting2ime @ H: // 7aiting time in a 4ueue
int time @ H: // CPU time
System.out."rint<CHC?:
7hile <I tas%s.is.m"ty<?? // ta%e the tas%s in the natural order
; // and thro7 them into the schedule
2as% t @ tas%s.remove<H?:
i0 <I tas%s.is.m"ty<??
7aiting2ime E@ 7aiting2ime E t.burst:
time E@ t.burst:
System.out."rint<C J PC E t.inde! E C J C E time?:
F
System.out."rintln<CKnAverage 7aiting timeL C E 7aiting2ime E C/C E
num2as%s E C @ C E <<1.H97aiting2ime?/num2as%s??:
F
2
F
class 2as%
;
"ublic int inde!: // tas% inde!
"ublic int burst: // tas% burst time
"ublic 2as%<int inde!5 int burst? // tas% class constructor
;
this.inde! @ inde!:
this.burst @ burst:
F
F
Samp0e Inp4t2o4tp4t+
.nter CPU burst time5 enter non integer to sto"
2
.nter CPU burst time5 enter non integer to sto"
1
.nter CPU burst time5 enter non integer to sto"
3
.nter CPU burst time5 enter non integer to sto"
a
H J P1 J 2 J P2 J 3 J P3 J '
Average 7aiting timeL &/3 @ 1.'''''''''''''''(
5
E)*no+&b S'O"ES"-6OB-,IS" SC'ED(LI#$
!im+
Allocate the "rocesses in the ready 4ueue to the CPU5 giving "re0erence to short duration o0
e!ecution.
!0gorit1m+
2his algorithm associates 7ith each "rocess the length o0 the "rocessMs ne!t CPU burst. 6hen
the CPU is available5 it is assigned to the "rocess that has the smallest ne!t CPU burst. 10 the ne!t CPU
bursts o0 t7o "rocesses are the same5 FCFS scheduling is used to brea% the tie. Dote that a more
a""ro"riate term 0or this scheduling method 7ould be the shortestJne!tJCPUJburst algorithm5 because
scheduling de"ends on the length o0 the ne!t CPU burst o0 a "rocess5 rather than its total length.
Program+
22 programming t1e S6, s31ed40ing a0gorit1m
im"ort 8ava.util.9:
"ublic class SJF
;
"ublic static void main<String=> args?
;
Scanner in"ut @ ne7 Scanner<System.in?:
int inde! @ 1:
Array-istA2as%B tas%s @ ne7 Array-istA2as%B<?: // storage 0or tas%s
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
7hile <in"ut.hasDe!t1nt<?? // read CPU burst times o0 tas%s
;
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
int burst @ in"ut.ne!t1nt<?: // create a ne7 tas%
tas%s.add<ne7 2as%<inde!5 burst??: // and add it to an array
inde!EE:
F
int num2as%s @ tas%s.siGe<?: // total number o0 tas%s
2as%=> tas%sA @ tas%s.toArray<ne7 2as%=tas%s.siGe<?>?: // convert Array-ist
Com"aratorA2as%B c @ ne7 Com"aratorA2as%B<? // into array
;
"ublic int com"are<2as% t15 2as% t2? // com"arator 0or sorting
;
return<t1.burst J t2.burst?:
F
F:
Arrays.sort<tas%sA5 c?: // sort tas%s by burst times
System.out."rintln<num2as%s E C createdC?: // "rint the schedule
int 7aiting2ime @ H:
int time @ H:
System.out."rint<CHC?:
7
0or <int i@H: iAtas%sA.length: iEE?
;
2as% t @ tas%sA=i>:
time E@ t.burst:
System.out."rint<C J PC E t.inde! E C J C E time?:
i0 <i A tas%sA.length J1?
7aiting2ime E@ time:
F
System.out."rintln<CKnAverage 7aiting timeL C E 7aiting2ime E C/C E
num2as%s E C @ C E <<1.H97aiting2ime?/num2as%s??:
F
F
class 2as%
;
"ublic int inde!: // tas% inde! <1)?
"ublic int burst: // tas% burst time
"ublic 2as%<int inde!5 int burst? // class constructor
;
this.inde! @ inde!:
this.burst @ burst:
F
F
Samp0e Inp4t2o4tp4t+
.nter CPU burst time5 enter non integer to sto"
2
.nter CPU burst time5 enter non integer to sto"
1
.nter CPU burst time5 enter non integer to sto"
3
.nter CPU burst time5 enter non integer to sto"
a
3 created
H J P2 J 1 J P1 J 3 J P3 J '
Average 7aiting timeL #/3 @ 1.3333333333333333
8
E)*no+&3 PIOI"% SC'ED(LI#$
!im+
Allocate the "rocesses in the ready 4ueue to the CPU5 giving "re0erence to high "riority.
!0gorit1m+
A "riority is associated 7ith each "rocess5 and the CPU is allocated to the "rocess 7ith the
highest "riority. .4ualJ"riority "rocesses are scheduled in FCFS order.
Program+
22 programming t1e Priority s31ed40ing a0gorit1m
im"ort 8ava.util.9:
"ublic class Priority
;
"ublic static void main<String=> args?
;
Scanner in"ut @ ne7 Scanner<System.in?:
int inde! @ 1:
int "riority:
Array-istA2as%B tas%s @ ne7 Array-istA2as%B<?: // storage 0or tas%sK
System.out."rintln<C.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"C?:
7hile <in"ut.hasDe!t1nt<?? // read CPU burst times o0 tas%s
;
int burst @ in"ut.ne!t1nt<?: // create a ne7 tas%
"riority @ in"ut.ne!t1nt<?:
System.out."rintln<C.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"C?:
tas%s.add<ne7 2as%<inde!5 burst5 "riority??: // and add it to an array
inde!EE:
F
int num2as%s @ tas%s.siGe<?: // total number o0 tas%s
2as%=> tas%sA @ tas%s.toArray<ne7 2as%=tas%s.siGe<?>?: // convert Array-ist
Com"aratorA2as%B c @ ne7 Com"aratorA2as%B<? // into array
;
"ublic int com"are<2as% t15 2as% t2? // com"arator 0or sorting
;
return<t1."riority J t2."riority?:
F
F:
Arrays.sort<tas%sA5 c?: // sort tas%s by burst times
System.out."rintln<num2as%s E C createdC?: // "rint the schedule
int 7aiting2ime @ H:
int time @ H:
System.out."rint<CHC?:
0or <int i@H: iAtas%sA.length: iEE?
;
9
2as% t @ tas%sA=i>:
time E@ t.burst:
System.out."rint<C J PC E t.inde! E C J C E time?:
i0 <i A tas%sA.length J1?
7aiting2ime E@ time:
F
System.out."rintln<CKnAverage 7aiting timeL C E 7aiting2ime E C/C E
num2as%s E C @ C E <<1.H97aiting2ime?/num2as%s??:
F
F
class 2as%
;
"ublic int inde!: // tas% inde! <1)?
"ublic int burst: // tas% burst time
"ublic int "riority:
"ublic 2as%<int inde!5 int burst5 int "riority? // class constructor
;
this.inde! @ inde!:
this.burst @ burst:
this."riority @ "riority:
F
F
Samp0e Inp4t2o4tp4t+
.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"
2
2
.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"
3
1
.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"
1
3
.nter CPU burst time5 0ollo7ed by "riority5 enter non integer to sto"
a
3 created
H J P2 J 3 J P1 J & J P3 J '
Average 7aiting timeL */3 @ 2.'''''''''''''''&
7
E)*no+&d O(#D-OBI# SC'ED(LI#$
!im+
Allocate the "rocesses in the ready 4ueue to the CPU5 e!ecuting them in intervals.
!0gorit1m+
2o im"lement RR scheduling5 7e %ee" the ready 4ueue as a F1F3 4ueue o0 "rocesses. De7
"rocesses are added to the tail o0 the ready 4ueue. 2he CPU scheduler "ic%s the 0irst "rocess 0rom the
ready 4ueue5 sets a timer to interru"t a0ter 1 time 4uantum5 and dis"atches the "rocess.
Program+
22 t1e o4nd obin s31ed40ing a0gorit1m
22 o4tp4ts s31ed40e and 3omp4tes t1e a:erage t4rnaro4nd time
22 ;irst 3ommand 0ine parameter is t1e <4anta
im"ort 8ava.util.9:
"ublic class RR
;
"ublic static void main<String=> args?
;
Scanner in"ut @ ne7 Scanner<System.in?:

int inde! @ 1:
Array-istA2as%B tas%s @ ne7 Array-istA2as%B<?: // read tas%s 0rom 0ile
System.out."rintln<C.nter 4uantaC?:
int 4uanta @ in"ut.ne!t1nt<?:
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
7hile <in"ut.hasDe!t1nt<??
;
System.out."rintln<C.nter CPU burst time5 enter non integer to sto"C?:
int burst @ in"ut.ne!t1nt<?:
tas%s.add<ne7 2as%<inde!5 burst??:
inde!EE:
F
int tas%sDo @ tas%s.siGe<?: // initial N o0 tas%s
System.out."rint<CHC?:
int timeStam" @ H:
double ave2urnaround @ H:
7hile <I tas%s.is.m"ty<?? // loo" over all tas%s
;
2as% tas% @ tas%s.remove<H?: // get the 0irst tas% 0rom the 4ueue
System.out."rint<C J PC E tas%.inde! E C J C?:
i0 <tas%.burst B 4uanta?
;
timeStam" E@ 4uanta:
tas%.burst J@ 4uanta:
tas%s.add<tas%?: // "ut this "rocess bac% to 4ueue
F
=
else
;
timeStam" E@ tas%.burst:
ave2urnaround E@ timeStam":
F
System.out."rint<timeStam"?:
F
ave2urnaround /@ tas%sDo:
System.out."rintln<CKnaverage turnaround time @ C E ave2urnaround?:
F
F
class 2as%
;
int inde!:
int burst:
"ublic 2as%<int inde!5 int burst?
;
this.inde! @ inde!:
this.burst @ burst:
F
F
Samp0e Inp4t2o4tp4t+
.nter 4uanta
1
.nter CPU burst time5 enter non integer to sto"
2
.nter CPU burst time5 enter non integer to sto"
1
.nter CPU burst time5 enter non integer to sto"
3
.nter CPU burst time5 enter non integer to sto"
a
H J P1 J 1 J P2 J 2 J P3 J 3 J P1 J # J P3 J & J P3 O '
average turnaround time @ #.H
>
E)*no+2 POD(CE-CO#S(ME POBLEM
!im+
1llustrate the conce"t o0 coo"erating "rocesses.
!0gorit1m+
3ne solution to the "roducerOconsumer "roblem uses shared memory. 2o allo7 "roducer and
consumer "rocesses to run concurrently5 7e must have available a bu00er o0 items that can be 0illed by
the "roducer and em"tied by the consumer. 2his bu00er 7ill reside in a region o0 memory that is shared
by the "roducer and consumer "rocesses. A "roducer can "roduce one item 7hile the consumer is
consuming another item. 2he "roducer and consumer must be synchroniGed5 so that the consumer
does not try to consume an item that has not yet been "roduced.
27o ty"es o0 bu00ers can be used. 2he unbounded bu00er "laces no "ractical limit on the siGe o0 the
bu00er. 2he consumer may have to 7ait 0or ne7 items5 but the "roducer can al7ays "roduce ne7
items. 2he bounded bu00er assumes a 0i!ed bu00er siGe. 1n this case5 the consumer must 7ait i0 the
bu00er is em"ty5 and the "roducer must 7ait i0 the bu00er is 0ull.
Program+
22 ! 3orre3t imp0ementation o; prod43er and a 3ons4mer.
class , ;
int n5 o @ 15 c @ H:
static int d @ H5 consumed @ 1:
boolean valueSet @ 0alse:

synchroniGed int get<? ;
i0<IvalueSet?
try ;
2hread.slee"<1?:
F catch<1nterru"ted.!ce"tion e? ;
System.out."rintln<C1nterru"ted.!ce"tion caughtC?:
F
i0<n I@ o?
;
i0<d B 1?
System.out."rintln<CConsumer slee"ingKnConsumer sle"t 0or CEdEC cyclesC?:
else i0<d @@ 1?
System.out."rintln<CConsumer slee"ingKnConsumer sle"t5 a single cycleC?:
d @ H:
System.out."rintln<CConsumer Consuming CE n ECKnConsumer Consumed CE n?:
o @ n:
System.out."rintln<CConsumer 7aitingC?:
consumed @ 1:
valueSet @ 0alse:
noti0y<?:
F
else
cEE:
return n:
F

&0
synchroniGed void "ut<int n? ;
i0<valueSet?
try ;
2hread.slee"<1?:
F catch<1nterru"ted.!ce"tion e? ;
System.out."rintln<C1nterru"ted.!ce"tion caughtC?:
F

this.n @ n:
valueSet @ true:
i0<c B 1?
System.out."rintln<CProducer slee"ingKnProducer sle"t 0or CEcEC cyclesC?:
else i0<c @@ 1?
System.out."rintln<CProducer slee"ingKnProducer sle"t5 a single cycleC?:
c @ H:
System.out."rintln<CProducer Producing CE n ECKnProducer Produced CE n?:
System.out."rintln<CProducer 7aitingC?:
noti0y<?:
F
F
class Producer im"lements Runnable ;
, 4:

Producer<, 4? ;
this.4 @ 4:
ne7 2hread<this5 CProducerC?.start<?:
F

"ublic void run<? ;
int i @ H:
7hile<true? ;
i0 <,.consumed @@ 1? ;
4."ut<iEE?:
,.consumed @ H:
F
else
,.dEE:
F
F
F
class Consumer im"lements Runnable ;
, 4:

Consumer<, 4? ;
this.4 @ 4:
ne7 2hread<this5 CConsumerC?.start<?:
&&
F

"ublic void run<? ;
7hile<true? ;
4.get<?:
F
F
F
class PCFi!ed ;
"ublic static void main<String args=>? ;
, 4 @ ne7 ,<?:
ne7 Producer<4?:
ne7 Consumer<4?:
System.out."rintln<CPress ControlJC to sto"C?:
F
F
Samp0e Inp4t2o4tp4t+
Producer Producing H
Producer Produced H
Producer 7aiting
Press ControlJC to sto"
Consumer slee"ing
Consumer sle"t 0or *#1((2 cycles
Consumer Consuming H
Consumer Consumed H
Consumer 7aiting
Producer slee"ing
Producer sle"t 0or 2H&& cycles
Producer Producing 1
Producer Produced 1
Producer 7aiting
Consumer slee"ing
Consumer sle"t 0or 322(H3+2 cycles
Consumer Consuming 1
Consumer Consumed 1
Consumer 7aiting
Producer Producing 2
Producer Produced 2
Producer 7aiting
Consumer slee"ing
Consumer sle"t 0or 2'#&33#1 cycles
Consumer Consuming 2
Consumer Consumed 2
Consumer 7aiting
&2
E)*no+5 M!"I? M(L"IPLIC!"IO# (SI#$
M(L"I"'E!DI#$
!im+
1llustrate the conce"t o0 multithreading.
!0gorit1m+
Piven t7o matrices5 A and $5 7here matri! A contains ro7s and Q columns and matri! $
contains Q ro7s and D columns5 the matri! "roduct o0 A and $ is matri! C5 7here C contains ro7s
and D columns. 2he entry in matri! C 0or ro7 i5 column 8 is the sum o0 the "roducts o0 the elements
0or ro7 i in matri! A and column 8 in matri! $.
2he "arent thread 7ill create ! D 7or%er threads5 "assing each 7or%er the values o0 ro7 i and
column 8 that it is to use in calculating the matri! "roduct. 2his re4uires "assing t7o "arameters to
each thread. 3nce all 7or%er threads have com"leted5 the main thread 7ill out"ut the "roduct
contained in matri! C. 2his re4uires the main thread to 7ait 0or all 7or%er threads to 0inish be0ore it
can out"ut the value o0 the matri! "roduct.
Program+
22 t1is is a demo ;or a m40tit1read imp0ementation ;or 3omp4ting
22 t1e matri) prod43t C @ !AB
"ublic class atri!Product
;
"ublic static void main<String=> args?
;
int=>=> A @ ;;15#F5 ;25&F5 ;35'FF: // create matrices
int=>=> $ @ ;;*5(5'F5 ;&5#53FF:
int=>=> C @ ne7 int=A.length>=$=H>.length>:
"rintatri!<A?: // "rint matrices 0or control
System.out."rintln<?:
"rintatri!<$?:
System.out."rintln<?:
2hread=> 7or%ers @ ne7 2hread=C.length 9 C=H>.length>:
int % @ H:
0or <int i@H: iAC.length: iEE? // create 7or%ing threads
0or <int 8@H: 8AC=H>.length: 8EE?
;
7or%ers=%> @ ne7 6or%er2hread<i5 85 A5 $5 C?:
7or%ers=%>.start<?:
%EE:
F
0or <%@H: %A7or%ers.length: %EE?
try
;
7or%ers=%>.8oin<?: // 7ait 0or each thread to com"lete
F
catch<1nterru"ted.!ce"tion e?
;
&5
System.out."rintln<C%@C E % E C C E e?:
F
"rintatri!<C?: // "rint the result
F
"ublic static void "rintatri!<int=>=> ? // "rints a matri!
;
0or <int i@H: iA.length: iEE?
;
0or <int 8@H: 8A=H>.length: 8EE?
System.out."rint0<CR3dC5 =i>=8>?:
System.out."rintln<?:
F
F
F
class 6or%er2hread e!tends 2hread // thread 0or com"uting one
; // matri! element C=ro7>=col>
"rivate int ro7:
"rivate int col:
"rivate int=>=> A:
"rivate int=>=> $:
"rivate int=>=> C:
"ublic 6or%er2hread<int ro75 int col5 int=>=> A5 int=>=> $5 int=>=> C?
;
this.ro7 @ ro7: // thread constructor
this.col @ col:
this.A @ A:
this.$ @ $:
this.C @ C:
F
"ublic void run<? // here 7e do all the 8ob
;
System.out."rintln<C2hread<C E ro7 E C5C E col E C? startedC?:
try
;
2hread.slee"<&?: // this call simulates longer
F // com"utations <0or demo only?
catch<1nterru"ted.!ce"tion e?;F
C=ro7>=col> @ H:
0or <int %@H: %AA=H>.length: %EE?
C=ro7>=col> E@ A=ro7>=%> 9 $=%>=col>:
System.out."rintln<C2hread<C E ro7 E C5C E col E C? sto""edC?:
F
F
&7
Samp0e Inp4t2o4tp4t+
1 #
2 &
3 '
* ( '
& # 3
2hread<H51? started
2hread<H5H? started
2hread<251? started
2hread<152? started
2hread<15H? started
2hread<H51? sto""ed
2hread<252? started
2hread<25H? started
2hread<151? started
2hread<H52? started
2hread<15H? sto""ed
2hread<152? sto""ed
2hread<151? sto""ed
2hread<251? sto""ed
2hread<H5H? sto""ed
2hread<H52? sto""ed
2hread<25H? sto""ed
2hread<252? sto""ed
2* 23 1*
#1 3# 2(
&# #& 3'
&8
E)*no+7 B!#BECS !L$OI"'M
!im+
Dever allocate available resources in such a 7ay that it could no longer satis0y the needs o0 all
its customers.
!0gorit1m+
6hen a ne7 "rocess enters the system5 it must declare the ma!imum number o0 instances o0
each resource ty"e that it may need. 2his number may not e!ceed the total number o0 resources in the
system. 6hen a user re4uests a set o0 resources5 the system must determine 7hether the allocation o0
these resources 7ill leave the system in a sa0e state. 10 it 7ill5 the resources are allocated: other7ise5
the "rocess must 7ait until some other "rocess releases enough resources.
Program+
22 demo ;or t1e BanDerEs a0gorit1m ;or dead0o3D a:oidan3e
im"ort 8ava.util.9:
"ublic class $an%ersAlgo
;
"rivate static 0inal int ASTR.S @ 1HH: // ma!imum number o0 resources
"rivate static 0inal int ASTCUS2 @ 1HH: // ma!imum number o0 customers
"rivate static int num30Customers: // actual number o0 customers
"rivate static int num30Resources: // actual number o0 resources
"rivate static int=> available @ ;H5 H5 H5 H5 H5 H5 H5 H5 H5 HF:
"rivate static int=>=> ma!imum @ ne7 int=ASTCUS2>=ASTR.S>:
"rivate static int=>=> allocation @ ne7 int=ASTCUS2>=ASTR.S>:
"rivate static int=>=> need @ ne7 int=ASTCUS2>=ASTR.S>:

"ublic static void main<String=> args?
;
// PAR2 1L reading "rocess data and initialiGation
Scanner %eyboard @ ne7 Scanner<System.in?:
String o5 demand5 demands @ CC:
int count @ H5 trigger @ 1:
0or<int i@H: iA1H: iEE? //Ca"turing total number o0 each resource
;
System.out."rint<C.nter total number o0 Resource C E i?:
System.out."rintln<C5 .nter the digit H to sto" adding resourcesC?:
available=i> @ %eyboard.ne!t1nt<?:
i0<available=i> @@ H?
i@1H:
F
System.out."rintln<C.nter ma!imum demands onlyC?:
7hile<trigger I@ H? //Ca"turing ma!imum demand o0 each "rocess
;
System.out."rintln<C.nter s"ace delimited demands o0 Process C E countEE?:
o @ %eyboard.ne!t-ine<?:
demand @ %eyboard.ne!t-ine<?:
i0<count I@ 1?
demands @ demands E CKrC E demand:
&9
else
demands @ demand:
System.out."rintln<C.nter H to sto" demanding5 .nter 1 to demand moreC?:
trigger @ %eyboard.ne!t1nt<?:
F
try // create ma!imum demands
;
Scanner customers @ ne7 Scanner<demands?:
7hile <customers.hasDe!t-ine<?? // read customers data
;
int=> re4uest @ ne7 int=ASTR.S>:
String s @ customers.ne!t-ine<?: // read each customer demands
Scanner ss @ ne7 Scanner<s?: // and to%eniGe it

0or <num30Resources@H: ss.hasDe!t1nt<?: num30ResourcesEE?
re4uest=num30Resources> @ ss.ne!t1nt<?:

re4uestResources<num30Customers5 re4uest?:// "rocess re4uest
ma!imum=num30CustomersEE> @ re4uest: // set ma!imum demand
F
customers.close<?: // no more demand to ca"ture
F
catch<.!ce"tion e?
;
System.out."rintln<e?:
F
System.out."rintln<C.ntered ma!imum demandsLC?:// "rint customers data
0or <int i@H: iAnum30Customers: iEE?
;
System.out."rint<CPTC E i E CL C?:
0or <int 8@H: 8Anum30Resources: 8EE?
System.out."rint<ma!imum=i>=8> E C C?:
System.out."rintln<?:
F

0or <int i@H: iAnum30Customers: iEE?
0or <int 8@H: 8Anum30Resources: 8EE?
;
allocation=i>=8> @ H: // initialiGe allocation
need=i>=8> @ ma!imum=i>=8>: // and need matrices
F


// PAR2 11L getting and "rocessing ne7 "rocess re4uest
Scanner in"ut @ ne7 Scanner<System.in?: // read ne7 re4uest
System.out."rintln<C.nter only one Process "er 1n"ut -ineC?:
System.out."rintln<C.nter s"ace delimited Process number U ne7 re4uestC?:
do // re4uest reading loo"
&7
;
String s @ in"ut.ne!t-ine<?:
Scanner ss @ ne7 Scanner<s?:
int customerDo @ ss.ne!t1nt<?: // re4uest author
int=> re4uest @ ne7 int=ASTR.S>:
0or <int i@H: ss.hasDe!t1nt<?: iEE?
re4uest=i> @ ss.ne!t1nt<?: // reading the re4uest

i0 <re4uestResources<customerDo5 re4uest?? // "rocess re4uest
System.out."rintln<CRe4uest is grantedC?:
else
System.out."rintln<CRe4uest is re8ectedC?:
"rintState<?: // "rint resulting state

System.out."rintln<C.nter s"ace delimited Process number U ne7 re4uestC?:
F
7hile <in"ut.hasDe!t-ine<??:
F

"ublic static boolean re4uestResources<int customerDum5 int=> re4uest?
;
0or <int 8@H: 8Anum30Resources: 8EE? // ste"s 1 and 2 o0 resource
; // re4uest algorithm
i0 <re4uest=8> B need=customerDum>=8>? return<0alse?:
i0 <re4uest=8> B available=8>? return<0alse?:
F

0or <int 8@H: 8Anum30Resources: 8EE? // ste" 3
;
allocation=customerDum>=8> E@ re4uest=8>: // "retend allocation o0
need=customerDum>=8> J@ re4uest=8>: // resources
available=8> J@ re4uest=8>:
F
i0 <isSa0e<?? // is resulting state sa0eV
return<true?: // W.S J grant the re4uest
else
;
releaseResources<customerDum5 re4uest?: // D3 J re8ect the re4uest
return<0alse?: // and restore the old state
F
F

"ublic static void releaseResources<int customerDum5 int=> re4uest?
;
0or <int 8@H: 8Anum30Resources: 8EE? // claiming the resources
; // o0 the last re4uest
allocation=customerDum>=8> J@ re4uest=8>: // bac% and restoring
need=customerDum>=8> E@ re4uest=8>: // the old state
&=
available=8> E@ re4uest=8>:
F
F

"ublic static boolean isSa0e<? // sa0ety algorithm
;
int=> se4uence @ ne7 int=num30Customers>:
int inde! @ H:
// S2.P 1
int=> 7or% @ ne7 int=num30Resources>: // initialiGation o0 63RQ
boolean=> 0inish @ ne7 boolean=num30Customers>:// initialiGation o0 F1D1SX
0or <int i@H: iAnum30Resources: iEE?
7or%=i> @ available=i>:
0or <int i @ H: iAnum30Customers: iEE?
0inish=i> @ 0alse:
// S2.P 2
boolean 0ound @ 0alse: // loo%ing 0or an a""ro"riate
do // "rocess
;
0ound @ 0alse: // "rocess 0ound 0lag
int i @ H:
0or <: iAnum30Customers: iEE?
;
i0 <<I 0inish=i>??
;
boolean good @ true: // "rocess is good i0
0or <int 8@H: 8Anum30Resources: 8EE? // conditions <a? and <b? in
i0 <need=i>=8> B 7or%=8>? // the algorithm descri"tion
; // are satis0ied
good @ 0alse:
brea%:
F
i0 <I good? continue: // try another "rocess
0ound @ true:
brea%:
F
F
// S2.P 3
i0 <0ound? // an a""ro"riate "rocess
; // is 0ound
0inish=i> @ true: // u"date the F1D1SX array
0or <int 8@H: 8Anum30Resources: 8EE? // u"date the 63RQ array
7or%=8> E@ allocation=i>=8>:
se4uence=inde!EE> @ i:
F
F 7hile <0ound?:
// S2.P #
0or <int i@H: iAnum30Customers: iEE? // chec% the F1D1SX array
&>
i0 <I 0inish=i>? return<0alse?:
System.out."rint<CProcess se4uenceL C?:
0or <int i@H: iAse4uence.length: iEE?
System.out."rint<se4uence=i> E C C?:
System.out."rintln<?:
return<true?:
F

"ublic static void "rintState<? // "rint the current state
; // matrices
System.out."rint0<CKtAllocationKtDeedKtKtAvailableKnC?:
0or <int i@H: iAnum30Customers: iEE?
;
System.out."rint0<CPTRdKtC5 i?:
0or <int 8@H: 8Anum30Resources: 8EE?
System.out."rint<allocation=i>=8> E C C?:
System.out."rint<CKtKtC?:
0or <int 8@H: 8Anum30Resources: 8EE?
System.out."rint<need=i>=8> E C C?:
System.out."rint<CKtKtC?:
i0 <i@@H?
0or <int 8@H: 8Anum30Resources: 8EE?
System.out."rint<available=8> E C C?:
System.out."rintln<?:
F
F
F
Samp0e Inp4t2o4tp4t+
.nter total number o0 Resource H5 .nter the digit H to sto" adding resources
1H
.nter total number o0 Resource 15 .nter the digit H to sto" adding resources
&
.nter total number o0 Resource 25 .nter the digit H to sto" adding resources
(
.nter total number o0 Resource 35 .nter the digit H to sto" adding resources
H
.nter ma!imum demands only
.nter s"ace delimited demands o0 Process H
( & 3
.nter H to sto" demanding5 .nter 1 to demand more
1
.nter s"ace delimited demands o0 Process 1
3 2 2
.nter H to sto" demanding5 .nter 1 to demand more
1
.nter s"ace delimited demands o0 Process 2
+ H 2
20
.nter H to sto" demanding5 .nter 1 to demand more
1
.nter s"ace delimited demands o0 Process 3
2 2 2
.nter H to sto" demanding5 .nter 1 to demand more
1
.nter s"ace delimited demands o0 Process #
# 3 3
.nter H to sto" demanding5 .nter 1 to demand more
H
.ntered ma!imum demandsL
PTHL ( & 3
PT1L 3 2 2
PT2L + H 2
PT3L 2 2 2
PT#L # 3 3
.nter only one Process "er 1n"ut -ine
.nter s"ace delimited Process number U ne7 re4uest
H H 1 H
Process se4uenceL H 1 2 3 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 1H # (
PT1 H H H 3 2 2
PT2 H H H + H 2
PT3 H H H 2 2 2
PT# H H H # 3 3
.nter s"ace delimited Process number U ne7 re4uest
1 2 H H
Process se4uenceL H 1 2 3 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 * # (
PT1 2 H H 1 2 2
PT2 H H H + H 2
PT3 H H H 2 2 2
PT# H H H # 3 3
.nter s"ace delimited Process number U ne7 re4uest
2 3 H 2
Process se4uenceL 1 H 2 3 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 & # &
PT1 2 H H 1 2 2
PT2 3 H 2 ' H H
PT3 H H H 2 2 2
PT# H H H # 3 3
.nter s"ace delimited Process number U ne7 re4uest
2&
3 2 1 1
Process se4uenceL 1 3 H 2 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 3 3 #
PT1 2 H H 1 2 2
PT2 3 H 2 ' H H
PT3 2 1 1 H 1 1
PT# H H H # 3 3
.nter s"ace delimited Process number U ne7 re4uest
# H H 2
Process se4uenceL 1 3 H 2 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 3 3 2
PT1 2 H H 1 2 2
PT2 3 H 2 ' H H
PT3 2 1 1 H 1 1
PT# H H 2 # 3 1
.nter s"ace delimited Process number U ne7 re4uest
1 1 H 2
Process se4uenceL 1 3 H 2 #
Re4uest is granted
Allocation Deed Available
PTH H 1 H ( # 3 2 3 H
PT1 3 H 2 H 2 H
PT2 3 H 2 ' H H
PT3 2 1 1 H 1 1
PT# H H 2 # 3 1
.nter s"ace delimited Process number U ne7 re4uest
# 3 3 H
Re4uest is re8ected
Allocation Deed Available
PTH H 1 H ( # 3 2 3 H
PT1 3 H 2 H 2 H
PT2 3 H 2 ' H H
PT3 2 1 1 H 1 1
PT# H H 2 # 3 1
.nter s"ace delimited Process number U ne7 re4uest
H H 2 H
Re4uest is re8ected
Allocation Deed Available
PTH H 1 H ( # 3 2 3 H
PT1 3 H 2 H 2 H
PT2 3 H 2 ' H H
PT3 2 1 1 H 1 1
PT# H H 2 # 3 1
.nter s"ace delimited Process number U ne7 re4uest
22
E)*no+8 P!$I#$
!im+
Solve the considerable "roblem o0 0itting memory chun%s o0 varying siGes
onto the bac%ing store.
!0gorit1m+
2he basic method 0or im"lementing "aging involves brea%ing "hysical memory into 0i!edJ
siGed bloc%s called 0rames and brea%ing logical memory into bloc%s o0 the same siGe called "ages.
6hen a "rocess is to be e!ecuted5 its "ages are loaded into any available memory 0rames 0rom their
source.
Program+
im"ort 8ava.io.9:
class Paging
;
"ublic static void main<String args=>? thro7s 13.!ce"tion
;
int ch5i585count@H50lag@H:
int l5"r5":
int totalT"age5logicalTadd5"rocessTsiGe@H5"ageTsiGe@H5t:
int "Tnum50Tnum5o0set5"hTmem5lTadd:
int 0rameTnum=>@ne7 int=3H>:
String "age=>=>@ne7 String=3H>=3H>:

7hile<true?
;
0lag@H:
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<CPagingKn1L StoreKn2L RetrievalKn3L .!itC?:
System.out."rint<CKn.nter your choiceL C?:
ch@1nteger."arse1nt<br.read-ine<??:

i0<ch@@1?
;
do
;
System.out."rint<CKnKn.nter the -ogical address <in Po7er o0 2?L C?:
logicalTadd@1nteger."arse1nt<br.read-ine<??:
System.out."rint<CKn.nter the Process siGe <A -ogical address?L C?:
"rocessTsiGe@1nteger."arse1nt<br.read-ine<??:
System.out."rint<CKn.nter the Page siGe <in Po7er o0 2?L C?:
"ageTsiGe@1nteger."arse1nt<br.read-ine<??:

l@logicalTadd: "r@"rocessTsiGe: "@"ageTsiGe:
F7hile<<<JlUl?I@l?YY<<J"U"?I@"?YY<"rBl??:

totalT"age@"rocessTsiGe/"ageTsiGe:
i0<"rocessTsiGeR"ageTsiGeI@H? totalT"ageEE:
0or<i@H:iAtotalT"age:iEE?
25
;
System.out."rintln<CKn.nter the Content o0 Page CEiECL C?:
0or<8@H:8A"ageTsiGe:8EE?
;
System.out."rint<CKn.nter the Content CE8ECL C?:
"age=i>=8>@br.read-ine<?:
countEE:
i0<count@@"rocessTsiGe? brea%:
F
F
0or<i@H:iAtotalT"age:iEE?
;
System.out."rint<CKn.nter the Frame Dumber o0 Page number CEiECL C?:
0rameTnum=i>@1nteger."arse1nt<br.read-ine<??:
F
System.out."rintln<CKnPhysical emoryC?:
count@H:
0or<i@H:iAtotalT"age:iEE?
;
System.out."rintln<CKnContents o0 Page CEiECL C?:
0or<8@H:8A"ageTsiGe:8EE?
;
t@8E"ageTsiGe90rameTnum=i>:
System.out."rintln<CKnContent CEtECL CE"age=i>=8>?:
countEE:
i0<count@@"rocessTsiGe? brea%:
F
F
i0<"rocessTsiGeR"ageTsiGeI@H?
System.out."rintln<CKn2he Page has 1nternal 0ragmentationKnC?:
F
else i0<ch@@2?
;
System.out."rint<CKn.nter the -ogical address to RetrieveL C?:
lTadd@1nteger."arse1nt<br.read-ine<??:
i0<lTaddB@"rocessTsiGeYYlTaddAH?
;
System.out."rintln<CKn1nvalid -ogical addressC?:
0lag@1:
F
i0<0lag@@H?
;
"Tnum@lTadd/"ageTsiGe:
0Tnum@0rameTnum="Tnum>:
o0set@lTaddR"ageTsiGe:
"hTmem@o0setE0Tnum9"ageTsiGe:

System.out."rintln<CKnPage numberL CE"Tnum?:
27
System.out."rintln<CKn300set valueL CEo0set?:
System.out."rintln<CKnContentL CE"age="Tnum>=o0set>?:
System.out."rintln<CKnPhysical memoryL CE"hTmemECKnC?:
F
F
else i0 <ch@@3? brea%:
F
F
F
Samp0e Inp4t2o4tp4t+
Paging
1L Store
2L Retrieval
3L .!it
.nter your choiceL 1
.nter the -ogical address <in Po7er o0 2?L 1'
.nter the Process siGe <A -ogical address?L 1H
.nter the Page siGe <in Po7er o0 2?L #
.nter the Content o0 Page HL
.nter the Content HL a
.nter the Content 1L b
.nter the Content 2L c
.nter the Content 3L d
.nter the Content o0 Page 1L
.nter the Content HL e
.nter the Content 1L 0
.nter the Content 2L g
.nter the Content 3L h
.nter the Content o0 Page 2L
.nter the Content HL i
.nter the Content 1L 8
.nter the Frame Dumber o0 Page number HL #
.nter the Frame Dumber o0 Page number 1L *
.nter the Frame Dumber o0 Page number 2L 12
Physical emory
Contents o0 Page HL
Content 1'L a
Content 1(L b
Content 1*L c
Content 1+L d
Contents o0 Page 1L
28
Content 32L e
Content 33L 0
Content 3#L g
Content 3&L h
Contents o0 Page 2L
Content #*L i
Content #+L 8
2he Page has 1nternal 0ragmentation
Paging
1L Store
2L Retrieval
3L .!it
.nter your choiceL 2
.nter the -ogical address to RetrieveL '
Page numberL 1
300set valueL 2
ContentL g
Physical memoryL 3#
Paging
1L Store
2L Retrieval
3L .!it
.nter your choiceL 3
29
E)*no+9 SE$ME#"!"IO#
!im+
Su""ort user vie7 o0 memory.
!0gorit1m+
A logical address s"ace is a collection o0 segments. .ach segment has a name and a length.
2he addresses s"eci0y both the segment name and the o00set 7ithin the segment.
Program+
im"ort 8ava.io.9:
"ublic class Segmentation
;
"ublic static void main<String=> args? thro7s 13.!ce"tion
;
int ch5i50lag@H:
int segTno@H5segTnoTret5segTdis:
int segTbase=>@ne7 int=3H>:
int segTlimit=>@ne7 int=&H>:
String segTname=>@ne7 String=&H>:

7hile<true?
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<CSegmentationC?:
System.out."rintln<C1L StoreKn2L RetrievalKn3L .!itC?:
System.out."rint<CKn.nter your choiceL C?:
ch@1nteger."arse1nt<br.read-ine<??:
i0<ch@@1?
;
System.out."rint<CKn.nter the Dumber o0 SegmentsL C?:
segTno@1nteger."arse1nt<br.read-ine<??:
0or<i@1:iA@segTno:iEE?
;
System.out."rint<CKn.nter the Dame o0 a SegmentL C?:
segTname=i>@br.read-ine<?:
System.out."rint<CKn.nter the Segment limitL C?:
segTlimit=i>@1nteger."arse1nt<br.read-ine<??:
int u@H5t:
7hile<u@@H?
;
System.out."rint<CKn.nter the Segment baseL C?:
segTbase=i>@1nteger."arse1nt<br.read-ine<??:
i0<iB1?
;
t@segTbase=iJ1>EsegTlimit=iJ1>J1:
i0<tAsegTbase=i>? u@1:
else System.out."rintln<C1nvalid in"utC?:
27
F
else u@1:
F
F
0or<i@1:iA@segTno:iEE?
;
System.out."rint<CKnKnSegment numberL CEi?:
System.out."rint<CKnSegment nameL CEsegTname=i>?:
System.out."rint<CKnSegment starting addressL CEsegTbase=i>?:
System.out."rintln<CKnend addressLCE<segTlimit=i>EsegTbase=i>?ECKnC?:
F
F
else i0<ch@@2?
;
7hile<true?
;
0lag@H:
System.out."rint<CKn.nter needed segment number=1.....CEsegTnoEC>L C?:
segTnoTret@1nteger."arse1nt<br.read-ine<??:
System.out."rint<CKn.nter the dis"lacement valueL C?:
segTdis@1nteger."arse1nt<br.read-ine<??:
i0 <segTdisBsegTlimit=segTnoTret>?
;
System.out."rintln<CKn1nvalid in"utC?:
0lag@1:
F
i0<0lag@@H?
;
System.out."rint<CKnSegment numberL CEsegTnoTret?:
System.out."rint<CKnSegment nameL CEsegTname=segTnoTret>?:
System.out."rint<CKnSegment retrieval addressL C?:
System.out."rintln<segTbase=segTnoTret>EsegTdisECKnC?:

brea%:
F
F
F
else i0<ch@@3? brea%:
F
F
F
Samp0e Inp4t2o4tp4t+
Segmentation
1L Store
2L Retrieval
3L .!it
2=
.nter your choiceL 1
.nter the Dumber o0 SegmentsL 3
.nter the Dame o0 a SegmentL Print
.nter the Segment limitL 1HHH
.nter the Segment baseL 1&HH
.nter the Dame o0 a SegmentL s4rt
.nter the Segment limitL #HH
.nter the Segment baseL 2(HH
.nter the Dame o0 a SegmentL main
.nter the Segment limitL 11HH
.nter the Segment baseL 3(HH
Segment numberL 1
Segment nameL Print
Segment starting addressL 1&HH
Segment end addressL2&HH
Segment numberL 2
Segment nameL s4rt
Segment starting addressL 2(HH
Segment end addressL31HH
Segment numberL 3
Segment nameL main
Segment starting addressL 3(HH
Segment end addressL#*HH
Segmentation
1L Store
2L Retrieval
3L .!it
.nter your choiceL 2
.nter needed segment number=1.....3>L 1
.nter the dis"lacement valueL 2HH
Segment numberL 1
Segment nameL Print
Segment retrieval addressL 1(HH
Segmentation
1L Store
2L Retrieval
3L .!it
.nter your choiceL 3
2>
E)*no+7 D%#!MIC S"O!$E-!LLOC!"IO# POBLEM
!im+
Satis0y a re4uest o0 a given siGe 0rom a list o0 0ree holes.
!0gorit1m+
2he ;irst-;it5 best-;it5 and Forst-;it strategies are the ones most commonly used to select a
0ree hole 0rom the set o0 available holes.
,irst ;it. Allocate the 0irst hole that is big enough. Searching can start either at the beginning o0 the set
o0 holes or at the location 7here the "revious 0irstJ0it search ended. 6e can sto" searching as soon as
7e 0ind a 0ree hole that is large enough.
Best ;it. Allocate the smallest hole that is big enough. 6e must search the entire list5 unless the list is
ordered by siGe. 2his strategy "roduces the smallest le0tover hole.
Gorst ;it. Allocate the largest hole. Again5 7e must search the entire list5 unless it is sorted by siGe.
2his strategy "roduces the largest le0tover hole5 7hich may be more use0ul than the smaller le0tover
hole 0rom a bestJ0it a""roach.
Program+
im"ort 8ava.io.9:
"ublic class Fitting
;
$u00eredReader in"ut@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
int "rocess=>5 r"rocess=>5 bloc%=>5 rbloc%=>5 usage=>5 rusage=>:
int "5 b5 0ree5 used5 r0ree5 rused5 c5 c1:
"ublic Fitting<? thro7s 13.!ce"tion
;
System.out."rintln<C.nter number o0 bloc%sC?:
b@1nteger."arse1nt<in"ut.read-ine<??:
System.out."rintln<C.nter number o0 "rocessesC?:
"@1nteger."arse1nt<in"ut.read-ine<??:
"rocess@ne7 int=">:r"rocess@ne7 int=">:
bloc%@ne7 int=b>:
rbloc%@ne7 int=b>:
usage@ne7 int=b>:rusage@ne7 int=b>:
c@H:// 23)3 AutoJgenerated constructor stub
F
void read<? thro7s 13.!ce"tion
;
int i:
System.out."rintln<C.nter bloc% siGesC?:
0or<i@H:iAb:iEE?
;
System.out."rint<C$loc% CE<iE1?EC L C?:
rbloc%=i>@1nteger."arse1nt<in"ut.read-ine<??:
F
System.out."rintln<C.nter bloc% usage scenarioC?:
0or<i@H:iAb:iEE?
;
System.out."rintln<C1s bloc% CE<iE1?EC used <1? or 0ree <H?VC?:
rusage=i>@1nteger."arse1nt<in"ut.read-ine<??:
50
i0<rusage=i>@@1?
;
rused@rusedErbloc%=i>:
c1EE:
F
else r0ree@r0reeErbloc%=i>:
F
System.out."rintln<C.nter "rocess demandC?:
0or<i@H:iA":iEE?
;
System.out."rint<CProcess CE<iE1?EC L C?:
r"rocess=i>@1nteger."arse1nt<in"ut.read-ine<??:
F
F
void reset<?
;
int i:
0or<i@H:iAb:iEE?
;
bloc%=i>@rbloc%=i>:
usage=i>@rusage=i>:
F
0or<i@H:iA":iEE?
"rocess=i>@r"rocess=i>:
used@rused:
0ree@r0ree:
c@c1:
F
void dis"lay<?
;
int total:
total@rusedEr0ree:
System.out."rintln<C$loc%s used @ CEc?:
System.out."rintln<C2otal used s"ace @ CEused?:
System.out."rintln<C$loc%s 0ree @ CE<bJc??:
System.out."rintln<C2otal 0ree s"ace @ CE<totalJused??:
F
void 0T0it<?
;
int i58:
0or<i@H:iA":iEE? //Processes.
0or<8@H:8Ab:8EE? //$loc%s.
;
i0<"rocess=i>A@bloc%=8>UUusage=8>@@H?
;
usage=8>@1:
used@usedEbloc%=8>:
cEE:
5&
System.out."rintln<CProcess CE<iE1?EC is in bloc% CE<8E1??:
brea%:
F
F
F
void bT0it<?
;
int i585siGe5best:
0or<i@H:iA":iEE?
;
siGe@32+'(:
best@J1:
0or<8@H:8Ab:8EE?
;
i0<"rocess=i>A@bloc%=8>UUusage=8>@@HUU<bloc%=8>J"rocess=i>?AsiGe?
;
siGe@bloc%=8>J"rocess=i>:
best@8:
F
F
i0<siGeA32+'(UUbestI@J1? //.nsuring a best 0it.
;
usage=best>@1:
used@usedEbloc%=best>:
cEE:
System.out."rintln<CProcess CE<iE1?EC is in bloc% CE<bestE1??:
F
F
F
void 7T0it<?
;
int i585siGe57orst:
0or<i@H:iA":iEE?
;
siGe@H:
7orst@J1:
0or<8@H:8Ab:8EE?
;
i0<"rocess=i>A@bloc%=8>UUusage=8>@@HUU<bloc%=8>J"rocess=i>?BsiGe?
;
siGe@bloc%=8>J"rocess=i>:
7orst@8:
F
F
i0<7orstI@J1? //.nsuring a 7orst 0it.
;
usage=7orst>@1:
used@usedEbloc%=7orst>:
52
cEE:
System.out."rintln<CProcess CE<iE1?EC is in bloc% CE<7orstE1??:
F
F
F
/999 Z"aram args9/
"ublic static void main<String=> args? thro7s 13.!ce"tion
;
$u00eredReader in"ut@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
int o"tion:
String choice:
Fitting 0@ne7 Fitting<?:
0.read<?:
do;
0.reset<?:
System.out."rintln<CenuC?:
System.out."rintln<C1. First 0itC?:
System.out."rintln<C2. $est 0itC?:
System.out."rintln<C3. 6orst 0itC?:
System.out."rintln<C#. $loc% in0ormationC?:
System.out."rintln<C.nter o"tionC?:
o"tion@1nteger."arse1nt<in"ut.read-ine<??:
s7itch<o"tion?
;
case 1L 0.0T0it<?:
brea%:
case 2L 0.bT0it<?:
brea%:
case 3L 0.7T0it<?:
brea%:
case #L 0.dis"lay<?:
brea%:
de0aultL System.out."rintln<C1nvalid in"utC?:
F
0.dis"lay<?:
System.out."rintln<CPress W to continueC?:
choice@in"ut.read-ine<?:
F
7hile<choice.com"are2o1gnoreCase<CyC?@@H?://23)3 AutoJgenerated method stub
F
F
55
Samp0e Inp4t2o4tp4t+
.nter number o0 bloc%s
'
.nter number o0 "rocesses
1
.nter bloc% siGes
$loc% 1 L 3
$loc% 2 L &
$loc% 3 L 2
$loc% # L (
$loc% & L '
$loc% ' L 1
.nter bloc% usage scenario
1s bloc% 1 used <1? or 0ree <H?V
H
1s bloc% 2 used <1? or 0ree <H?V
H
1s bloc% 3 used <1? or 0ree <H?V
H
1s bloc% # used <1? or 0ree <H?V
H
1s bloc% & used <1? or 0ree <H?V
H
1s bloc% ' used <1? or 0ree <H?V
H
.nter "rocess demand
Process 1 L 2
enu
1. First 0it
2. $est 0it
3. 6orst 0it
#. $loc% in0ormation
.nter o"tion
#
$loc%s used @ H
2otal used s"ace @ H
$loc%s 0ree @ '
2otal 0ree s"ace @ 2#
$loc%s used @ H
2otal used s"ace @ H
$loc%s 0ree @ '
2otal 0ree s"ace @ 2#
Press W to continue
y
enu
1. First 0it
2. $est 0it
3. 6orst 0it
57
#. $loc% in0ormation
.nter o"tion
1
Process 1 is in bloc% 1
$loc%s used @ 1
2otal used s"ace @ 3
$loc%s 0ree @ &
2otal 0ree s"ace @ 21
Press W to continue
y
enu
1. First 0it
2. $est 0it
3. 6orst 0it
#. $loc% in0ormation
.nter o"tion
2
Process 1 is in bloc% 3
$loc%s used @ 1
2otal used s"ace @ 2
$loc%s 0ree @ &
2otal 0ree s"ace @ 22
Press W to continue
y
enu
1. First 0it
2. $est 0it
3. 6orst 0it
#. $loc% in0ormation
.nter o"tion
3
Process 1 is in bloc% #
$loc%s used @ 1
2otal used s"ace @ (
$loc%s 0ree @ &
2otal 0ree s"ace @ 1(
Press W to continue
58
E)*no+= DISB SC'ED(LI#$
!im+
Xave 0ast access time and large dis% band7idth.
!0gorit1m+
2he sim"lest 0orm o0 dis% scheduling is5 o0 course5 the 0irstJcome5 0irstJserved <FCFS? algorithm. 2his
algorithm is intrinsically 0air5 but it generally does not "rovide the 0astest service. 2he SS2F algorithm
selects the re4uest 7ith the least see% time 0rom the current head "osition. Since see% time increases
7ith the number o0 cylinders traversed by the head5 SS2F chooses the "ending re4uest closest to the
current head "osition. 1n the SCAD algorithm5 the dis% arm starts at one end o0 the dis% and moves
to7ard the other end5 servicing re4uests as it reaches each cylinder5 until it gets to the other end o0 the
dis%. At the other end5 the direction o0 head movement is reversed5 and servicing continues. 2he head
continuously scans bac% and 0orth across the dis%. -i%e SCAD5 CJSCAD moves the head 0rom one
end o0 the dis% to the other5 servicing re4uests along the 7ay. 6hen the head reaches the other end5
ho7ever5 it immediately returns to the beginning o0 the dis% 7ithout servicing any re4uests on the
return tri". 2he CJSCAD scheduling algorithm essentially treats the cylinders as a circular list that
7ra"s around 0rom the 0inal cylinder to the 0irst one. As 7e described them5 both SCAD and CJSCAD
move the dis% arm across the 0ull 7idth o0 the dis%. 1n "ractice5 neither algorithm is o0ten im"lemented
this 7ay. ore commonly5 the arm goes only as 0ar as the 0inal re4uest in each direction. 2hen5 it
reverses direction immediately5 7ithout going all the 7ay to the end o0 the dis%. [ersions o0 SCAD
and CJSCAD that 0ollo7 this "attern are called -33Q and CJ-33Q scheduling5 because they loo%
0or a re4uest be0ore continuing to move in a given direction.
Program+
im"ort 8ava.io.9:
class )is%mgmt
;
int i585head5t5c:
int b=>@ne7 int=3H>:
int s=>@ne7 int=3H>:
int tem"=>@ne7 int=3H>:

"ublic static void main<String arg=>? thro7s 13.!ce"tion
;
int ch5head5n5i5start5end:
int a=>@ne7 int=3H>:
)is%mgmt ds@ne7 )is%mgmt<?:
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
do
;
System.out."rint<CKn.nter the Starting bloc% numberL C?:
start@1nteger."arse1nt<br.read-ine<??:
System.out."rint<CKn.nter the .nding bloc% numberL C?:
end@1nteger."arse1nt<br.read-ine<??:
System.out."rint<CKn.nter the Starting head "ositionL C?:
head@1nteger."arse1nt<br.read-ine<??:
F7hile<<head B@ end? YY <head A start??:
a=H>@head:
System.out."rint<CKn.nter the 2otal number o0 re4uestL C?:
59
n@1nteger."arse1nt<br.read-ine<??:
0or<i@1:iA@n:iEE?
;
System.out."rint<CKn.nter Re4uest CEiECL C?:
a=i>@1nteger."arse1nt<br.read-ine<??:
i0<<a=i>Bend? YY <a=i>Astart??
;
System.out."rintln<C1nvalid number.....nter AgainC?:
iJJ:
F
F
System.out."rint<CKn)is% 4ueue isLC?:
0or<i@H:iA@n:iEE?
System.out."rint<C C E a=i>?:
do
;
System.out."rintln<CKn)1SQ SCX.)U-1DP 2.CXD1,U.KnJJJJJJJJJJJJJJJJJJJJC?:
System.out."rintln<C1.FCFSKn2.SS2FKn3.SCADC?:
System.out."rintln<C#.CJSCADKn&.-33QKn'.CJ-33QKn(..S12C?:
System.out."rint<C.nter your choiceL C?:
ch@1nteger."arse1nt<br.read-ine<??:
s7itch<ch?
;
case 1L ds.FCFS<n5a?: brea%:
case 2L ds.SS2F<n5a?: brea%:
case 3L ds.SCAD<n5a5start5end?: brea%:
case #L ds.CSCAD<n5a5start5end?: brea%:
case &L ds.-33Q<n5a?: brea%:
case 'L ds.C-33Q<n5a?: brea%:
case (L brea%:
de0aultL System.out."rintln<C1nvalid choiceC?:
F
F7hile<ch I@ (?:
F
void FCFS<int n5int a=>?
;
int sum@H:
System.out."rintln<CKnKt FCFSC?:
System.out."rintln<CAccess order Dumber o0 head movementsC?:
0or<i@H:iA@n:iEE?
;
System.out."rint<a=i>?:
i0<i I@ n?
;
b=i>@ath.abs<a=i>Ja=iE1>?:
System.out."rintln<CKtKtCEb=i>?:
sum E@ b=i>:
F
57
F
System.out."rintln<CKn2otal number o0 head movementsL C Esum?:
F
void SS2F<int n5int a=>?
;
int n15min@H5G:
int ss=>@ne7 int=3H>:
0or<i@H:iA@n:iEE? ss=i>@a=i>:
n1@n:
b=H>@ss=H>:
head@ss=H>:
c@H:
7hile<n1 B H?
;
8@1:
min@ath.abs<ss=H>Jss=1>?:
0or<i@2:iA@n1:iEE?
i0<ath.abs<headJss=i>? A@ min?
;
min@ath.abs<headJss=i>?:
8@i:
F
cEE:
b=c>@ss=8>: head@ss=8>: ss=H>@ss=8>:
JJn1:
0or<G@8:GA@n1:GEE? ss=G>@ss=GE1>:
F
System.out."rintln<CKnKt SS2FC?:
dis"lay<?:
F
void SCAD<int n5int a=>5int start5int end?
;
init<n5a?:
c@H:
0or<i@H:iA@n:iEE?
;
i0<tem"=i>@@head?
;
b=c>@head:
0or<8@iE1:8A@n:8EE? b=EEc>@tem"=8>:
b=EEc>@end:
0or<8@iJ1:8B@H:8JJ? b=EEc>@tem"=8>:
b=EEc>@start:
F
F
System.out."rintln<CKnKt SCADC?:
sTdis"lay<n?:
F
5=
void CSCAD<int n5int a=>5int start5int end?
;
init<n5a?:
c@H:
0or<i@H:iA@n:iEE?
;
i0<tem"=i>@@head?
;
b=c>@head:
0or<8@iE1:8A@n:8EE? b=EEc>@tem"=8>:
b=EEc>@end:
b=EEc>@start:
0or<8@H:8A@iJ1:8EE? b=EEc>@tem"=8>:
F
F
System.out."rintln<CKnKt CJSCADC?:
sTdis"lay<n?:
F
void -33Q<int n5int a=>?
;
init<n5a?:
c@H:
0or<i@H:iA@n:iEE?
;
i0<tem"=i>@@head?
;
b=c>@head:
0or<8@iE1:8A@n:8EE? b=EEc>@tem"=8>:
0or<8@iJ1:8B@H:8JJ? b=EEc>@tem"=8>:
F
F
System.out."rintln<CKnKt -33QC?:
dis"lay<?:
F
void C-33Q<int n5int a=>?
;
init<n5a?:
c@H:
0or<i@H:iA@n:iEE?
;
i0<tem"=i>@@head?
;
b=c>@head:
0or<8@iE1:8A@n:8EE? b=EEc>@tem"=8>:
0or<8@H:8A@iJ1:8EE? b=EEc>@tem"=8>:
F
F
System.out."rintln<CKnKt CJ-33QC?:
5>
dis"lay<?:
F
void init<int n5int a=>?
;
0or<i@H:iA@n:iEE? tem"=i>@a=i>:
head@a=H>:
0or<i@H:iA@n:iEE?
0or<8@iE1:8A@n:8EE?
i0<tem"=i> B tem"=8>?
;
t@tem"=i>:
tem"=i>@tem"=8>:
tem"=8>@t:
F
F
void dis"lay<?
;
int sum@H:
System.out."rintln<CAccess order Dumber o0 head movementsC?:
0or<i@H:iA@c:iEE?
;
System.out."rint<b=i>?:
i0<i I@ c?
;
s=i>@ath.abs<b=i>Jb=iE1>?:
System.out."rintln<CKtKtC Es=i>?:
sum E@ s=i>:
F
F
System.out."rintln<CKn2otal number o0 head movementsL C Esum?:
F
void sTdis"lay<int n?
;
int sum@H:
System.out."rintln<CAccess order Dumber o0 head movementsC?:
0or<i@H:iA@nE2:iEE?
;
System.out."rint<b=i>?:
i0<i I@ c?
;
s=i>@ath.abs<b=i>Jb=iE1>?:
System.out."rintln<CKtKtC Es=i>?:
sum E@ s=i>:
F
F
System.out."rintln<CKn2otal number o0 head movementsL C Esum?:
F
F
70
Samp0e Inp4t2o4tp4t
.nter the Starting bloc% numberL H
.nter the .nding bloc% numberL 1HH
.nter the Starting head "ositionL 'H
.nter the 2otal number o0 re4uestL 1H
.nter Re4uest 1L &&
.nter Re4uest 2L (H
.nter Re4uest 3L 3H
.nter Re4uest #L 1H
.nter Re4uest &L #&
.nter Re4uest 'L +#
.nter Re4uest (L ((
.nter Re4uest *L 2H
.nter Re4uest +L &&
.nter Re4uest 1HL *+
)is% 4ueue isL 'H && (H 3H 1H #& +# (( 2H && *+
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL 1
FCFS
Access order Dumber o0 head movements
'H &
&& 1&
(H #H
3H 2H
7&
1H 3&
#& #+
+# 1(
(( &(
2H 3&
&& 3#
*+
2otal number o0 head movementsL 3H(
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL 2
SS2F
Access order Dumber o0 head movements
'H &
&& H
&& 1H
#& 1&
3H 1H
2H 1H
1H 'H
(H (
(( 12
*+ &
+#
2otal number o0 head movementsL 13#
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL 3
SCAD
Access order Dumber o0 head movements
72
'H 1H
(H (
(( 12
*+ &
+# '
1HH #&
&& H
&& 1H
#& 1&
3H 1H
2H 1H
1H 1H
H
2otal number o0 head movementsL 1#H
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL #
CJSCAD
Access order Dumber o0 head movements
'H 1H
(H (
(( 12
*+ &
+# '
1HH 1HH
H 1H
1H 1H
2H 1H
3H 1&
#& 1H
&& H
&&
2otal number o0 head movementsL 1+&
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
75
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL &
-33Q
Access order Dumber o0 head movements
'H 1H
(H (
(( 12
*+ &
+# 3+
&& H
&& 1H
#& 1&
3H 1H
2H 1H
1H
2otal number o0 head movementsL 11*
)1SQ SCX.)U-1DP 2.CXD1,U.
JJJJJJJJJJJJJJJJJJJJJJJJJ
1.FCFS
2.SS2F
3.SCAD
#.CJSCAD
&.-33Q
'.CJ-33Q
(..S12
.nter your choiceL '
CJ-33Q
Access order Dumber o0 head movements
'H 1H
(H (
(( 12
*+ &
+# *#
1H 1H
2H 1H
3H 1&
#& 1H
&& H
&&
2otal number o0 head movementsL 1'3
77
E)*no+> ,ILE M!#!$EME#"
!im+
1denti0y several common system calls dealing 7ith 0iles.
!0gorit1m+
6e 0irst need to be able to create and delete 0iles. .ither system call re4uires the name o0 the 0ile and
"erha"s some o0 the 0ileMs attributes. 3nce the 0ile is created5 7e need to o"en it and to use it. 6e may
also read5 7rite5 or re"osition <re7inding or s%i""ing to the end o0 the 0ile5 0or e!am"le?. Finally5 7e
need to close the 0ile5 indicating that 7e are no longer using it.
Program+
im"ort 8ava.io.9:
class Filemgmt
;
"ublic static void main<String arg=>? thro7s 13.!ce"tion
;
int o"t:
Filemgmt 0m@ne7 Filemgmt<?:
try
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
do
;
System.out."rintln<CF1-. ADAP..D2 SWS2.C?:
System.out."rintln<C1. De7 FileKn2. )is"lay FileKn3. Rename FileC?:
System.out."rintln<C#. Search FileKn&. )elete FileKn'. .!itC?:
System.out."rintln<C.nter your choiceL C?:
o"t@1nteger."arse1nt<br.read-ine<??:
s7itch<o"t?
;
case 1L 0m.create<?: brea%:
case 2L 0m.dis"lay<?: brea%:
case 3L 0m.ren<?: brea%:
case #L 0m.search<?: brea%:
case &L 0m.del<?: brea%:
case 'L System.e!it<H?:
F
F7hile<o"t I@ '?:
F
catch<.!ce"tion e? ;F
F

void create<?
;
int ch:
System.out."rintln<CF1-. CR.A213DC?:
try
;
78
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<C.nter the File DameL C?:
String str@br.read-ine<?:
File 0ile@ne7 File<str?:
0ile.createDe7File<?:
$u00ered6riter b7@null:
System.out."rintln<C.nter the 2e!t <CtrlEG to end?L C?:
b7@ne7 $u00ered6riter<ne7 File6riter<str??:
7hile<<ch@System.in.read<?? I@ J1?
;
b7.7rite<ch?:
F
b7.0lush<?:
b7.close<?:
F
catch<.!ce"tion e ? ;F
F

void dis"lay<?
;
int ch:
System.out."rintln<C)1SP-AW1DP F1-. C3D2.D2C?:
try
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<C.nter the File Dame to dis"layL C?:
String str@br.read-ine<?:
FileReader 0@ne7 FileReader<str?:
7hile<<ch@0.read<?? I@ J1?
;
System.out."rint<<char?ch?:
F
0.close<?:
F
catch<FileDotFound.!ce"tion 0n? ;F
catch<13.!ce"tion e? ;F
F

void ren<?
;
System.out."rintln<CR.DA1DP 2X. F1-.C?:
try
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<CR.DA1DP F1-.C?:
System.out."rintln<C.nter the .!isting File DameL C?:
String e!@br.read-ine<?:
System.out."rintln<C.nter the De7 File DameL C?:
79
String rename@br.read-ine<?:
File 0@ne7 File<e!?:
File 01@ne7 File<rename?:
0.rename2o<01?:
System.out."rintln<CFile CEe!E C is renamed as C E01?:
F
catch<.!ce"tion e? ;F
F

void del<?
;
System.out."rintln<C).-.21DP 2X. F1-.C?:
try
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<C.nter the File to )eleteL C?:
String d@br.read-ine<?:
File 0@ne7 File<d?:
System.out."rintln<C)eleting the File CE0?:
0.delete<?:

F
catch<.!ce"tion e? ;F
F

void search<?
;
System.out."rintln<CS.ARCX1DP A F1-.C?:
try
;
$u00eredReader br@ne7 $u00eredReader<ne7 1n"utStreamReader<System.in??:
System.out."rintln<C.nter the File name to SearchL C?:
String st@br.read-ine<?:
File 0@ne7 File<st?:
i0<0.e!ists<??
System.out."rintln<CFile 0ound in C E0?:
else
System.out."rintln<CFile D32 Found in CE0?:
F
catch<.!ce"tion e? ;F
F
F
77
Samp0e Inp4t2o4tp4t
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
1
F1-. CR.A213D
.nter the File DameL
au
.nter the 2e!t <CtrlEG to end?L
Annamalai University
\]
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
2
)1SP-AW1DP F1-. C3D2.D2
.nter the File Dame to dis"layL
au
Annamalai University
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
3
R.DA1DP 2X. F1-.
R.DA1DP F1-.
.nter the .!isting File DameL
au
.nter the De7 File DameL
ua
File au is renamed as ua
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
7=
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
#
S.ARCX1DP A F1-.
.nter the File name to SearchL
au
File D32 Found in au
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
#
S.ARCX1DP A F1-.
.nter the File name to SearchL
ua
File 0ound in ua
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
&
).-.21DP 2X. F1-.
.nter the File to )eleteL
ua
)eleting the File ua
F1-. ADAP..D2 SWS2.
1. De7 File
2. )is"lay File
3. Rename File
#. Search File
&. )elete File
'. .!it
.nter your choiceL
'
7>
E? #O+ &0
D!"E+
S"(DE#" M!#!$EME#" S%S"EM
(SI#$ SHL COMM!#DS
!im+
2o load the student detail in the database and "rocess it using S,-.
!0gorit1m+
1. Create a student table 5student5 de"artment table and set a "rimary %ey 0or reg.no in
student table
2. 1nsert values into the table
3. Alter the data inttable5by inserting ne7 data
#. U"date and delete data in table
&. Commit .
Program+
9999999999999S2U).D2 ADAP..D2 SWS2. US1DP99999999999999
999999999999999999999999S,- C3AD)S99999999999999999999999999
S,-B CR.A2. 2A$-. S2U).D2<R.PD3 DU$.R<(?5C3URS.
[ARCXAR2<2H??:
2able created.
S,-B CR.A2. 2A$-. S2U).D2).2<R.PD3 DU$.R<(? PR1ARW
Q.W5SDA.
[ARCXAR2<2H?5)3$ )A2.5)3J )A2.5S.S [ARCXAR2<3?5).P2DA.
[ARCXAR2<2H??:
2able created.
S,-B CR.A2. 2A$-. ).PAR2.D2<).P2DA. [ARCXAR2<2H?5).P2C3).
DU$.R<(??:
2able created.
S,-B A-2.R 2A$-. S2U).D2).2 A)) R3--D3 DU$.R<(?:
2able altered.
S,-B A-2.R 2A$-. S2U).D2 A)) C3DS2RA1D2 FQ.W1 F3R.P1D Q.W<R.P
D3?
R.F.R.DC.S S2U).D2).2<R.PD3?:
80
2able altered.
S,-BA-2.R 2A$-. ).PAR2.D2 A)) C3DS2RA1D2 PQ.W1
PR1ARWQ.W<).P2C3).?:
2able altered.
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
S,-B).SC S2U).D2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 DU$.R<(?
C3URS. [ARCXAR2<2H?
S,-B).SC ).PAR2.D2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
).P2DA. [ARCXAR2<2H?
).P2C3). D32 DU-- DU$.R<(?
S,-B1DS.R2 1D23 ).PAR2.D2 [A-U.S<^U).P2DA.^5^U).P2C3).^?:
.nter value 0or de"tnameL C3PU2.R
.nter value 0or de"tcodeL 1
old 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^U).P2DA.^5^U).P2C3).^?
ne7 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^C3PU2.R^5^1^?
1 ro7 created.
S,-B/
.nter value 0or de"tnameL .-.C2R1CA-
.nter value 0or de"tcodeL 2
old 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^U).P2DA.^5^U).P2C3).^?
ne7 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^.-.C2R1CA-^5^2^?
1 ro7 created.
S,-B/
.nter value 0or de"tnameL 1DF3RA213D
8&
.nter value 0or de"tcodeL 3
old 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^U).P2DA.^5^U).P2C3).^?
ne7 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^1DF3RA213D^5^3^?
1 ro7 created.
S,-B/
.nter value 0or de"tnameL .-.C2R3D1CS
.nter value 0or de"tcodeL #
old 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^U).P2DA.^5^U).P2C3).^?
ne7 1L 1DS.R2 1D23 ).PAR2.D2 [A-U.S<^.-.C2R3D1CS^5^#^?
1 ro7 created.
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
S,-B1DS.R2 1D23 S2U).D2).2
[A-U.S<UR.PD35^USDA.^5^U)3$^5^U)3J^5^US.S^5^U).P2DA.^5UR3--D3?:
.nter value 0or regnoL 1H2H
.nter value 0or sname L [1D32X
.nter value 0or dobL 11JJU-J1+**
.nter value 0or do8L &JJUDJ1++1
.nter value 0or se!L
.nter value 0or de"tnameL C3PU2.R
.nter value 0or rollnoL 1
old 1L 1DS.R2 1D23 S2U).D2).2
[A-U.S<UR.PD35^USDA.^5^U)3$^5^U)3J^5^US.S^5^U).P2DA.^5UR3--D3?
ne7 1L 1DS.R2 1D23 S2U).D2).2 [A-U.S<1H2H5^[1D32X^5^11JJU-J1+**^5^&JJUDJ
1++1^5^^5^C3PU2.R^51?
1 ro7 created
S,-B/
.nter value 0or regnoL 1H21
.nter value 0or sname L CX1DDU
.nter value 0or dobL 23JJADJ1+('
.nter value 0or do8L 11J).CJ2HH(
.nter value 0or se!L F
.nter value 0or de"tnameL .-.C2R3D1CS
.nter value 0or rollnoL 2
old 1L 1DS.R2 1D23 S2U).D2).2
[A-U.S<UR.PD35^USDA.^5^U)3$^5^U)3J^5^US.S^5^U).P2DA.^5UR3--D3?
82
ne7 1L 1DS.R2 1D23 S2U).D2).2 [A-U.S<1H215^CX1DDU^5^23JJADJ1+('^5^11J
).CJ2HH(^5^F^5^.-.C2R3D1CS^52?
1 ro7 created
S,-B/
.nter value 0or regnoL 1H22
.nter value 0or sname L SXAR1
.nter value 0or dobL +JF.$J1+((
.nter value 0or do8L 11JF.$J2HH(
.nter value 0or se!L F
.nter value 0or de"tnameL 1DF3RA213D
.nter value 0or rollnoL 3
old 1L 1DS.R2 1D23 S2U).D2).2
[A-U.S<UR.PD35^USDA.^5^U)3$^5^U)3J^5^US.S^5^U).P2DA.^5UR3--D3?
ne7 1L 1DS.R2 1D23 S2U).D2).2 [A-U.S<1H225^SXAR1^5^+JF.$J1+((^5^11J
F.$J2HH(^5^F^5^1DF3RA213D^53?
1 ro7 created
S,-B/
.nter value 0or regnoL 1H23
.nter value 0or sname L ASX61D
.nter value 0or dobL 3JJU-J1+(*
.nter value 0or do8L +J).CJ2HH'
.nter value 0or se!L
.nter value 0or de"tnameL .-.C2R1CA-
.nter value 0or rollnoL #
old 1L 1DS.R2 1D23 S2U).D2).2
[A-U.S<UR.PD35^USDA.^5^U)3$^5^U)3J^5^US.S^5^U).P2DA.^5UR3--D3?
ne7 1L 1DS.R2 1D23 S2U).D2).2 [A-U.S<1H235^ASX61D^5^3JJU-J1+(*^5^+J).CJ
2HH'^5^^5^.-.C2R1CA-^5#?
1 ro7 created
S,-B S.-.C29 FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
S,-B).SC S2U).D2
Dame DullV 2y"e
85
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 DU$.R<(?
C3URS. [ARCXAR2<2H?
S,-B 1DS.R2 1D23 S2U).D2 [A-U.S<UR.PD35^UC3URS.^?:
.nter value 0or regnoL 1H2H
.nter value 0or courseL $..
old 1L 1DS.R2 1D23 S2U).D2 [A-U.S<UR.PD35^UC3URS.^?
ne7 1L 1DS.R2 1D23 S2U).D2 [A-U.S<1H2H5^$..^?
1 ro7 created.
S,-B/
.nter value 0or regnoL 1H21
.nter value 0or courseL $..
old 1L 1DS.R2 1D23 S2U).D2 [A-U.S<UR.PD35^UC3URS.^?
ne7 1L 1DS.R2 1D23 S2U).D2 [A-U.S<1H215^$..^?
1 ro7 created.
S,-B/
.nter value 0or regnoL 1H22
.nter value 0or courseL .Sc
old 1L 1DS.R2 1D23 S2U).D2 [A-U.S<UR.PD35^UC3URS.^?
ne7 1L 1DS.R2 1D23 S2U).D2 [A-U.S<1H225^.Sc^?
1 ro7 created.
S,-B/
.nter value 0or regnoL 1H23
.nter value 0or courseL )1P-A3
old 1L 1DS.R2 1D23 S2U).D2 [A-U.S<UR.PD35^UC3URS.^?
ne7 1L 1DS.R2 1D23 S2U).D2 [A-U.S<1H235^)1P-A3^?
1 ro7 created.
S,-B S.-.C29 FR3 S2U).D2:
R.PD3 C3URS.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H $..
1H21 $..
1H22 .Sc
1H23 )1P-A3
S,-BS.-.C29FR3 ).PAR2.D2:
).P2DA. ).P2C3).
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
C3PU2.R 1
.-.C2R1CA- 2
1DF3RA213D 3
.-.C2R3D1CS #
87
S,-B S.-.C2 R.PD35SDA.5).P2DA. FR3 S2U).D2).2 6X.R.
R3--D3B2:
R.PD3 SDA. ).P2DA.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H22 SXAR1 1DF3RA213D
1H23 ASX61D .-.C2R1CA-
S,-B S.-.C2 R.PD35SDA.5).P2DA. FR3 S2U).D2).2 6X.R.
)3$@^H+JF.$J1+((^:
R.PD3 SDA. ).P2DA.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H22 SXAR1 1DF3RA213D
S,-B S.-.C2 R.PD35SDA.5).P2DA. FR3 S2U).D2).2 6X.R.
)3$@^H+JF.$J((^:
no ro7s selected
S,-B S.-.C2 R.PD35SDA.5).P2DA. FR3 S2U).D2).2 6X.R.
)3$@^H+JF.$J1+((^:
R.PD3 SDA. ).P2DA.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H22 SXAR1 1DF3RA213D
S,-B S.-.C2 R.PD35SDA.5).P2DA. FR3 S2U).D2).2 6X.R.
SDA. -1Q.^SR^:
R.PD3 SDA. ).P2DA.
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H22 SXAR1 1DF3RA213D
S,-BA-2.R 2A$-. S2U).D2).2 A)) R.SU-2 [ARCXAR2<1H?:
2able altered.
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
R.SU-2 [ARCXAR2<1H?
88
S,-BA-2.R 2A$-. S2U).D2).2 A)) SCX3-ARSX1P CXAR<1?:
2able altered.
S,-BA-2.R 2A$-. S2U).D2).2 A)) A3UD2 F-3A2:
2able altered.
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
R.SU-2 [ARCXAR2<1H?
SCX3-ARSX1P CXAR<1?
A3UD2 F-3A2<12'?
S,-BS.-.C29FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJ JJJJJJJJJJJJ JJJJJJJJJJJJJJJJJJ JJJJJJJJJJJJJJJJ JJJJJJJJJJJJJ JJJJJJJJJJJJ JJJJJJJJJJJ
R.SU-2 SCX3-ARSX1P A3UD2
JJJJJJJJJJJJJJJJJJJJJ JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
S,-BUP)A2. S2U).D2).2 S.2 R.SU-2@^UR.S^6X.R. R.PD3@UR.PD3:
.nter value 0or resL PASS
.nter value 0or regnoL 1H2H
old 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^UR.S^6X.R. R.PD3@UR.PD3
ne7 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^PASS^6X.R. R.PD3@1H2H
1 ro7 u"dated.
S,-B/
.nter value 0or resL PASS
89
.nter value 0or regnoL 1H21
old 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^UR.S^6X.R. R.PD3@UR.PD3
ne7 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^PASS^6X.R. R.PD3@1H21
1 ro7 u"dated.
S,-B/
.nter value 0or resL FA1-
.nter value 0or regnoL 1H22
old 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^UR.S^6X.R. R.PD3@UR.PD3
ne7 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^FA1-^6X.R. R.PD3@1H22
1 ro7 u"dated.
S,-B/
.nter value 0or resL PASS
.nter value 0or regnoL 1H23
old 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^UR.S^6X.R. R.PD3@UR.PD3
ne7 1L UP)A2. S2U).D2).2 S.2 R.SU-2@^PASS^6X.R. R.PD3@1H23
1 ro7 u"dated.
S,-BS.-.C29FR3 S2U).D2:
R.PD3 C3URS.
JJJJJJ JJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H $..
1H21 $..
1H22 .Sc
1H23 )1P-A3
S,-B)R3P 2A$-. ).PAR2.D2:
2able dro""ed.
S,-BUP)A2. S2U).D2).2 S.2 SCX3-ARSX1P@^D^5A3UD2@H:
# ro7s u"dated.
S,-BS.-.C29FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.SU-2 SCX3-ARSX1P A3UD2
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
PASS D H
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
PASS D H
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
FA1- D H
87
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
PASS D H
S,-BUP)A2. S2U).D2).2 S.2 SCX3-ARSX1P@^USS^5A3UD2@UA2:
.nter value 0or ssL W
.nter value 0or amtL 2HHH.&H
old 1L UP)A2. S2U).D2).2 S.2 SCX3-ARSX1P @^USS^5A3UD2@UA2
ne7 1L UP)A2. S2U).D2).2 S.2 SCX3-ARSX1P@^W^5A3UD2@2HHH.&H
# ro7s u"dated.
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
R.SU-2 [ARCXAR2<1H?
SCX3-ARSX1P CXAR<1?
A3UD2 F-3A2<12'?
S,-BS.-.C29FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.SU-2 SCX3-ARSX1P A3UD2
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
PASS W 2HHH.&
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
PASS W 2HHH.&
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
FA1- W 2HHH.&
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
PASS W 2HHH.&
S,-BA-2.R 2A$-. S2U).D2).2 3)1FW S.S [ARCXAR2<'?:
2able altered.
8=
S,-B).SC S2U).D2).2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 D32 DU-- DU$.R<(?
SDA. [ARCXAR2<2H?
)3$ )A2.
)3J )A2.
S.S [ARCXAR2<3?
).P2DA. [ARCXAR2<2H?
R3--D3 DU$.R<(?
R.SU-2 [ARCXAR2<1H?
SCX3-ARSX1P CXAR<1?
A3UD2 F-3A2<12'?
S,-BS.-.C29FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.SU-2 SCX3-ARSX1P A3UD2
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
PASS W 2HHH.&
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
PASS W 2HHH.&
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
FA1- W 2HHH.&
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
PASS W 2HHH.&
S,-BUP)A2. S2U).D2).2 S.2 S.S@^US.^ 6X.R. S.S@^U1S.S^:
.nter value 0or seL A-.
.nter value 0or ise!L
old 1L UP)A2. S2U).D2).2 S.2 S.S@^US.^ 6X.R. S.S@^U1S.S^
ne7 1L UP)A2. S2U).D2).2 S.2 S.S@^A-.^6X.R. S.S@^^
3 ro7s u"dated.
S,-B/
.nter value 0or seL F.A-.
.nter value 0or ise!L F
8>
old 1L UP)A2. S2U).D2).2 S.2 S.S@^US.^ 6X.R. S.S@^U1S.S^
ne7 1L UP)A2. S2U).D2).2 S.2 S.S@^A-.^6X.R. S.S@^F^
1 ro7s u"dated.
S,-BS.-.C29FR3 S2U).D2).2:
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.SU-2 SCX3-ARSX1P A3UD2
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 C3PU2.R 1
PASS W 2HHH.&
1H21 CX1DDU 23JJADJ(' 11J).CJH( F .-.C2R3D1CS 2
PASS W 2HHH.&
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F 1DF3RA213D 3
FA1- W 2HHH.&
1H23 ASX61D H3JJU-J(* H+J).CJH' .-.C2R1CA- #
PASS W 2HHH.&
S,-BA-2.R 2A$-. S2U).D2 A)) S.S [ARCXAR2<'?:
2able altered.
S,-B).SC S2U).D2:
Dame DullV 2y"e
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
R.PD3 DU$.R<(?
C3URS. [ARCXAR2<2H?
S.S [ARCXAR2<'?
S,-BC312:
Commit com"lete.
es40t+
2hus the 4ueries 7ere "er0ormed.
90
E? #O+ &&
D!"E+
EMPLO%EE M!#!$EME#" (SI#$
PL2SHL ,(#C"IO#S
!im+
2o create a em"loyee management details in the database and "rocess it using P-/S3-
and 0unctions.
!0gorit1m+
1. Create "rocedure "roJem"loyee
2. )eclare the "rocedure
3. )ro" the "rocedure "roJem"loyee
#. Create a 0unction F-
&. )eclare the 0unction F-
'. )ro" 0unction F-
(. Procedure and 0unction are loaded
*. Sto".
Program+
99999999999.P-3W.. ADAP..D2 US1DP P-/S,-FUDC2139999999
create table mast<em"no number<&?5ename varchar2<2H?5hra number<(?5da number<(?5"0
number<(?5lic number<(?5basic number<(52?5net"ay number<*52??:
create or re"lace "rocedure "roem"lo<em"no1 number5bas number?
is
da1 number<(?:
hra1 number<(?:
"01 number<(?:
lic1 number<(?:
netsal1 number<(?:
begin
da1L@<bas9(#/1HH?:
hra1L@<bas91&/1HH?:
"01L@<bas912/1HH?:
lic1L@<bas91H/1HH?:
netsal1L@basEda1Ehra1J"01Jlic1:
dbmsTout"ut."utTline<^.m" )A L^YYda1?:
dbmsTout"ut."utTline<^.m" XRA L^YYhra1?:
9&
dbmsTout"ut."utTline<^.m" PF L^YY"01?:
dbmsTout"ut."utTline<^.m" -1C L^YYlic1?:
dbmsTout"ut."utTline<^.m"DetSalary L^YYnetsal1?:
u"date mast
setnet"ay@netsal15da@da15"0@"015lic@lic15hra@hra1
7hereem"no@em"no1:
end:
/
PR3C.)UR. CR.A2.)
declare
no number<(?:
basic number<(?:
begin
noL@Uno:
basicL@Ubas:
"roem"lo<no5basic?:
end:
/
P-/S,- PR3C.)UR. SUCC.SSFU--W C3P-.2.)
)R3P PR3C.)UR. PR3.P-3:
PR3C.)UR. )R3PP.)
create or re"lace 0unction F-
<!mast.em"noR2WP.?
return number
is
cursor C- is
selectem"no5ename5hra5da5"05lic5basic5net"ay
0rom mast
7hereem"no@!:
var C-RR362WP.:
begin
o"en C-:
loo"
0etch C- into var:
e!it 7hen C-RD32F3UD):
dbmsTout"ut."utTline<^.m"loyee )etails?:
dbmsTout"ut."utTline<^.m"no L^YYvar.em"no?:
dbmsTout"ut."utTline<^.m"Dame L^YYvar.ename?:
dbmsTout"ut."utTline<^$asic L^YYvar.basic?:
dbmsTout"ut."utTline<^PF L^YYvar."0?:
dbmsTout"ut."utTline<^-1C L^YYvar.lic?:
dbmsTout"ut."utTline<^)A L^YYvar.da?:
92
dbmsTout"ut."utTline<^XRA L^YYvar.hra?:
dbmsTout"ut."utTline<^D.2 SA-ARW L^YYvar.net"ay?:
end loo":
close C-:
return H:
end:
/
FUDC213D CR.A2.)
declare
enomast.em"noRty"e:
S Dumber<(?:
begin
enoL@Ueno:
sL@F-<eno?:
end:
/
)R3P FUDC213D F1:
FUDC213D )R3PP.)
es40t+
2hus the em"loyee management systems are loaded in the database using P-/S,- and
0unctions.
95
E? #O+ &2
D!"E+
CE!"IO# O, I#DE? !#D "I$$E
!im+
2o create an inde! and trigger.
!0gorit1m ;or inde)+
1. Create inde! o0 student table.
2. Using the "ortioned inde! on given table
3. Function using on student table.
#. )ro" the inde! on student table.
!0gorit1m ;or trigger+
1. Create a trigger
2. Using a trigger in student table
3. 2riggers 7hen inserting the table.
Program+
AAAAAAAAAACE!"IO# O, I#DE? !#D "I$$EAAAAAAAAAAAAAA
S,-B CR.A2. 1D).S 1D) 3D S2U).D2<R.PD3?:
1nde! created.
S,-B CR.A2. UD1,U. 1D).S 1D)1 3D S2U).D2).2<R3--D3?:
1nde! created.
S,-B CR.A2. 1D).S 1D)2 3D S2U).D2).2<R.PD35R3--D3?:
1nde! created.
S,-B CR.A2. 1D).S 1D)# 3D S2U).D2).2<)3J? R.[.RS.:
1nde! created.
S,-B S.-.C29FR3 S2U).D2).2:
97
R.PD3 SDA. )3$ )3J S.S ).P2DA. R3--D3 R.SU-2
JJJJJ JJJJJJJJJ JJJJJJJJJ JJJJJJJJ JJJJJ JJJJJJJJJJ JJJJJJ JJJJJJJJ
1H2H [1D32X 11JJU-J** H&JJUDJ+1 A-. CS. 1 PASS
1H21 SR1 23JJADJ(' 11J).CJH( A-. .C. 2 FA1-
1H22 SXAR1 H+JF.$J(( 11JF.$JH( F.A-. ... 3 PASS
S,-BA-2.R 2A$-. S2U).D2).2 A)) ).P2D3 DU$.R<(? :
2able altered.
S,-BCR.A2. 1D).S 1D)& 3D S2U).D2).2<).P2D3? P-3$A- PAR21213D
$W
RADP.<).P2D3?
2 <PAR21213D P1 [A-U.S -.SS 2XAD <2H?5
3 PAR21213D P2 [A-U.S -.SS 2XAD<AS[A-U.??:
1nde! created.
S,-BCR.A2. 3R R.P-AC. 2R1PP.R 2R1P
2 $.F3R. 1DS.R2 3D S2U).D2).2
3 $.P1D
# RA1S.TAPP-1CA213DT.RR3R<J2HHH15^S23P .D2.R1DP R.C3R)S^?:
& .D):
' /
2rigger created.
S,-B)R3P 2R1PP.R 2R1P:
2rigger dro""ed.
es40t+
2hus the 4ueries 7ere "er0ormed.
98
E? #O+ &5
D!"E+
CE!"IO# O, "!BLE P!"I"IO#
!im+
2o create a table "artition o0 the table.
!0gorit1m+
1. 2o create a em"loyee
2. 1nsert the values into em"loyee table
3. Partition the em"loyee "art 1 less than _0M 0rom em"loyee table
#.Partition the em"loyee "art 2 less than _nM 0rom em"loyee table
&.Partition the em"loyee "art 3 less than_tM 0rom em"loyee table
'. S"lit the "artition "art3 into "art# and "art &.
Program+
9999999999999999CR.A213D 3F 2A$-. PAR21213D99999999999999999
S,-B CR.A2. 2A$-. S2U)<DA. [ARCXAR2<1H?5.D3 DU$.R<(?5$AS1C
DU$.R<(??PAR21213D $W RADP.<.D3?<PAR21213D SD31 [A-U.S -.SS
2XAD<1H?5PAR21213D SD32 [A-U.S -.SS 2XAD<2H??:
2able created.
S,-B 1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?:
.nter value 0or nameL[1D32X
.nter value 0or enoL1
.nter value 0or basicL*HHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^[1D32X^515*HHH?
1 ro7 created.
S,-B/
.nter value 0or nameLDA2XAD
.nter value 0or enoL12
.nter value 0or basicL+HHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^DA2XAD^5125+HHH?
1 ro7 created.
99
S,-BS.-.C29FR3 S2U):
DA. .D3 $AS1C
JJJJ JJJJ JJJJJ
[1D32X 1 *HHH
DA2XAD 12 +HHH
S,-B S.-.C29FR3 S2U) PAR21213D<SD31?:
DA. .D3 $AS1C
JJJJ JJJ JJJJJJJ
[1D32X 1 *HHH
S,-B S.-.C29FR3 S2U) PAR21213D<SD32?:
DA. .D3 $AS1C
JJJJ JJJJ JJJJJ
DA2XAD 12 +HHH
S,-BA-2.R 2A$-. S2U) A)) PAR21213D SD33 [A-U.S -.SS 2XAD <3H?:
2able altered.
S,-B1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?:
.nter value 0or nameLAD3
.nter value 0or enoL2#
.nter value 0or basicL1HHHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^AD3^52#51HHHH?
1 ro7 created.
S,-B/
.nter value 0or nameL..DA
.nter value 0or enoL2&
.nter value 0or basicL11HHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5U.D35U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^..DA^52&511HHH?
1 ro7 created.
97
S,-BS.-.C29FR3 S2U):
DA. .D3 $AS1C
JJJJ JJJ JJJJJJ
[1D32X 1 *HHH
DA2XAD 12 +HHH
AD3 2# 1HHHH
..DA 2& 11HHH
S,-BS.-.C29FR3 S2U) PAR21213D<SD33?:
DA. .D3 $AS1C
JJJJJ JJJJ JJJJJJ
AD3 2# 1HHHH
..DA 2& 11HHH
S,-BA-2.R 2A$-. S2U) SP-12 PAR21213D SD33 A2<2&? 1D23<PAR21213D
SD3115PAR21213D SD312?:
2able altered.
S,-BS.-.C29FR3 S2U) PAR21213D<SD311?:
DA. .D3 $AS1C
JJJJ JJJ JJJJJ
AD3 2# 1HHHH
S,-BS.-.C29FR3 S2U) PAR21213D<SD312?:
DA. .D3 $AS1C
JJJJ JJJ JJJJJ
..DA 2& 11HHH
S,-B1DS.R2 1D23 S2U) [A-U.S<^UDA.^5^U.D3^5U$AS1C?:
.nter value 0or nameL..DA
.nter value 0or enoL22
.nter value 0or basicL1&HHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5^U.D3^5U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^..DA^5^22^51&HHH?
1 ro7 created.
S,-B1DS.R2 1D23 S2U) [A-U.S<^UDA.^5^U.D3^5U$AS1C?:
.nter value 0or nameLS3U
.nter value 0or enoL2'
.nter value 0or basicL1#HHH
old 1L1DS.R2 1D23 S2U) [A-U.S<^UDA.^5^U.D3^5U$AS1C?
ne7 1L1DS.R2 1D23 S2U) [A-U.S<^S3U^5^2'^51#HHH?
9=
1 ro7 created.
S,-BS.-.C29FR3 S2U) PAR21213D<SD311?:
DA. .D3 $AS1C
JJJJ JJJJ JJJJJJ
AD3 2# 1HHHH
..DA 22 1&HHH
S,-BS.-.C29FR3 S2U) PAR21213D<SD312?:
DA. .D3 $AS1C
JJJJ JJJ JJJJJJ
..DA 2& 11HHH
S3U 2' 1#HHH
S,-BC312:
Commit com"lete.
es40t+
2hus the 4ueries 7ere "er0ormed.
9>
E) #o+ &7
Date+
ODBC and 6DBC Conne3ti:ity
!im+
2o Create an 3)$C and J)$C data source 0or .m"loyee.
!0gorit1m+
J)$C is used to connect the 8ava 7ith oracle 0or the database a""lications. 1n this 8ava is
7or%ing as 0ront end and oracle as bac% end. Java database connectivity is achieved using the
3)$C <3"en database Connectivity? data source
Ste"s involved in creating the 3)$C data source are given belo7.
1n control Panel choose `Administrative 2oolsa and Select `3)$C data Sourcea
70
1n User )SD add `icroso0t 3)$C 0or oracle )rivera and assign the )SD name.
7&
PO$!M+
im"ort 8ava.s4l.9:
class cre
;
"ublic static void main<string args=>? thro7s .!ce"tion
;
try
;
class.0orDame<Csun.8dbc.odbc.8dbcd3bc)riverC?:
connection con@)riveranager.getconnnecion<C8dbcLodbcLds%C5CscottC5CtigerC?:
statemant st@con.createStatement<?:
st.e!ecuteU"date<Ccreate table sur1<name varchar2<2H?5age number<3??C?:
system.out."rintln<C2able CreatedC?:
F
catch<S,-.!ce"tion e?
;
e."rintStac%2race<?:
F
F
F
es40t+
2hus the J)$C and 3)$C Connectivity 7ere "er0ormed.
72

You might also like