Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Java Part 2

Uploaded by

Subhankar Das
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)
25 views

Java Part 2

Uploaded by

Subhankar Das
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/ 20
25 is A Mechanigin to Exeephion handling handle nun-Hme ehneng such as — AnithmeticEnceplion i> TOEnception. “The. exception handling mechaniom penn, She Follsaing task — | @ Find She problem. (Hit the exception) | Penh Ahet an ebron has occured (Threads te @ ts exception) @ Receive he error information (Catch the exception) connective aeHions (Hondie the exception). Oo “Take » Syntar_of Exception hell | Exception objech cheatont Slalements thal Exception handle handle the excephic N Fig— Exception Hand bya Mechaniom » B ae 4 Any One-Dimensional /4-D Prepay — 7 @ Declaration Qyntans 0) °° Dalatype PnpayNomeL=new Datalype [size 4: ink arppi-ned ini Tso]; . ob, int obht > abp=nea int[3cl; op, ink Tiabry Abb=ned ini[3ely 24 a Jnitielization; O Al Compile me > int ann d+ {40,0, -10,5,20}; © Pk Ra ne | ak apbEl=ned intTs}; fon (1 = 05 1<8 7 144) t apb[i} =sc.nedIn.(); j > Tao- Dimensional [9-D Ppnoy »— eDeclaration Syntan: Dalalype AnnayNane LILI -né® Delelype Tso] [aleamnl; fa-. int MabTIL1=ne@ in} PICs, ee Thdewx oA 2 060 O14 O2 4o 44 40 20 24 22 gos i 2 0 [ee Jor on 2} 20 {4d [49 9 [20 [94 | 22 Ty} PIGS mal Tolta) Mal LSI [61 mah (4) trols} By mok[36)| wat wet BID) Mal [s3fo3 mal [oJ] a d= Memany Representation of mallZC33 |S habization: OF coile ney ink maltacs§ 52s}, f4,s.63h; ae eee —— oo Oe ink mol TIT 1= ne inl [aI[3l; ton (ico, 1X35 i+4) i j Son Gos 135344) mat [i] [4 -8e-next Inf, Mite a program -to multiply +0 satvices. (3x2), impor} Java.io ky inont Tava-wh).#y Class Madnin, Mal ALITJ=neo int csypyy: in} maloCi ey =neo ink fey [3], Mat3 =f i : ia ROCs @ intlsdcsy, sds Scanner Sc =new Scannels (Suslem.in); | void Pn) . } , | i System.oul. pninfin(* Enlen ‘elements fon mal | fon(izo; iKayi+4) - | fon ()=0; J<3jJ+4) te Mall i Lid=se-nectin(), 3 a4 System. oul-printly (Elen element fon mat 2-”); fon(izoy 1x3) 144) i Pont J=0 3 AL Compile times chah shat =" Siliguyi", > AL Run Hime- chan sipras Be Shy = Neo chal y]; on(icos i Sting Class - Fixed Length » Swing Buller Class— Variable length. g¥s 4 Declanation ard _SnsKalization— 2 AL ile Kine — Qlring obs =ped Swing (* Siliguni); Ob, GhingBufer aly = Na Swing Buf Pen ("Sigua"); > BL Ban Pues ning slay Ob, Sting Baten olny sth =senent Line ()5 « Various methods @ hengthy: Th is used to find He length of o shvng. @ Synlox ~ StwingName. lengthy # Eromple- String gk = ned ning ("Sihigari'); nf = stn. lengtbOi ll dpa a. used in Shing and Dring But fen lass ® chan Aly; Lt ig used to Pind @ Single charockeh Bom ® Specific position. of ao otning. # Synfan— “ShwingName-chabAl (Inder No.) eEkample- Sining shp =pe@ Slwieg (" Siligani); char ch= sthchahDi(1);// output t. me © ® compancTot) : J) is used +o compahe foo otnings Chanaclen by charac ler and preduce a value o, if bell, te ghningg ane identical} (Same), otherdive i} Dill Produce g value @bhich is the clifferent bebacen the D8eIt Value of -the mismatch charactes « That is Ge) ib preduces 3 values , —~| =Q . So, 2a. is i @ Syntor Chnings. Compane To CString 2): cdoda © Example~ Otaing gpiznea Sbning (saber) — Sting stpa= ne® Sdpi (aBe")i int n- ob. ‘cempareTa(sina); I Outpt: 3 32 ye - suy blue = (435, 206,235) “A Plbstnae!. Melhed and Abstroat Claes _ A methed ahich mug! be ovennide in 8 subclass ig called Abstract Methed . A, class Shel <> Maing atleas} one absinac! nelhod ‘8 ealled Abglnact Class. « Exomple— abshnach class A i Dbstaael clasy absinacl void display ) Pbsimacl Methed. System-oul print (” Hello’) ; cloas B enlends A void lisplay () Qyclem -ouh-prin} (“World — EF Thlenface = 4 An Tnlenface ts an allennative of muliple inhenitence . Maltiple Inhenitence nefeng te Cheats Ned clase Prom several base classes. Tn tava, tal, inhenilence can be achived by Means of Interface, A) Base Inlenlace->(B) Denived” Tnlenface/ elass © Syntox— inten face inlenPace name | Vahiable declaration iniatization; Method declaration, a by defaukt Here , vaniables ane Final variables. § Methads are Publie , abstract Methed, by defauft : @ Example- inderkee A L Sloot . Aiek pi-gd4; public void display¢ y, e Extending Tntenfoce~ TL nefene te iwhenil te ° Properties of a base. > ~ interface inte a child intenface. Bose Inlen face > extends E fe ehld Tolenface : + . Lirplementing Anlenfore— TL nefens to inherit and defin tle prepenties of a base interface into a child clase. Base Interface nplements hid Derived class 3t /y gyiffenen Fovmg_of Tnhenface: «le Inher tonce— g at® 5 (A) Base ‘Interface by ©) hase InlenPace etends implements (8) Denived ‘Intenfaco (8) derived olase? 8 fulitevel Tohenilance — III III DLA > (B) Pose Interface b> Base Interface extends oii) arhenface (B) Penived of A/ G derivedect A/ exlends Base of ¢ implements Boredeh ne (C) Denived Interface © ehived chess @ Malkiple “Inhenitanee — eae anne Base inier- > ® @B) Base Inlenface b> . tee extends implements © Denived Interface Derived class @ Hienan chicsl Tohenitance — AA RE a Base Interface or Base Inter fa ? Pay! 7 inden . Dehived B derived Class Tnlerface 9 WAP to how the se of maltple Tnhenitance through Tren Pace. public veid Sum " a ens] t Beaty i - : fablie void displayc, me gam); t Boronia Coens intenface B } int b= 20; class mi 1 publie shake void main (Sha | Public vad cisplay ir; Lg obf =nea cs ink 8 yess pers gloss © implements 8/6 obj-sumc;, obj. displeyo; fp hr EF thio! Kegon — a. ete Th jova, the Keytond this’ ic g befenenee vaniable that refers +e the Stannent Object. Uses/ Featunes/ Advantages : . ( ® ‘this! hefeng +e the instance vamiable oP a clay, Tf dhene is an ambiguity betaeen te inslance Variables and tHe panametepe , then the keyQond ‘this’? Solve the problem of fle Ambiguity. @ “this? Can he wsed to inveke methods om Constracten of a chags, e Example — impor Java. tok s Clase +h inl ay > 4h Cnt gy ; Ahis.a=g: Noid disployc) a System ou. Poind (*\p Value of a= 3 Classy Tyg pc static Void main(String has £1) th abj=nea tho), Obj. dig 15 ] ny ( 3p — Lit PB Super’ Keyond:—_ 2 Tn dove, th ; y “he Ke peleence Vaniable Shab nelace wt cere “the parent class object Cmethad 7 Soncth vol Ad ‘ useal Baverioge/ Reataves ot is_used to hefleng ra mediate ob), ‘immediate paken} instance Vahiable, clase gH is used to invoke . cons!huc bop, Parent class Melhed on o Example — impent Java.io.4; class A ‘Foratnucton Never ' inhenile. Ind ay,bs 7 *S alucays tes ip A Cink a) deshuustoe nt ane this. atay Mast } + Super sheold be Dee } : in Fingh Line class B extends A t BCant 4b) SUpeh (49); this .b=b; ¢ ‘ : void display Y System.oul-phin| ("Nn Value of a = “4), ' Syslem.oul-print C\n Value of b = ”+b): § ; Clase Supete public etetic void main ( String args £3) g B. obj -néd B(20)2 } obj .disploy 7 4g > ER Applet Fin applel is a Java Prognom thal. is tly) in indennel- Preapamming. I} can be tnancporles over the indennel from one to anethen and “Sing the ‘applelviewen! toa] OP MY Deb by hed Support tava like Hol Java, Netscape Na ele. Oo, APPLET v Local Pepplel Remote Apple|— ® Lecal Applet —~ Ro opplel ahich je develop in a hocal syghem and stoned in that system is Knsdn as Local Applet. © Remele Ppplel - An apple! ahich is develop ond Shoned ina Senven System @hich is conne +b the inlennel is Knoan as Remete Applet. eo Re Leeal (client) Gemgulers aa @ “7 AL patil HicyteL Sele Trnsthon cegan fle Th Vie eyele of an pple includes Vhe fyaing Soles gy eon | Tilizaionh Slate, hareyhele/ sity Qunts Qlale, | g wel Ghopped / Suspended Clale/ Block stole, dead | Destneyed State, 6 Distley stole. _Fig- Applel Life Qyele ® Boon Sale: Dn applet enters info been shale Olen ih 88 loaded ints memeny by initc) method. TL ineludes —© Selup instil value . ® Sebup Coloung, * Syntax — publia void initcy reo oe a oming Slates Bn applet entens ‘inte Pannicg ehale @hen system ally the shane) methed- Sanfex— public void short Leen a 7 id . af be @ Wile, Stele. Fa opgict ontere inte idle hy by ealligg the melhed Shop: e Syntax — public void stop ae 1 Dead Stale + An applel entebs inte dead Pale «, iL is removed Sram memory by destnoyc Meer ¢ Sonar public void cligploy () pee © Display * When the applel enlene inte the Deng { Slate, the display’ shale pebform cutput Operations” through the painty method j © Synfox— public void Paint Graphies 9) | bo, ' j e Ad: eh | » Th is sed fon internel Phos 3) TL ; } 4 @epks al client Side @il Vese e Pisedvanages : Ida | ) DI * ia, negquined ' t t i Ser ‘, | at client bneasen he oPplet. ee re ee om Fipple Progam: = \ We Need +t files to cCheafe an Apple| Poosnam — ® shtml file § © -Jova file. = = e Synbon— y hd [: | 5 “ | JOVO s = ne import Java-o@t-*; ad shea eS. import Java: applet x, § ie vo} ; « 3 Sets poblic cid pain Graphics g a eade= ... Java 2 - BMb- goo _— height = 600> $ ih Point wm .% “ ve ° (22,92) > Fie Point o Exomple- G:draiali ne (Ase,Joo, 260/208) 0% peal’ Veiqun. ie (100,400) 9 ards (260,260) Pyeng’ * GQ a draakecl(y: Used to chad o neclangle on % Square. b> FillReck Oe Used to Pi) the inner ponition of reclaagk Oh 34 wake . Compile—s tavae filename-Jova “To ooo Qyntar= dpaDecl (ayy, a * 2Byh)y a $illReck oy aany Cm)» Sawing Point ‘ (ON wh height 4 Examgle— G-ddadRecl (100,200,306, 446) g 9.FillReck (408 966,905 1400) ' (400,260) ee ‘ Z CL, soo Lhe (469,300) @ ordramReund Real .): Used to drem Wounded reclargle oh squae by FillRourd Rect): Used to Fill pounded heclangle om squate. « Syntax Anam Round Real (x,y,,h, aah); Quy) sTep-leff eomnen | LlRoundReck(xy,hadab), CBN Width | Height | (atd,ah)> Pirale of @idth |e Example - Anad Round Rech( 10a, 400,200,200,40,46), ond HOGM | Fill Round Reck (400, 460,268,200, 46,46), (100/268) 94 | CZ ie | Loo | * (300,300) 6 ab.dram Polygon ¢): Used +o dna o polygon(any ‘hage contains ~s I>£NPolygoncy: Used to Bil a polygon: ‘ . + a> Array of potols about x axis # Syphon drow? lagen (90) yo Prray of Pointy aboul y ani HillPolygon (% yn); N-> Number of teints. * Example int xT 1=} 900,300, 400,200} 5 ‘int YyTI =| 400, 300, 36% 400} 5 GrdbacPolygon(e9 44) , Quill Polygon (4-4) j (oe, 368) {> (360, 369) (400,302) —————_—- @o dnaadvalt): Used fo draw a cincle ob elips. by FilOvalo: Used to Fill a cinele on clips, *Syntan= racoval (9/03 (yy) Top-tefl Cennen SiO val (%/,@yh)5 (Dh)-> Width § Helgi Example - §: draw Oval (100,400 , 268,200) ; FiO val (400, 400,200 , 200)} Use, 498) 200 i 260 Oe (300,300) © DdnowAnet): Used be naw an aro. BAU Arc: Used to Fill an ane. CWY)—> Top -lef 5 Cobneb @H>di Hh Y height (aa an Set angie ¥ @ Example - G-dnam Ane (160, 400, 260,208, 0,90) § meee angle g-fill Arc(dse, 100, 200,260, 0,9 °); 40 90° @ Syntox— dha Ane (x,9,0,h, a4yo3)s Fi Ane Coy, Oh, a4)02)5 340° ° FOr Saabs aioe. dhapAreV) Uda. ; eth oto @ Ghai Sningt):_ Used +o prinl a aining ob ated .” “Sunken dren ("tng 2.5);—“alnag™“o eek to be pt ' CK) > Top le? Cotsned © Enample- gudnao ning Hello" Jo0,40; ¢ 100, 400) ‘Hello | a : = - 35 GseiCelehOe Wsed +o select a PabHeulate colon o Synlan= 6) Using Seloe Name + selColon (Calon. colon name) ; fg gclCelon (Colors. blue) ; ® Using, 248 value Sel lob (nee Color (hn val, 3 val b vol); RQ, B= O-2H5S Tela) Colour = 956" Fac sel Color (neo Colon (0,255,0)) ; +Some Galoury and Heim RGB valac: . Red = (255 ,0,0) Gineen= (0,268,0) | Blue -Co/0,255) Black = (0, 0/2) | Ghile= C255 255458) Yellows (255,255, 0) Ghay = (199/498, 128) Svange = (ass, 46579) Suy blue = (435, 206,235)

You might also like