Programming pardigms.doc
-
Upload
venkatesh-naidu -
Category
Documents
-
view
213 -
download
0
Transcript of Programming pardigms.doc
-
8/10/2019 Programming pardigms.doc
1/34
PROGRAMMING PARADIGMS
GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY
VELLORE 632 501
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Third Year Computer Science and Engineering !thSeme"ter
#UESTION $AN% UNI&ERSITY #UESTIONS
Su'(ect Code ) Name*CS+,-! PROGRAMMING PARADIGMS
Prepared '.* Mr/A/R/R Senthi01umar AP2CSE
UNIT3I
PART 4 A
1. Define constructor? (DEC 2012,CSE)A constructor is a special meto! "ose purpose is to construct an!
initiali#e o$%ects& Constructors al"a's a(e te same name as te class
name&2. List out the t!e of "rr"s.(DEC 2012,CSE)
Sin#$e %i&ension "rr"s
'u$ti %i&ension"$ "rr"s
3. o to cre"te one %i&ension"$ "rr"? (DEC 2012,*+)TY)E ARRAYNA*E+,- NE. TY)E+SI/E,0int ia+, - ne" int+122,0
. 'ention so&e of the se!"r"tors use% in -"" !ro#r"&&in#?(DEC 2012,*+)CO''/S,unctu"tions,Se&ico$on ,co&&ents .
5. Define the ter& c$"ss. ('" 2012 +o '"r *+)A class is a $lueprint or protot'pe 3rom "ic o$%ects are create!& Te
entire set o3 !ata an! co!e o3 an o$%ect can $e ma!e o3 a user !e4ne! !ata
t'pe "it te elp o3 a class& .e can create an' num$er o3 o$%ects 3or te
same class&
6. h"t is fin"$iin# ðo%? ('" 2012 +o '"r *+)Finali#er meto!s are li5e te opposite o3 constructor meto!s0 "ereas a
constructor meto! is use! to initiali#e an o$%ect6 4nali#er meto!s are
calle! %ust $e3ore te o$%ect is 7ar$a7e collecte! an! its memor' reclaime!&
To create a 4nali#er meto!6 inclu!e a meto! "it te 3ollo"in7 si7nature
in 'our class !e4nition8
Department o3 Compute Science an! En7ineerin7 )a7e 1
-
8/10/2019 Programming pardigms.doc
2/34
PROGRAMMING PARADIGMS
(oi! 4nali#e9: ; &&& s 2 "s. +he first thin# is to no th"t " -Iutton>s e%#es "re %r"n "
Ior%er. so ou c"n oerri%e the Iutton>s !"intCo&!onent(Ar"!hics) ðo% "n% %r" "
circ$e or roun%e% rect"n#$e (h"teer), "n% turn off the or%er. Or ou c"n cre"te " custo&
or%er th"t %r"s " circ$e or roun%e% rect"n#$e "roun% "n co&!onent "n% set the utton>s
or%er to it.
3. h"t is the %ifference eteen the ont> "n% ont'etrics> c$"ss? ('" 2012 +o '"r
CSE)
+he ont C$"ss is use% to ren%er #$!hs> 7 the ch"r"cters ou see on the screen.
ont'etrics enc"!su$"tes infor&"tion "out " s!ecific font on " s!ecific Ar"!hics oect.
(i%th of the ch"r"cters, "scent, %escent)
Department o3 Compute Science an! En7ineerin7 )a7e 16
-
8/10/2019 Programming pardigms.doc
17/34
PROGRAMMING PARADIGMS
. h"t is the %ifference eteen the !"int() "n% re!"int() ðo%s? ('" 2012 +o '"r
CSE)
+he !"int() ðo% su!!orts !"intin# i" " Ar"!hics oect. +he re!"int() ðo% is use% to
c"use !"int() to e inoe% the /+ !"intin# thre"%.
!/ hich cont"iners use " or%er L"out "s their %ef"u$t $"out? .(DEC 2012,CSE)
+he in%o, r"&e "n% Di"$o# c$"sses use " or%er $"out "s their %ef"u$t $"out.
=/ h"t is the %ifference eteen "!!$ic"tions "n% "!!$ets? ('" 2012 +o '"r CSE)
")/!!$ic"tion &ust e run on $oc"$ &"chine here"s "!!$et nee%s no e@!$icit inst"$$"tion on
$oc"$ &"chine.
)/!!$ic"tion &ust e run e@!$icit$ ithin " ""7co&!"ti$e irtu"$ &"chine here"s
"!!$et $o"%s "n% runs itse$f "uto&"tic"$$ in " ""7en"$e% roser.
c)/!!$ic"tion st"rts e@ecution ith its &"in ðo% here"s "!!$et st"rts e@ecution ith its
init ðo%.
%)/!!$ic"tion c"n run ith or ithout #r"!hic"$ user interf"ce here"s "!!$et &ust run ithin
" #r"!hic"$ user interf"ce.
@/ Difference eteen Sin# "n% /t? .(DEC 2012,CSE)
/+ "re he"7ei#ht co&!onenets. Sin#s "re $i#ht7ei#ht co&!onents. ence sin# orsf"ster th"n /+.
/ h"t is " $"out &"n"#er "n% h"t "re %ifferent t!es of $"out &"n"#ers ""i$"$e in ""
/+? ('" 2012 +o '"r CSE)
/ $"out &"n"#er is "n oect th"t is use% to or#"nie co&!onents in " cont"iner. +he %ifferent
$"outs "re ""i$"$e "re $oL"out, Ior%erL"out, C"r%L"out, Ari%L"out "n%
Ari%I"#L"out.
B/ o "re the e$e&ents of %ifferent $"outs or#"nie%? ('" 2012 +o '"r CSE)
Department o3 Compute Science an! En7ineerin7 )a7e 14
-
8/10/2019 Programming pardigms.doc
18/34
PROGRAMMING PARADIGMS
$oL"out8 +he e$e&ents of " $o L"out "re or#"nie% in " to! to otto&, $eft to ri#ht f"shion.
Ior%erL"out8 +he e$e&ents of " Ior%er L"out "re or#"nie% "t the or%ers (North, South, E"st
"n% est) "n% the center of " cont"iner.
C"r%L"out8 +he e$e&ents of " C"r%L"out "re st"ce%, on to! of the other, $ie " %ec of c"r%s
Ari%L"out8 +he e$e&ents of " Ari%L"out "re of ePu"$ sie "n% "re $"i% out usin# the sPu"re of "
#ri%.
Ari%I"#L"out8 +he e$e&ents of " Ari%I"#L"out "re or#"nie% "ccor%in# to " #ri%. oeer,
the e$e&ents "re of %ifferent sie "n% &" occu! &ore th"n one ro or co$u&n of the #ri%. *n
"%%ition, the ros "n% co$u&ns &" h"e %ifferent sie. +he %ef"u$t L"out '"n"#er of "ne$ "n%
"ne$ su c$"sses is $oL"out.
11) h"t is "n eent "n% h"t "re the &o%e$s ""i$"$e for eent h"n%$in#? .(DEC 2012,CSE)
/n eent is "n eent oect th"t %escries " st"te of ch"n#e in " source. *n other or%s,
eent occurs hen "n "ction is #ener"te%, $ie !ressin# utton, c$icin# &ouse, se$ectin# " $ist, etc.
+here "re to t!es of &o%e$s for h"n%$in# eents "n% the "re8
") eent7inherit"nce &o%e$ "n%
) eent7%e$e#"tion &o%e$
12) h"t is the %ifference eteen scro$$"r "n% scro$$!"ne? .(DEC 2013,CSE)/ Scro$$"r is " Co&!onent, ut not " Cont"iner here"s Scro$$!"ne is " Con"tiner "n%
h"n%$es its on eents "n% !erfor& its on scro$$in#.
13) h on>t the -V' ter&in"te hen * c$ose "$$ the "!!$ic"tion in%os? .(DEC 2012,CSE)
+he /+ eent %is!"tcher thre"% is not " %"e&on thre"%. ou &ust e@!$icit$ c"$$
Sste&.e@it to ter&in"te the -V'.
1) h"t is &e"nt contro$s "n% h"t "re %ifferent t!es of contro$s in /+?(DEC 2012,CSE)
Contro$s "re co&!onents th"t "$$o " user to inter"ct ith our "!!$ic"tion "n% the /+
su!!orts the fo$$oin# t!es of contro$s8 L"e$s, ush Iuttons, Chec Io@es, Choice Lists, Lists,
Scro$$"rs, "n% +e@t Co&!onents. +hese contro$s "re suc$"sses of Co&!onent.
Department o3 Compute Science an! En7ineerin7 )a7e 1;
-
8/10/2019 Programming pardigms.doc
19/34
PROGRAMMING PARADIGMS
15) h"t is the %ifference eteen " Choice "n% " List? .(DEC 2012,CSE)
/ Choice is %is!$"e% in " co&!"ct for& th"t rePuires ou to !u$$ it %on to see the $ist of
""i$"$e choices. On$ one ite& &" e se$ecte% fro& " Choice. / List &" e %is!$"e% in such "
" th"t seer"$ List ite&s "re isi$e. / List su!!orts the se$ection of one or &ore List ite&s.
16) h"t is the !ur!ose of the en"$eEents() ðo%? .(DEC 2012,CSE)
+he en"$eEents() ðo% is use% to en"$e "n eent for " !"rticu$"r oect. Nor&"$$,"n
eent is en"$e% hen " $istener is "%%e% to "n oect for " !"rticu$"r eent. +he en"$eEents()
ðo% is use% oects th"t h"n%$e eents oerri%in# their eent%is!"tch ðo%s.
14) h"t is the %ifference eteen the i$e "n% R"n%o&/ccessi$e c$"sses? .(DEC 2012,CSE)
+he i$e c$"ss enc"!su$"tes the fi$es "n% %irectories of the $oc"$ fi$e sste&. +he
R"n%o&/ccessi$e c$"ss !roi%es the ðo%s nee%e% to %irect$ "ccess %"t" cont"ine% in "n !"rt
of " fi$e.
1;) h"t is the $ifecc$e of "n "!!$et? .(DEC 2012,CSE)init() ðo% 7 C"n e c"$$e% hen "n "!!$et is first $o"%e% st"rt() ðo% 7 C"n e c"$$e%
e"ch ti&e "n "!!$et is st"rte%. !"int() ðo% 7 C"n e c"$$e% hen the "!!$et is &ini&ie% or
&"@i&ie%. sto!() ðo% 7 C"n e use% hen the roser &oes off the "!!$et>s !"#e. %estro()
ðo% 7 C"n e c"$$e% hen the roser is finishe% ith the "!!$et.
1
-
8/10/2019 Programming pardigms.doc
20/34
PROGRAMMING PARADIGMS
PART $
1. E@!$"in Aeneric ro#r"&&in# in Det"i$?
*ntro%uction
Si&!$e ro#r"&
ier"rch "n% c$"ssific"tion
'oti"tion
Aeneric 'etho%s ith e@"&!$e
Aeneric C$"ss ith e@"&!$e
i$%c"r%
2. E@!"$in Aeneric Ref$ection in Det"i$?
o Aeneric 'etho% Return +!es
o Aeneric 'etho% "r"&eter +!es
o Aeneric ie$% +!es
o De&onstr"te " si&!$e #eneric ðo%
3. E@!$"in E@ce!tion in Det"i$?
/n e@ce!tion is "n eent th"t occurs %urin# the e@ecution of " !ro#r"& th"t %isru!ts the
nor&"$ f$o of instructions.+he C"tch or S!ecif RePuire&ent
+his section coers ho to c"tch "n% h"n%$e e@ce!tions. +he %iscussion inc$u%es thetr, c"tch, "n% fin"$$ $ocs, "s e$$ "s ch"ine% e@ce!tions "n% $o##in#. o to+hro
E@ce!tions+his section coers the thro st"te&ent "n% the +hro"$e c$"ss "n% its suc$"sses.
nchece% E@ce!tions = +he Controers +his section e@!$"ins the correct "n% incorrect use ofthe unchece% e@ce!tions in%ic"te% suc$"sses of Runti&eE@ce!tion.
Co$$ections M '"!!in#s
ti$ities "n% /$#orith&s "r"&eterie% +!es
/rr"s to Lists
Concor%"nce
or%
Checin#
E@ce!tion "n%$in#
Department o3 Compute Science an! En7ineerin7 )a7e 20
-
8/10/2019 Programming pardigms.doc
21/34
PROGRAMMING PARADIGMS
thros "n% thro
Effectie ier"rch
/%"nt"#es of E@ce!tions
+he use of e@ce!tions to &"n"#e errors h"s so&e "%"nt"#es oer tr"%ition"$ error &"n"#e&ent
techniPues.
. Aie " e@"&!$e for St"c+r"ce'etho%? ith e@!$"n"tion?
"".$"n#.Oect "".$"n#.St"c+r"ceE$e&ent
/$$ *&!$e&ente% *nterf"ces8
Seri"$i"$e
5. E@!$"in in %et"i$ "out /+ eent hier"rch? (DEC 2012,*+)(16'"r)
Source E8ent C0a"" C0a"" Method" i"tener Inter6ace Inter6ace Method"
Iutton /ctionEent Strin#
#et/ctionCo&&"n%( )
/ctionListener "ctionerfor&e%(/
ctionEent "e)
List, Choice,
Checo@
*te&Eent Oect #et*te&( )
*te&Se$ect"$e#et*te&Se$ect"$e(
)
*te&Listener ite&St"teCh"n#e%(*
te&Eent ie)
eo"r% eEent ch"r #eteCh"r( )int #eteCo%e( )
eListener eresse%(eEent ke)
eRe$e"se%(eEent ke)
e+!e%(eEent ke)
'ouse 'ouseEent int #etU( ) int#et( )
'ouseListener &ouseC$ice%('ouseEent me)
&ouseEntere%('ou
seEent me)
&ouseE@ite%('ouseEent me)
&ouseresse%('ou
seEent me)
&ouseRe$e"se%('o
useEent me)'ouse'otionListener &ouseDr"##e%('ouseEent me)
&ouse'oe%('ouseEent me)
6. E@!$"in "out "!!$et $ifecc$e? o "!!$ets "re !re!"re% "n% e@ecute%.(DEC 2012,*+)
(16'"r)
init() ðo%
Department o3 Compute Science an! En7ineerin7 )a7e 21
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/7/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/7/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html -
8/10/2019 Programming pardigms.doc
22/34
PROGRAMMING PARADIGMS
st"rt() ðo%
!"int() ðo%
sto!() ðo%
%estro() ðo%
E@"&!$e !ro#r"& E@!$"n"tion
4. E@!$"in the "rious eents h"n%$in# in %et"i$. ('" 2012 16 '"r *+)
Eents h"n%$in#
+!es of Eent
Ste!s ino$e% in eent h"n%$in#
E@"&!$e !ro#r"&
E@!$"n"tion
;. E@!$"in "n fie sin# co&!onent ith "n e@"&!$e !ro#r"&. ('" 2012 16 '"r CSE)
S
-
8/10/2019 Programming pardigms.doc
23/34
PROGRAMMING PARADIGMS
-"ssor%ie$% -"ssor%ie$%(Strin# te@t, int
co$u&ns)
oi% setEchoCh"r(ch"r echo)
-
8/10/2019 Programming pardigms.doc
24/34
PROGRAMMING PARADIGMS
Chece% e@ce!tions8 / chece% e@ce!tion is so&e suc$"ss of E@ce!tion (or E@ce!tion
itse$f), e@c$u%in# c$"ss Runti&eE@ce!tion "n% its suc$"sses. E"ch ðo% &ust either
h"n%$e "$$ chece% e@ce!tions su!!$in# " c"tch c$"use or $ist e"ch unh"n%$e% chece%
e@ce!tion "s " thron e@ce!tion.nchece% e@ce!tions8 /$$ E@ce!tions th"t e@ten% the Runti&eE@ce!tion c$"ss "re
unchece% e@ce!tions. C$"ss Error "n% its suc$"sses "$so "re unchece%.
& h Errors "re Not Chece%? .(DEC 201072&)
/ unchece% e@ce!tion c$"sses hich "re the error c$"sses (Error "n% its suc$"sses) "re
e@e&!te% fro& co&!i$e7ti&e checin# ec"use the c"n occur "t &"n !oints in the
!ro#r"& "n% recoer fro& the& is %ifficu$t or i&!ossi$e. / !ro#r"& %ec$"rin# such
e@ce!tions ou$% e !oint$ess$.
J& o %oes " tr st"te&ent %eter&ine hich c"tch c$"use shou$% e use% to h"n%$e "n
e@ce!tion? .(DEC 201072&)hen "n e@ce!tion is thron ithin the o% of " tr st"te&ent, the c"tch c$"uses of the tr
st"te&ent "re e@"&ine% in the or%er in hich the "!!e"r. +he first c"tch c$"use th"t is
c"!"$e of h"n%$in# the e@ce!tion is e@ecute%. +he re&"inin# c"tch c$"uses "re i#nore%.
K& h"t is the !ur!ose of the fin"$$ c$"use of " tr7c"tch7fin"$$ st"te&ent? .(DEC 201072&)
+he fin"$$ c$"use is use% to !roi%e the c"!"i$it to e@ecute co%e no &"tter hether or
not "n e@ce!tion is thron or c"u#ht.
& h"t is the %ifference eteen chece% "n% nchece% E@ce!tions in -""? .(DEC 20107
2&)/$$ !re%efine% e@ce!tions in -"" "re either " chece% e@ce!tion or "n
unchece% e@ce!tion. Chece% e@ce!tions &ust e c"u#ht usin# tr.. c"tch () $oc or e
shou$% thro the e@ce!tion usin# thros c$"use. *f ou %ont, co&!i$"tion of !ro#r"& i$$
f"i$.
12&h"t is the %ifference eteen e@ce!tion "n% error?.(DEC 201072&)+he e@ce!tion c$"ss %efines &i$% error con%itions th"t our !ro#r"&
encounters. E@ce!tions c"n occur hen trin# to o!en the fi$e, hich %oes not e@ist, the
netor connection is %isru!te%, o!er"n%s ein# &"ni!u$"te% "re out of !rescrie% r"n#es,
the c$"ss fi$e ou "re intereste% in $o"%in# is &issin#. +he error c$"ss %efines serious error
Department o3 Compute Science an! En7ineerin7 )a7e 2
-
8/10/2019 Programming pardigms.doc
25/34
PROGRAMMING PARADIGMS
con%itions th"t ou shou$% not "tte&!t to recoer fro&. *n &ost c"ses it is "%is"$e to $et
the !ro#r"& ter&in"te hen such "n error is encountere%.11&h"t is the c"tch or %ec$"re ru$e for ðo% %ec$"r"tions? ('" 2012 +o '"r *+ CSE)
*f " chece% e@ce!tion &" e thron ithin the o% of " ðo%, the ðo% &ust either
c"tch the e@ce!tion or %ec$"re it in its thros c$"use.1&hen is the fin"$$ c$"use of " tr7c"tch7fin"$$ st"te&ent e@ecute%? .(DEC 201072&)
+he fin"$$ c$"use of the tr7c"tch7fin"$$ st"te&ent is "$"s e@ecute% un$ess the thre"% of
e@ecution ter&in"tes or "n e@ce!tion occurs ithin the e@ecution of the fin"$$ c$"use.
1&h"t if there is " re" or return st"te&ent in tr $oc fo$$oe% fin"$$ $oc? .(DEC
201072&)*f there is " return st"te&ent in the tr $oc, the fin"$$ $oc e@ecutes ri#ht "fter the return
st"te&ent encountere%, "n% efore the return e@ecutes.
1&h"t "re the %ifferent "s to h"n%$e e@ce!tions? .(DEC 201072&)
+here "re to "s to h"n%$e e@ce!tions8
r"!!in# the %esire% co%e in " tr $oc fo$$oe% " c"tch $oc to c"tch the e@ce!tions.List the %esire% e@ce!tions in the thros c$"use of the ðo% "n% $et the c"$$er of the
ðo% h"n%$e those e@ce!tions.1&o to cre"te custo& e@ce!tions? ('" 2012 +o '"r *+ CSE)
I e@ten%in# the E@ce!tion c$"ss or one of its suc$"sses.
E@"&!$e8
c$"ss'E@ce!tione@ten%sE@ce!tion
!u$ic'E@ce!tion()
su!er()9 H!u$ic'E@ce!tion(Strin#s)
su!er(s)9 H
H
1&C"n e h"e the tr $oc ithout c"tch $oc? .(DEC 201072&)
es, e c"n h"e the tr $oc ithout c"tch $oc, ut fin"$$ $oc shou$% fo$$o the tr
$oc.Note8 *t is not "$i% to use " tr c$"use ithout either " c"tch c$"use or " fin"$$ c$"use.
14. h"t is the %ifference eteen sin# "n% "!!$et?Sin# is " $i#ht ei#ht co&!onent here"s /!!$et is " he" ei#ht Co&!onent. /!!$et
%oes not rePuire &"in ðo%, inste"% it nee%s init ðo%.
Department o3 Compute Science an! En7ineerin7 )a7e 25
-
8/10/2019 Programming pardigms.doc
26/34
PROGRAMMING PARADIGMS
1K&h"t is the use of "ssert eor%? ('" 2012 +o '"r *+ CSE)
/ssert eor% "$i%"tes cert"in e@!ressions. *t re!$"ces the if $oc effectie$ "n%
thros "n /ssertionError on f"i$ure. +he "ssert eor% shou$% e use% on$ for critic"$
"r#u&ents (&e"ns ithout th"t the ðo% %oes nothin#).
1&o %oes fin"$$ $oc %iffer fro& fin"$ie() ðo%? .(DEC 201072&)
in"$$ $oc i$$ e e@ecute% hether or not "n e@ce!tion is thron. So it is use% to free
resoources. fin"$ie() is " !rotecte% ðo% in the Oect c$"ss hich is c"$$e% the -V'
ust efore "n oect is #"r"#e co$$ecte%.
2&h"t is the %ifference eteen thro "n% thros c$"use? ('" 2012 +o '"r *+ CSE)
thro is use% to thro "n e@ce!tion &"nu"$$, here "s thros is use% in the c"se of
chece% e@ce!tions, to te$$ the co&!i$er th"t e h"enBt h"n%$e% the e@ce!tion, so th"t the
e@ce!tion i$$ e h"n%$e% the c"$$in# function.
1&h"t "re the %ifferent "s to #ener"te "n% E@ce!tion? .(DEC 201072&)+here "re to %ifferent "s to #ener"te "n E@ce!tion. E@ce!tions c"n e #ener"te% the
-"" run7ti&e sste&. E@ce!tions thron -"" re$"te to fun%"&ent"$ errors th"t io$"te the
ru$es of the -"" $"n#u"#e or the constr"ints of the -"" e@ecution eniron&ent. E@ce!tions c"n e
&"nu"$$ #ener"te% our co%e. '"nu"$$ #ener"te% e@ce!tions "re t!ic"$$ use% to re!ort so&e
error con%ition to the c"$$er of " ðo%.
&here %oes E@ce!tion st"n% in the -"" tree hier"rch? .(DEC 201072&)"".$"n#.Oect"".$"n#.+hro"$e
"".$"n#.E@ce!tion
"".$"n#.Error
&h"t is St"cOerf$oError? ('" 2012 +o '"r *+ CSE)
+he St"cOer$oError is "n Error Oect thorn the Runti&e Sste& hen it
Encounters th"t our "!!$ic"tionFco%e h"s r"n out of the &e&or. *t &" occur in c"se of
recursie ðo%s or " $"r#e "&ount of %"t" is fetche% fro& the serer "n% store% in so&e
oect. +his error is #ener"te% -V'.e.#. oi% s"!()
s"!()9H
&E@!$"in the e@ce!tion hier"rch in "". .(DEC 201072&)
Department o3 Compute Science an! En7ineerin7 )a7e 26
http://www.javacertificate.net/core_java_iqns_10.htmhttp://www.javacertificate.net/core_java_iqns_10.htm -
8/10/2019 Programming pardigms.doc
27/34
PROGRAMMING PARADIGMS
+he hier"rch is "s fo$$os8 +hro"$e is " !"rent c$"ss off "$$ E@ce!tion
c$"sses. +he "re to t!es of E@ce!tions8 Chece% e@ce!tions "n% nchece%E@ce!tions.
Ioth t!e of e@ce!tions e@ten%s E@ce!tion c$"ss
&o %o ou #et the %escri!tie infor&"tion "out the E@ce!tion occurre% %urin# the
!ro#r"& e@ecution? ('" 2012 +o '"r *+ CSE)
/$$ the e@ce!tions inherit " ðo% !rintSt"c+r"ce() fro& the +hro"$e c$"ss.
+his ðo% !rints the st"c tr"ce fro& here the e@ce!tion occurre%. *t !rints the &ost
recent$ entere% ðo% first "n% continues %on, !rintin# the n"&e of e"ch ðo% "s it
ors its " %on the c"$$ st"c fro& the to!.
PART $
1. E@!$"in #eneric c$"sses "n% their ðo%s).(DEC 2012,CSE)(16'"r)
2. E@!$"in the throin# "n% c"tchin# e@ce!tion. (DEC 2012,*+,CSE)(16'"r)3. E@!$"in in %et"i$ "out inherit"nce, #enerics "n% ref$ection.(DEC 2012,*+)(16'"r)
. E@!$"in e@ce!tion h"n%$in# fe"ture of -"" in %et"i$. ('" 2012 16 '"r *+)
5. E@!$"in the fo$$oin# ('" 2012 16 '"r CSE)i) Aeneric c$"sses
ii) Aeneric ðo%s
6. Discuss on e@ce!tion h"n%$in# in %et"i$. ('" 2012 16 '"r CSE)
4. h"t is "n e@ce!tion? E@!$"in ho to thro, c"tch "n% h"n%$e e@ce!tions. (DEC20107*+);. h"t is #eneric !ro#r"&&in# "n% h is it nee%e%? List the $i&it"tions "n% restrictions of
#eneric !ro#r"&&in#. (DEC20107*+)
-
8/10/2019 Programming pardigms.doc
28/34
PROGRAMMING PARADIGMS
UNIT3&
PART 4 A
!" E@!$"in %ifferent " of usin# thre"%? .(2&7&" 2013)
+he thre"% cou$% e i&!$e&ente% usin# runn"$e interf"ce or inheritin# fro& the
+hre"% c$"ss. +he for&er is &ore "%"nt"#eous, Bc"use hen ou "re #oin# for &u$ti!$e
inherit"nce..the on$ interf"ce c"n he$!.
2) h"t "re the %ifferent st"tes of " thre"%? (2&7&" 2011)
+he %ifferent thre"% st"tes "re
re"%,
runnin#,
"itin#
%e"%.
3) h "re there se!"r"te "it "n% s$ee! ðo%s? .(2&7&" 2011)
+he st"tic +hre"%.s$ee!($on#) ðo% &"int"ins contro$ of thre"% e@ecution ut
%e$"s the ne@t "ction unti$ the s$ee! ti&e e@!ires. +he "it ðo% #ies u! contro$ oer thre"%
e@ecution in%efinite$ so th"t other thre"%s c"n run.
) h"t is &u$tithre"%in# "n% h"t "re the ðo%s for inter7thre"% co&&unic"tion "n% h"t is
the c$"ss in hich these ðo%s "re %efine%? .(2&7&" 2011)
'u$tithre"%in# is the &ech"nis& in hich &ore th"n one thre"% run in%e!en%ent of e"ch other
ithin the !rocess. "it (), notif () "n% notif/$$() ðo%s c"n e use% for inter7thre"%
co&&unic"tion "n% these ðo%s "re in Oect c$"ss. "it() 8 hen " thre"% e@ecutes " c"$$ to
"it() ðo%, it surren%ers the oect $oc "n% enters into " "itin# st"te. notif() or notif/$$() 8
+o re&oe " thre"% fro& the "itin# st"te, so&e other thre"% &ust &"e " c"$$ to notif() or
notif/$$() ðo% on the s"&e oect.
Department o3 Compute Science an! En7ineerin7 )a7e 2;
-
8/10/2019 Programming pardigms.doc
29/34
PROGRAMMING PARADIGMS
5) h"t is snchroni"tion "n% h is it i&!ort"nt? .(2&7&" 2011)
ith res!ect to &u$tithre"%in#, snchroni"tion is the c"!"i$it to contro$ the "ccess of
&u$ti!$e thre"%s to sh"re% resources. ithout snchroni"tion, it is !ossi$e for one thre"% to
&o%if " sh"re% oect hi$e "nother thre"% is in the !rocess of usin# or u!%"tin# th"t oectBs
"$ue. +his often $e"%s to si#nific"nt errors.
6) o %oes &u$tithre"%in# t"e !$"ce on " co&!uter ith " sin#$e C? .(2&7&" 2011)
+he o!er"tin# sste&Bst"s sche%u$er "$$oc"tes e@ecution ti&e to &u$ti!$e t"ss. I
Puic$ sitchin# eteen e@ecutin# t"ss, it cre"tes the i&!ression th"t t"ss e@ecute
sePuenti"$$.
4) h"t is the %ifference eteen !rocess "n% thre"%? .(2&7&" 2011)
rocess is " !ro#r"& in e@ecution here"s thre"% is " se!"r"te !"th of e@ecution in "
!ro#r"&.
;) h"t h"!!ens hen ou inoe " thre"%Bs interru!t ðo% hi$e it is s$ee!in# or "itin#?(2&7
&" 2011)
hen " t"sBs interru!t() ðo% is e@ecute%, the t"s enters the re"% st"te. +he ne@t ti&e
the t"s enters the runnin# st"te, "n *nterru!te%E@ce!tion is thron.
-
8/10/2019 Programming pardigms.doc
30/34
PROGRAMMING PARADIGMS
rior to -"" 5, is/$ie() "s co&&on$ use% to test " thre"%s st"te. *f /$ie()
returne% f"$se the thre"% "s either ne or ter&in"te% ut there "s si&!$ no " to %ifferenti"te
eteen the to.
12) h"t is snchronie% eor%? *n h"t situ"tions ou i$$ se it? .(2&7&" 2011)
Snchroni"tionis the "ct of seri"$iin# "ccess to critic"$ sections of co%e. e i$$ use this
eor% hen e e@!ect &u$ti!$e thre"%s to "ccessF&o%if the s"&e %"t". +o un%erst"n%
snchroni"tion e nee% to $oo into thre"% e@ecution &"nner.
13) h"t is seri"$i"tion? (Dec20107*+)
Seri"$i"tion is the !rocess of ritin# co&!$ete st"te of "" oect into out!ut stre"&, th"t stre"&c"n e fi$e or te "rr" or stre"& "ssoci"te% ith +CF* socet.
1) h"t %oes the Seri"$i"$e interf"ce %o? (Dec20107*+)
Seri"$i"$e is " t"##in# interf"ce9 it !rescries no ðo%s. *t seres to
"ssi#n the Seri"$i"$e %"t" t!e to the t"##e% c$"ss "n% to i%entif the c$"ss "s one hich the
%ee$o!erh"s %esi#ne% for !ersistence. OectOut!utStre"& seri"$ies on$ those oects hich
i&!$e&ent this interf"ce.
15) hen ou i$$ snchronie " !iece of our co%e? (Dec20107*+)
hen ou e@!ect our co%e i$$ e "ccesse% %ifferent thre"%s "n% these
thre"%s &" ch"n#e " !"rticu$"r %"t" c"usin# %"t" corru!tion.
16) h"t is %"e&on thre"% "n% hich ðo% is use% to cre"te the %"e&on thre"%?
(Dec20107*+) D"e&on thre"% is " $o !riorit thre"% hich runs inter&ittent$ in
the "c #roun% %oin# the #"r"#e co$$ection o!er"tion for the "" runti&e sste&. setD"e&on
ðo% is use% to cre"te " %"e&on thre"%.
14) h"t is the %ifference eteen ie$%in# "n% s$ee!in#? (Dec20107*+)
hen " t"s inoes its ie$%() ðo%, it returns to the re"% st"te. hen " t"s
inoes its s$ee!() ðo%, it returns to the "itin# st"te.
Department o3 Compute Science an! En7ineerin7 )a7e 30
http://www.roseindia.net/interviewquestions/corejava/thread.shtmlhttp://www.roseindia.net/interviewquestions/corejava/serialization.shtmlhttp://www.roseindia.net/interviewquestions/corejava/serialization.shtmlhttp://www.roseindia.net/interviewquestions/corejava/thread.shtmlhttp://www.roseindia.net/interviewquestions/corejava/serialization.shtml -
8/10/2019 Programming pardigms.doc
31/34
PROGRAMMING PARADIGMS
1;) h"t is c"stin#? (Dec20107*+)
+here "re to t!es of c"stin#, c"stin# eteen !ri&itie nu&eric t!es "n% c"stin# eteen
oect references. C"stin# eteen nu&eric t!es is use% to conert $"r#er "$ues, such "s %ou$e
"$ues, to s&"$$er "$ues, such "s te "$ues. C"stin# eteen oect references is use% to refer to
"n oect " co&!"ti$e c$"ss, interf"ce, or "rr" t!e reference.
1
-
8/10/2019 Programming pardigms.doc
32/34
PROGRAMMING PARADIGMS
17 10 "n% the %ef"u$t "$ue is 5. Iut if " thre"% h"e hi#her !riorit %oesnBt &e"ns th"t it i$$
e@ecute first. +he thre"% sche%u$in# %e!en%s on the OS.
2) h"t "re the %ifferent "s in hich " thre"% c"n enter into "itin# st"te? .(DEC 2012,*+)
+here "re three "s for " thre"% to enter into "itin# st"te. I inoin# its s$ee!()
ðo%, $ocin# on *FO, unsuccessfu$$ "tte&!tin# to "cPuire "n oectBs $oc, or
inoin# "n oectBs "it() ðo%.
25) o ou$% ou i&!$e&ent " thre"% !oo$? .(DEC 2012,*+)
+he +hre"%oo$ c$"ss is " #eneric i&!$e&ent"tion of " thre"%
!oo$, hich t"es the fo$$oin# in!ut Sie of the !oo$ to e constructe% "n% n"&e of the c$"ss
hich i&!$e&ents Runn"$e (hich h"s " isi$e %ef"u$t constructor) "n% constructs " thre"% !oo$
ith "ctie thre"%s th"t "re "itin# for "cti"tion. once the thre"%s h"e finishe% !rocessin# the
co&e "c "n% "it once "#"in in the !oo$.
26) h"t is " thre"% #rou!? .(DEC 2012,*+)
/ thre"% #rou! is " %"t" structureth"t contro$s the
st"te of co$$ection of thre"% "s " ho$e &"n"#e% the !"rticu$"r runti&e eniron&ent.
PART $
1. rite in %et"i$ "out &u$ti thre"% !ro#r"&&in# ith e@"&!$e.(DEC 2012,CSE)(16'"r)
+hre"%
'u$ti +hre"%
se of +hre"%
o to cre"te thre"%
+hre"% !ro!erties
+hre"% St"te
2. Descrie E@ecutors? *n %et"i$. E@ecutor *nterf"ces %efine the three e@ecutor oect t!es. Executor *nterf"ce
ExecutorService *nterf"ce
Department o3 Compute Science an! En7ineerin7 )a7e 32
http://www.javacertificate.net/core_java_iqns_12.htmhttp://www.javacertificate.net/core_java_iqns_12.htmhttp://www.javacertificate.net/core_java_iqns_12.htm -
8/10/2019 Programming pardigms.doc
33/34
PROGRAMMING PARADIGMS
ScheduledExecutorService *nterf"ce
+hre"% oo$s "re the &ost co&&on in% of e@ecutor i&!$e&ent"tion
3. E@!$"in in %et"i$ "out thre"% s"fe co$$ections.(DEC 2012,CSE)(16'"r)
Definition Snt"@
ro#r"&
E@!$"n"tions
. h"t "re interru!tin# thre"%s? E@!$"in thre"% st"tes "n% snchroni"tion.(DEC 2012,*+)
(16'"r)
+hre"% %efinitions
+hre"% st"tes
Snchroni"tion
E@"&!$e !ro#r"&
E@!$"n"tions
5. rite the $ife cc$e of " thre"%. Aie "n e@"&!$e of " -"" !ro#r"& to e@!$"in the use of
thre"% !riorities. ('" 2012 16 '"r *+)
NeRunn"$e
"itin#
+i&e% "itin#
+er&in"te%
Department o3 Compute Science an! En7ineerin7 )a7e 33
-
8/10/2019 Programming pardigms.doc
34/34
PROGRAMMING PARADIGMS
6. rite notes on &u$ti7thre"%e% !ro#r"&&in#. ('" 2012 16 '"r *+)
+hre"% %efinitions
'u$ti thre"%in#
Snt"@
ro#r"&s
E@!$"n"tions
4. E@!$"in ho to cre"te thre"%s. rite " "" !ro#r"& th"t !rints nu&ers fro& 1 to 10 $ine"fter eer 5 secon%s(DEC20107*+)
+hre"% cre"tion
+hre"% %efinitions
ro#r"&s
E@!$"n"tions