0% found this document useful (0 votes)
15 views44 pages

OOP unit5 Notes

Oop(Object Oriented programming)notes In this document we will learn about exception handling using try catch and finnally block also we will use throw and throws for throwing exception manually

Uploaded by

fopik69411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views44 pages

OOP unit5 Notes

Oop(Object Oriented programming)notes In this document we will learn about exception handling using try catch and finnally block also we will use throw and throws for throwing exception manually

Uploaded by

fopik69411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 44
Jayawant Shikshan Prasarak Mandal’s ss JSPM’s Group of Institute Name of Institute Varified & all the entries found correct Jr Superviso’s Name, Signature & Date Rol No. (In Figures) Centre Roll No. (In Words) Day & Date Examination ‘Subject Section Course Paper No,;___________ Medium of Answer Main Ans. Book + No, Of Suppliments: Tota Quest : no | af 2] a | a] s |e] 7] a fo | 10 | to |sionor Examine Marks Obiaines Use of coloured pencil or inks strictly prohibited except in case of diagrams and sketches ( Winte on both sides and start writing on this page. ) aint YO p UU I c a ENpsem VOLT EMT = Unrr -May-June 2023 Supervisoral Name iaiiesisaeinsigceniseenaseceesee Pg./Suppl.No: Signature & Date ——_| Roit No. Sook [Dato: ela Set Sle) Define « extephont: Gyre? eer ite dypes "| aaa | —_ Discuss excep bien hanolling methaniswa—tin detail - a | 1 | ception» Definition =~ *) Null Point Exception | Coused wh en flempt to access object with a null _yeference is mace _liwJ_TO Exception —vhen— ‘llegolilp_or—olpo| © Peratin nis per Lo r _-med_, then this ex oo yaLsed. o iw) cEndlex Out of Bounds Ex cephio on a ne Covsed when an indey gels out i Been. “Loy Array Inder Olof founds Ene xeep hon : sade |_| Array inden when! gels. Oul of pauncl,this __| exception will be caused,eee] Supervisor's Name LA PalSuppiNo: | Signature & Date — Sex |Date’ Roll No. _|av9] Array Stove Excephton | Cawred when Wwrong—o J} era 7 ara 3 pjed is shore in vii) Empty Steck Pxceghign q —| | An attempt “te _pop element fx0 ro empty shook is made_then this exception occurs. 4 wi Nui berformatixcephi eeeereseeeaae When we try +6 convert ia volo string to ae Dumber thi 0% ousect : - To sho. general runh' error thi: excephr Ln ust pe Cut cl. ci Lx) Casslost Exception ite ; at Tthis_type—exceph'on _Indreates thet tries. to cost obysect to type which —ebyed be. cask fee i | Also, there are 2 main types of excep? vinta : : i fawkes te ® © Checked Excep hon! } | hes _ : hi Gea need to be handled expltel ty a: phe fete tse” either by using Moor cb : ‘ er by using throws , These a¢ D ‘i clay soverdang.Excepher E — +e *lendcg £9 TOlrcea from phionRoll No. Py /Supph te | Exception Exception excep hon El yy>cabeh % fry f block vred. *® eabch= for * Throw” | used to * Finally - rl Sped les the code that must be execu. Ucthed even | not occur: s ave extendend. Irom — java lang .kuntime~ class. ‘ ey. Ay vay Index 0 ul Ol Rounol: hondhive fundamentals: handling in java i& clone *y blocks» : eae of source Code that is lo be monite the catch bloc handles the Specdf'c type. of exception along with try block | cath Ixy block, there ext as “ccikch bbooh sv though excephon mayer may Specily exception trom program cade These ee of erceplrons need not be handled exphici fly. the IVI handles these hyper of exceplions . these creeph onsSupervisor's Name _—__—__— Signature & Date Roll No. Pg./Suppl.No' Date: throws” ava | te es ee at _must be —e-necutedi_ ee a or may nod | tb pecifies exception jniad_con be po by pashculey paethoods 2 Mech cai s ba ty block (Tee [Exception -cowsing| ee eeapacie| Statement eu e eel throw, : | excepHop |” | by ect catch block ee [Kxcepbion Excephion | —— > hanelling Pence eee | c tote pm ents ‘ ee eee ey tos Cause —o : extephion aye enclosed within hey bl GCI the catch__block is responsible fer h {| of ber try block. ra excephons —thrown—by try block. 2 As soon as excep ton ik decured it 1s. handled by catch block - the catch bloct 1s added _immecliuterySupervisor's Name 3%, |Pa-/Suppl.No: Signature & Date = [Date Roll No. —OS_| 5) what is _genexte prog rarami 1g 2 Discuss any — met four metho ols of Arraylist class tv Nn Phe yntox: C34 ¥ An Gener! A rh is a method fe reating general_model fn_whitch generic meHrodds and generic _simgle method & single loss for per formiry thy clesived tagie- G (ce prog i iS prog ranaming poracly afeky four method fF frvaylist class are follows * i) Ladd Cee) aan ‘tacos th. speadfied element to the _end of the Inst. : a _Syrtox + boolean add _Ce_e) | Pelurns frue if the element |addeds i Shee ess fullyPg./Suppl.No: eo ignature & Date —_________—_— Sst |Date: oll No. it)_get Crnt_tnde it—“retrieves the index inthe List: is yakow 1 Eg get Cnt _indexd} | yeturn the value f element at th Rec +Ffieo inde element at the sp eu fied. Jit) remove Uni index) lit vemoved the element at the speciGred _ | index jn the Isst. yntas : E emove Cini tnder). Ti shifts any subsequent elements fo the -cleft_s Returns the element that wos .removes fropm._the list iy) size O_ : returns the number of elements fn. te Ist aCe ee . e_size Of th Iist ). this method ts — Ube d_ 2d fox—alet oO. of elements retexmining the he prevent Pathe Biren Erste se a aa aNSupervisor's Name 7 Signature & Date 7 Roll No ae ——Class_arraylist a a 7 = i Tr Ublc skate void main ( Strin 42 args lJ i —faroylist the retolmAil() method ean be used to pete: mo _ the sntersecHon Fico ets . | as boolean refainAll Ceollechion ¢)Su ° pervisor’s Name —_——— Po Supine: Signature & Date Roll No. Soak [pate ————}_| Prog rem '* carey clas “maths a | | ___ Puli cokabe void main Cates ing Sn 1 new Hash Set et thyow new Fxcephon name EraSignature & Date Roll No, Pg /Suppl.No Supervisor's Name SESE EEE eee EEE Date: |} Ay gyi. Supervisor's Name Zs Pg./Suppl.No Signature & Date ee Seah (Date: Roll No. Qs._}by Write 6 genewic method to count eee ee Hef ele ments ino collechion that havea Specific a fike oleh. nleg ers, _ prime _pumbers and palindrome _ [4] Senpeck axa Ampork java: utils List Impack yore. UH! Funchon . precticame 4 PS blic class Element Counter § public static _ int count Clements bith Property Clist elements, Prearare Leap Check) 4 P a ‘wk Couns 0» foc Ctuementy elements) ¥ 1& (propery check. tat Celemenr)) ¥ CounE+ts fe | purlic syanc beolean IsPrime Cint my IFCN cumbers = Usp o & Cvj22) 181 lol, 1811 OY sT3 {ok odd coud} = Count Etemere ith Rope Crumb, leash snk pabind tome Count = |_| count. ements falth fraperb fu wert Bema Gantt pln __| ink prime Count = count Elemen|s -ovith Property. Cousens Blement Countee!! | Lsprine)5 system ou pcisk InCedd count) 5 fig Secs eeeeeeeceeesee a Lsfie our: pciotln Corie count) * | ong roy Out peteic Calla tame cunt); —§ cane i ete settee re te Perensaoa Supervisor's Name ———____—________— PgSuppl.No: | Signature & Date S creates a list —t st —tn.—winteh eollertinn elers ents are + iGocieid ee eres es | frveyList Cont i Geectbes tg ine ae by specified capacity ci. —}‘Supervisor's Name Signature & Date Roll No, re __Li'm, pova ubil. * 5 7 lL elass BrraytistProy Pope | | public static void moin (String arg sli) t [| System out. printtn (" Program for pvvay List "J, HM crveahion of . array liste | (5 Ayraylist obj new ArroyliskO 4 System: out. printin Ci Tnsert elements"); obj. add Cod} nee i } | obj-add (20); isa elem ents ared System-out eprint din CThe_arvoy loth je _ (Inserting some elements. _ Systems out: printthn ay in arty in between")y | : —abj._adad (949i eee System. out prinitn C" array elemsenle aves 24 ; 2 eS ta bj y iSupervisor's Name Pg Suppl.No: Signature & Date a Roll No. : —|Sya! peel oul. prink Qn eee __elem ents L etek! f j | Eersevtir or bem-ent§— in —erely | | a t output? Insert element | the ay elements are: [1u,20, 20, bo, So] T serting ome elements in ar cuy in betwee . — [the oraay elements are Lia door bents, So] | Removing elements from the array — —|—|-The_array elem ents are i [lo So, 40,45. 5. Pa|b pubiic clags Mantis Nua her Supervisor’s Name L5 Se Pg.JSuppl.No Roll No. — = |——__=— - : b)i Wribe a java program lo accep) and — cl'splay the _monkh number. Throw | number format _excephion — iL_im prop.ex—month | number ts entered. — C9) |—_The prog raya is _ ab follows 2 ________— || import java ubils} ie | pubic sslahie void main (Airing argo lV) l © Scanner SC 2 new Scanner (System ta); System.oul-prinitr_C" enter _a—mcnth putea h ty fant) 2 fy dry t String Input = _sC._ne thine Cs int month Number Inbeger_ Par 2 Tap Ling [pk tanith Number ) a rik |Date: Signature & Date —________——_ x Roll No. a.s_|el Explain collech’on. classes —1n- ele oi), t | : ean ee a Ans. 1 Collect on classes pravtole ‘the _i'vmn Plier ey ta _of_ol/Fferent collection tnierfoees | [_coneWor J = ' I ala ao TaseeeT oe ‘ [sorted get. | terator| lta if al [eevted maaal im LE Trerotor| Fig. differ ent callecWton saterfares | Various methods are Supp orted by. collector Haber foes Soh aye |—-): boolean add Cobpect ab) }——objetts are added _ubting this ] Li) boolean add All Clolech*en collechton) Hl ehhire content of Lhe amothey,_ One collech\on a ain_-b eada Supervisor's Name Signature & Date Roll No, Teper ——— [Pa iSppten ~ [Pate Wverd cleay (J ; === ~—MBed to —Cleay There ame —SOme of 4 co Ile chow inher face. j—|-Com mon ex ce pP-Rons i |The methods a collechon nter face throw two ON__for Unsupported Qperahion fxeephi MLeg ot Upporting eperahion, 4 Class Cost Br wc! ceptron when one obsect is . : og noe erpatible with other obsSupervisor's Name Signature & Date Lie Pg /Suppl.No = |Date: Ce\ | Roll No. Ge. || What ts generte method 2 explatn wih bh - Suitable example. et : Ans. Generic methad allows a _progrdm mer =a write « generalised method for tht methods of different olaha hypes+ priat ane Atte Op integer , Float & ehara ter typ elem. ab =o then oof allows bo use sare funch'o» — Name foe thi instead GF tw liking Fhe e cliffen nti fuoch'on $ a ey. | aay pove tory ache Jovo. ul #s peeing Public Sakic at se a — for Catiso 51-Supervisor's Name ys Signature & Date _____-—_____ [Po (Suppl to Roll No, LL jot Q=\e,b 2-15 e a : bzalo 's Careh CArithmeHe ExeepHoo e) - £ block «Ve ): Sytkm. eur printin ("za Catch bleek OU 3 iss : fay | te Cb! =-1) ( Hthowl Occurence : * Final Jock extntes aaithoul occur _| System uk pintl ae of _exception'!) 5 a, ewan vourpriniin ('Fineky— block € 2. = oa sere of excephiont) , a ad | a ] : —_——— ee eoceeSupervisor. Name sisuiacuanuaneeaedenseme Pg./Suppl.No: ——————————— Dat OO ee ee Roll No. Ou ee ea ee adit feray | Tndex Out 0f Bounds £ ———— Freep hon ff Null _ Pointer Exception with +h Prd grown: ea Ans Progr m_for Array Tradex Out Of Bound Ex cep tion class Exception Prog - fatie void fun Cint af) throws Areay Dac a Out Of Bounds Excephon eo) g : int C3 fey cea lef afal; 2 Cakeh (eve fl Out OF Bonnelp Exe ephion J t =—tystem out prin Jo" caught exception *s tawelitd fader"); | Oulpul! Caughi exceph'on s+ mnvalid tndex 3 a fee een se Funla);ee Jo hanclle_Nulleointe réxcephon _class —nullpointe + ——_—__— tabte volta nacin CS tr ing args) bry ¢ int _Lenghh = sty. length () } tch (Null PointerExcephion —e) | i Jystem. out printin( “Caught NullPoinker Eecey -hont object reference is null.")|sSig Roll Supervisor's Name Pg./Suppl.o nature & Date Z ne Setar Date: May- Tune 2024 Fe! Can! we throw an excep hon manually 2? Te yes! Jwhfy your -angwer. cai }—_| Yes, we cam throw cn — een explicitly | om manually using jhrow Acey word hin java When an _excephonal condition ts detected youcan use _thyew to ‘gnal_the Gccurun =¢e yf an eyvor Gf transfer control to the nearest © p-bion handler, __ You can throw beth ¢thecked of “un theciceo! exception s Laing throw key wor cle Synto : throw new excephicm-name (J); g. cla Excephienthrow | £ a | static votd” fun Cinto—, int bd ? bie tf | et as by | tint ae5s ive el ee ATT ATTOES ST : TTT TTT [se (pe eo) threw new 4 AsithmebreL xceeon » Cine. -by2ne' )y 242 | public static Voie yacin CSlitog angs £3) fun Cayo); a[; noel Pg/Suppl.No: | ‘Supervisor's Name $$ | Signature & Date —___—_$____ Sara | Date: Roll No. 2 ————— ' ie programming Discuss -|b)| What is Generic prog ae oo | four metho ds—of Link edlist : Syntax. — = __—— —_ _ta\) Be . ‘ ae gy Fn wn} Le vamming is 1 prog vr Yiey | —|-paro ges phat alleis—Funchimna-Lmethe da. fo be used with any cata types a |_| 7+ caked use generic i Generic is 0 mechanism for creahing « enecal model dn whith gtnente methods _ nd ginerite classes enable us +o clby a_single metodo _d class for per £0.x ania, the __desiyed tonk+ Linkedlisst is a collechon of nodW jn which nod. ! : Ha Fret ols four methods used in Linked] ist class are op follows * | |i) acta CE element J ' = }—}— Syntax: adds the speci Fred elem ent ko the end! of the Ist « is baa Wnkedlistiadd Cé element) 5—Supervisor's Name Signature & Date Roll No. Pg./Suppl.No: Date: ‘add fiest CE element) en |} Pacis ho spedfied element at. tat beginning lof the jist. : Syntax * i iit a E_ removefirst C)y -hw) get (Cini tad ) Rebieve the element at the speti fred jdael © fin the Ist. us Syotaxt : E get Cit tnder )sSupervisor's Name Signature & Date Roll No, |Pg./Suppl.No: Date: —|_hivakedditst String) I public stobie vated main (String crgol1) be new LinkedlpstzyC)s t———l'st. dad C" p Ist. " on anally Wsts edd (" Cheyry"); ao Sytem cout.prindin Chiat); Aist addfirst ("Che y "tomate “)} System out printin ( Dist): Systema vaws Printtn CA) st ye veFirst(y)s SY Stem. out. priotin (J) st); yrterm euake rint tn Chish get (2d) 4 - 4 \ co Output’ Enpple, Banana, Chery Leherry tomat 0. Apple, Banana i‘ Pe Heple, Banana, Cherry } Eee eee —___[ cherry]Supervisor's Name Signature & Date Roll No. Pg. /Suppl.N Date: a ety ts eto tad 8 Sees a cont be. Hext—Lengbh—ob nati O)|_Differentiofe between ArrayList class ane —|an array « Ex plain follows ny—metho oly ft | Arreuybist class. paneeLG| the differ ence ener A vals t cleat and Aira Cc Banat irevised once if can be pre constructed. taf | ‘ oe heapire- . Te iss dyngirnics a _T}_can_erther be singh oly single ci mengion }—-ty-climensional oy | ral [Tneaugh Tangih_Kaynora, | Pheaugn-ahecaiactin length of array cam be | method it's

You might also like