0% found this document useful (0 votes)
1 views14 pages

Java 02

The document discusses exception handling in Java, covering checked and unchecked exceptions, and the importance of managing exceptions to prevent program crashes. It includes examples of custom exception classes and the use of try-catch blocks for error handling. Additionally, it touches on threading concepts and input/output stream handling in Java.
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)
1 views14 pages

Java 02

The document discusses exception handling in Java, covering checked and unchecked exceptions, and the importance of managing exceptions to prevent program crashes. It includes examples of custom exception classes and the use of try-catch blocks for error handling. Additionally, it touches on threading concepts and input/output stream handling in Java.
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/ 14
a JAVA UNII202- Excaphion Homnelbing . | Didea berinderhond © Exception & wvwrs @ Vyh og Exesption © Wrbrot pew @IVM j»sackion Potx © Le of day Cobh gots throw “2 Trow.in exeaption hand © In but d- ona. usnayind @ checked ancl Uncheeled Exapoier 7 + Exception Am Exception tn Jouve pam sumenpetid or Hemet toon (urd, that ores dusing propo xe disrupts the mrormonl (ow of proyreorn He Uhy seocud : Trvabid User Input. G) bile rot four ® ee @ Nebusottk foto RE fen Homndbing 2 D4 tsa. mmechamisem that hulbs oabect xeypkien Hamdling amis yo Ap, an suentinne Cutors (excuptiams) 0 that trode And ALOU ‘a ea pulpal oS a Hi Why Ae ds medial = oe er (hetedl disconest @ Toprevent abrupt Aeerntinabion 0f progy~wm ® to share user puitndly ovr mtsoages. 3 To allow -bxogorrn td chontimsut Cxecwting Tohetp cuscboper debug arnd. pire tasuee wale fog T0 . # Type of Excption at 2 = 1 Use. dined. Exception Builk In Exception co Checked Exception Unchecked Exception Ls CLassNatround | _,Asucthemebec |» TOExceprer L_, ceassCost | 5.SOL Exception |, Nuon Patter L_, piteNotFounol | srvayinde * Cage ciay $s uate on 5 Prin Agéxctption oF (ets Or peaepien We ats | B08 (eheuagh 2Bed S:0'P (Vora 2bigtole to 3 trate”), sf —___ Staats mmathod: Auérh Scape prrblic phorbic Haid main (say by ¢ £2 0g) ChecleAge (16); # Colt muthad. 5 asith Anvalidl age Loto (Age Ex ctptcon ¢) i 5 3 3 Autput? Youmust vate SOP Exceprion? +e: perassop.oy Rete C04 athe. © scanned with OKEN Scanner ey Block = : FUseel to uorite ris ky amel oor pone Lode. ¥4 an Exception occurs At tron fom how ¥ Yom eur occurs , fara Skips Humoiniag ry block amet jarmnps ta 4otch . “4 ; % wtthout hee oe Spear by d “He Ris hy code Ahak may Ahea 4 Exctption 4 Catch BlouR = Used. 0 hares rhe Excepbien % OE pombaind code that cx eoutes eon block. % Mutbi ple cach Blok comb & ey NUTAY Catch 04 Nor e Abed. pote tay $ ar Risy code that rio? Exception 3 Catch £ ExceptionTypeo £ # Code that handle Exception 49 3 ry Bloch. Patong Create to Lose ps HALL WW be tn main dass be “publec class Exception$ op avd. (Sting CJ OBIE buy 8 Antas 105 Antb= O05 Nonny code ante = al b} ae eption $ Catch (AvuthemebicException )§ SOP UE Tras isam Ascithrnekic Exception”), Atta 0 hod be chide jyrremt ExCefotion _ ally § jee cosh Cexcepeierlypeo t ee eee se opiradty BLO lon moe, Otis One emainly pUbech £0 Chose filis yo” ehowy final mateo oe : rnp ents #0 bo SOP (8 Thus seri lt aban 3 ex cote)" © scanned with OKEN Scanner thew Keyword 2 Fra Keyword is txocel 0 emancially throw ones ception > Udul trate method , 7 Trx0ws only one exception > Followed by objcet of Ex ceptior Cass Lyrtax Aww hew Exceptionlype (& Custom Message”); Ex public etass Examples pe Lerol (Steing Changs) § Ant am ~ 16) “ Cage 2196 thaw new XC Eption C' Younus 18+ to Avate’?)* eC e abuse £ SOP Ebigiote to vate?) 3 Z a a AE thous Keywarch + oe Coane pee ew NN FIL used Avith muthod dictarakio, * Beclawws ore or emonwe EXCeptign, * Pallosea by Cxception Wass Mame ¥ Tngoromd, Cobhes that omnethod omy Arvow Exception a 0 AL chonas Sypehar pukuven Type method Nome () Exceplionlype L 3 oH Coda Ex public class Exampeet atabic worl puacpole() Houaws TDException ‘J Un = naw BilaRuodcr BruReades ple = naw Prkode yy tberua 5 tr aisky Cocke ple dogely, ‘4 3 poe Week Luang LIONS) bay § Heoopile ( Ds 5 Gatch [ LOEKceptione )i SOP Exception to-ndled??); S 3 4 Sd © scanned with OKEN Scanner : secked Exceptions ~ He Uncheked EXESREE Webeaun the Exception shot are Se tuajelboue abe ehucked ob Checkea. at compide by the Compile tine Ahn ; an : + Thay Ce tre cee x oo : ve pas zag risa es Birr qivtds * Ugecl eckerhal rusowr ces Ake pica zi He a Ase OAchcbw04LR Ex- T] 0 Exception ,SOLEcception, Cela Readcs file = neve Erte Readies CS geye- txt”) #echecKecL, yaad (); 4 gle hosee ds 3 pd ved (seeing L)ongat ary f pad pho, 5 catch (LOE Pe G0 (ES This om Checks one) $ Exception caught 79+ 3 ~enquenesoge?s 3 pS Output Checked excepenn Ong test Le UNO puch fe.) — Aruithemeeic Exception > NuwiParnter€ xceper. Gods public Class Exceptions pe wed (sbung LI Op > say § dnb aslo, Ark b= 20°, 5 ee ae wore = aby emda ©) S07 U4 4 pense); 3 Catch (x Arithemetic ExceprionO wumncheckeoe aes Os SOP CT tris v4 Om Exception ° 3 Ouukpatt = am uumcherked Cx.cepiion Iz. This 8 © scanned with OKEN Scanner — aS ee ¥ A Suan dn favo As 0. guuaud Probl acer ot suum dinnr and commmot be tamdllicl by pregyrorn o, aang uy Catth , : ¥ Ht tamnolbt At toverable b \ ~Cotth Lub Ex ception is Seevroble : + Comtiict plow dn.€xceprion : dling Shae (Program endons) V 7 | ey blncwatad v a2 Exception wes See Os Giada Geran ok yes td } Cn ty math Costch Block Catch bRippecL v v | Exccoute catth ; fino toch Ci exists) L Execute finally (ag prusent) Comtimuse prograrm v TLO Basics + x € WL ans ¥ Character etrtam #* Readliag § wasite u ay 4 ‘4 7H MaLbeitvwadsing $ } * Thad + Thuad dgpegele * Creating Thueadls Thad prrioruties * Gun i Thou % TALH Howat 47 chacomnising fhowatl © scanned with OKEN Scanner frbeh| Calput Struar Stxsarmm—+ Ud dato (£2 ies» c SEE font) ogi “pagan Be ame PO Conorna Hoses: Beet Octopus whoa | a PaLoInputShtars Th Recuter (Road. | C coms byes ko Character) Tawa.deto7ype) | 2) Output Gtrwarn Used An uote dada te elrstination (Like pileor | ducim ) da the dorure o4 bytes : | | > Common Uarss+ Suet ab Tnpattruam bak ust £24075 i + OuthulStrearm Baebes ~ Comuerds chanactes to byes: Input |Ouwtbud Stren wit hon lle seinen ded , oct * A ons Oe De Ont ie ae abo BR t:Stuarm Losses Character sixaam Classes ieee aoe (Used. (eee ar ee ae Guta.) al Reades setter > Classes Classes | Trputs tower Outpt (Reaol sé: (umite Single | Chases Gator Classes Chonaetes Ho Character to : ‘ Out pulsbLom (Rind dakaim (umette doloin — FrputSvuam) J ) por bytis) orn byte) | H Byte Shuarn Chassis > Useal do wack amd write oan bina Dato. (Aik, Armagus yourdio), One tO bArks) ata Lorne © scanned with OKEN Scanner ; * «in-stock L) ADant wad) | Read a diyle byte |anboh= x , 2)Ant Lab Reo i tus | inte Lo ys (ogee) b) pe Rea ae 3) Ant aattabhe Rukus mumbes Untn = ind quaitable ()} OY bytes owailable 4) pe eddaes (hoses Inputgisuem| A'n + Chose L); Exo CX Ech Inpurstream in = NU Eble Lnput Strom (pile veh”), dak bycBata = in read L); FE Reads om byte eee ins chose), Y Aucays eloseabrucoms, | Common Outbut Stream Mumb us Cfenbuyte Output) i. Mutha Nome | | Paxpose Exormph a>) see Out® sH0te (65); 2) eoyiel 38) Qube wrote Colata); D vai feush0) Qk Flush (9°, Gut chose ();, 4) vatd. close L EX Ch Outpuds eta Qu now Lely t Out umeite (65); Unites date nate (Bile tet). Gut* chose (9: a a © scanned with OKEN Scanner | Aading amd soxibtirg fils uoing Byte Slarn + i el ae J irmpout jovo.: Ca* Lic class Bytestruan§ bedurd (Sbangl) ongs) : ue povoavits Pile Trp Studi An = rd CileTnputiirstonn ( Meets : wukStrUam out’ raw Bit Out putsuarn (pie tte”), ea out Lindsey Ant data, PO Hatasin —t teach while (dake =An read () | =L)§ end fle Out: LMite (data); ” * Meal onebyte Data aba Line 4 Ly ite dota te ee. An hose 5 outclast. 7 ] Atways cLosewbuam Se0* PCBénary cli), 3 Coch ( LOE xce ptionc)$ i SOP ( Cerok 99 +e get nanenge U2) | 4 "Exception message FH ChaxocterSisuam seat %e odamol uimite Lexedete | % Ome bet Character (16 bit Unico de ) ater sire | 7 Readler Classes ~ Reads 0 single Choracker prom tapursirasan | Reacles 4 (Base Classpor ChorAnauReades i fades | all charates Petefeades (Reads Character Ory | Read tert ‘Chor aay ). | TrputSvuom) Cham actin ibe tow | Charade, | © scanned with OKEN Scanner fxs Ampot java lo } MS. pe vd, (Sburgidags tows Ip Excepuont hn, 1): EitsReader p= nao Gils Reads ("data te P Aink ch} WALL (Oh peread (9) = £98 SO-P(fchar)th); ¢ close) | 3 ad Latte claws Unutes ingle characte to output bbwam asin Bi wautls amd frvmute (Bata; BMubtithecading An Toug | drat allows Hu concvount exeeukion ef do oe mou parts Caled threeaeds) Of program AD grain (PU maage and | damprout Poyormence 4, Each thread puns indepen Pett BhONUk emurnouy | ¥ Meettipte Aaah rey eben tam Cay ThuadA — Thread B FE Thenadd > Tn Sowa ik ta Light wwe 4S 5 small Aunit of ‘proueh tak cam feten indtbemal ently om : Othe, Hreaols Lomearrintly ustth | _ l © scanned with OKEN Scanner Tat Thcadd (Nat Runreibhe) A) New Bown "A Thecad is vucled using mun Truad (J ~ Nebypt shosted + objeto bul daca mabner * DE omtoums Runnable astote amy ofses tartC) 4 Cable éx7 Theead A= hew Thread oy B) Rumnable State + * Th cead. becom ¢ paaddty to su%m. telat C) mmuthod iy Late “9k As wai. CPO. dios by Ah-*aad wcrhtdiles, : Noy Mumate inthis atate por while, Ex tatartl)y c) Rucnning state » SUM picks thera rom Runnable tocxcecute suum () methool + + Ontrone thrrad canbe ning shade pth Cate. + This As golive Exeeulion phase, Ex public uaid Aum LI ¢ Le Caumning” ): B) Bboceot | waiting | ings ALL ane pause state whinr Hn*a od Y Atmporonily inactive > Blocked await to Ke a dock on pusourer ——= "+ UseeL tn sifnch onda BOC = Uiaitting - Waiting for Oana amo thes th tad be Comp bite 4 Tfech © and unt(>} > Sle ping . REY Tempore oruly PUA s4ird Treeoad leipolth Cos) © scanned with OKEN Scanner > Theead dlocs mak mse COU sn thus estate Lt Rubwin kop nable ates coma” E+ Thead btu (4000); HF erluepirg fort second ) EL jain), W Waiting por Lt to Complt 5) Teemninated (Ocad wtate) ‘Thruad is Completed ox stopp ed * Camnat bewtarted again Enters this stake whem suum C) method. Completed 7 Moraoliy wkobped , SOP (ES Trxead Complited”?): 4h Thecad kets <— Meaning Syntax D Stork Thad is created ard > gkvet)§ PeroLoly sho wa 2 Stecp Thal Cy bud t-etup Lora); : dlr (RCT “Tn cxad. AvaUts 40s anather sun. Ao gir aignat 3) Wat watkl>: (inate ay mobo istol 4) Naw, ti eh ladanalad Bloch). eae U5 Andie apneuoniced. Hh eel apenttcoatinae | MOY (0s (nha agp eset S)Sarssbemdl) Pauisech manaably b sakes fp end 0) 6) Redasne | Ridtork auspend Tread 0, | E-resueme 0: aula percgollg Ritts theceact be sbeop 0; FF Th tead Prion dy . - xaV ee see bie Sampara, Avot f Thread , caches Should be Cx coking fiE Wher, mrt ple arth ra dsane nalbing £0 Mun * High Bacority = more them edn suun pout 5 A (Lowe) 4 Threads MIN_ PRIORITY — SlOtfautk ) Th *u0d- NORM_PRIO RITY lo CHeghuk) > Thoasl. MAX — PRIORITY, a —_ J © scanned with OKEN Scanner aX UAsiNG Gutamd Sot mtthooL Theead t = AWW Th «ead (); EL Sune @); YE Set Paianiy CMP ©: get Du onuisty (I), He Gut Butruidy * Creates Fhretad By ectem ding Aen na ble Intepace aes My Ruhna ble Crtendo Runnable £ Pubuc paicl rum ()f FOP (° Thraact is mumaing 9), j public ass Teat £ pow od (being £ Jonge) sf Th tead ty = 1QwThttad. (newly Runnable ())) tL ato) 5 J 5 4 © scanned with OKEN Scanner FW Synchsonization in {awa Whim rulkiple Hhedtidls am dsharu Comnman Pesaners (eke ge Reuabde 5 Obs ec!) am OL cot Cree Leask one mvutes » RLAR Of Chaka Coumrption . ~~ Only fre th cad tom avers 7s ota Lime tH Usea wy nchomiscal Keyan » HE dt com be used ith A) atthod San cvcomined, Muthoo Coss County, f nb LOURE <0, Ry nchrtons col Vatol dnckement B) block Synch nis col bbocR Cass Count £ Ank count = 05, eos wat cnvwam ert OF fone DYNO misc this) { ; counk++; | a |< Only ane thetacl tom coll 3 HH Useput ashim yous | Ani tam ent Oba time 3 wank 20 Lock putt muthod, © scanned with OKEN Scanner

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy