0% found this document useful (0 votes)
0 views34 pages

Java Unit 01&02

The document discusses various programming concepts in Java, including polymorphism, method overloading, and access specifiers. It explains the differences between compile-time and run-time polymorphism, as well as the roles of constructors and garbage collection in memory management. Additionally, it provides examples and definitions related to Java programming, emphasizing the importance of object-oriented principles.

Uploaded by

bangari355
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)
0 views34 pages

Java Unit 01&02

The document discusses various programming concepts in Java, including polymorphism, method overloading, and access specifiers. It explains the differences between compile-time and run-time polymorphism, as well as the roles of constructors and garbage collection in memory management. Additionally, it provides examples and definitions related to Java programming, emphasizing the importance of object-oriented principles.

Uploaded by

bangari355
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/ 34
Oops “Hewigh Tava yo” 2 raatsquestonfansnerei~ \. thal fe ~tdloy of Tava) Save wat developed by Tames Godieg Mie chefcbam an Pabicty ASeg nas ok Sin Hero Bice The. ret wat ‘Called Sreentell boy Tames Gosling A alee Gl was Called Oak | af¥inwarde $+ was Yenamed os Taal 2 Define polaerouphien) Femerpim & demed Rom 9. aveek word cord ph “The word " menne rary znd! morphe ‘means fan. f Poly mexphiem te Khowrloalled at rang fore. This = Concept vy ulich MEndle alin can be done % ” Bielerent tongs! i THM atiated To ope A) Gonile Tne tiem \) (method eeslindg) Ron Time Polymorphism tMathod overtidng). & DRre Tipe Cashing) whew one type of dita “s -afimed 40 -itther fue oF Yoiable ‘an automatic “tte Convention Bi} Late jleee, Sk Rlouws 9 Conditions | 2 Types mush oe Compatible , 2 Dedtinalion type de Langer then eovice type, 4: Define Gpobaqe Collection 9 Fe Cle a poprerme Sevesponthle-tir bath allocation and derllocation of alfects Cmerony')- But, Tawa, can be done sulorraltealy $0 that Mt maker Java Memon} — elficienk> hoz qeige Colleckor vemover vnvted algects Bom memord | which dees aubornaticnlly by somal 5: Dene Tahetbance? euahng oY, Senin wthe properties oF chs. dane by wtthe Doel og ital ge ch cat | 5 Then “TaheSbenian! fe. adtived 4 Bed tad? 4 Keawoord 6: White about the loreal and Continue elebemente vith an excample) pion Se oe Rreabi- Th te ured ~b brea’ iit riddle of he Loop when break dhalement % entoontered, exeaution of he Conveat- Loops “oomediately skops oe Re ee exeaution oft Ghekemortt -afker Loop : : Break! Keyword used « + Ep dace FE jcample olp: te} {22 perme) ot 5 txy Sat % SoS Dred Adered> for (j=0; 410,144) ‘I * soph (Drea? elalenert of break; . 3 yt 3 Continver M8Ke s broal? dae “he! “Canaus ako _ Skips she remit Stalements of whe Loop Ex.- chase Example’ olp:- . ! Pavey tea ee iy ey Le St = ieee cet “toy Pr Chay Pe =t0/444) we te Gees) oh Fl ee fe ee a a 4 ~Sopln (vf va). V=10 pis amas } question answers \ Deke tEnenp sulation ? Enenpalatn %edeFined a& the wrapfg oy Corel under a Sade vik Tks the medeaiten tot binds Code agate and ovaiipulales data” ple Nevinbles ave Waen fom Sther clnce vg IpBale! Kequond: ap Tk \e the Combiaalion of “diate Wh ng Beg Faye Exi- dase Area 2. nk lena, Sint breadth: fea (int length Dank brett) “ie. length = lourth: this. breadth= breadth: prblie vad get real) Gnt-n= Lengts Horeadth, Basler. out> phntty Caren: " a): th chase aomple. “psy t Te 5 dre recloute new thew (95183 “teelawale, qe Neat); t a > Delne cope and Lime ofa VaSabley Lope ~ af a Veale oy Diet deffaes hotw “Ra Noel Progiese “he Yon wwhelhor Sn “ania “8¥ Sn gfrsl. Xeope ok a aSable. chat vat open Coty louse of, mathed -and ends stk cloeed Cony bue of Coneapondad Bloct}. ; EN- hac Example \ Psvm q Anka =to So. pla Gy); ae (n==w0) 7 i Set b= Doxa! S-opln te); bebxto. Soplnfay: a | Litimer- “This cletines ho tong a Yewatle Si ens deg | the execution af pry : { ra = Ex clas’ Deno ty evml) 5 . antr= = . Plivele St benslh Vroudth; Drea Chat Length at bend) qt f\ien C pokccled Sint n= length x breadth A lacie ek Sonal 4 t chase Nemo aan 4 y Aiea ae neid Henle) s)-! angel real): soars $ * DesPho type Conver$on4 : When one te ce daly Se wath “type of Natale {e called supe j casther Ganversion. i we have hoo Convendione 1 |. wide any 5 New S Qo \ widening Conversiony~ Dedlinallon ‘We % bene bs pe TEx Convercion Rom ‘le Tile nt byte bat). shnk = Lewo, Saki =07 Fobysy 2 Navn Converclont= Destinaltsi type 4a anna cri to Wd Lge NE daly Wie tan wee pom coasting: Sate Exi- Loyte b=105 Short ¢=Lytoo; Sn =O) Yebxey lost 7 Exi- class Demo L ‘ peyeml ) 2 layte b= 266) 1 fat Weer leat = acg.03 toa teyleie soyle CUEWSG S En ih A 7 bello h VOX ect peat): [ io. duit Whe Use of Ute) aeferrence? | WS? Ss used te wer current chess Sntlente Votabbe ~ Gnveke Cawent chas mdted. _ Sayete Cement dass Gathidy 2 passed —ay oath agrorment Soe method cally contkr:cloy call. ~ dom the Cuwent class Sukece Bun mated. What % Conshuelor? Exylsin “ypes of Conthedlers vsad Sn Tava 4 een mes Th Tan, = Conilnder 9 a-Vlec cb codes didlos tre methods + “Rule =) Candhnaboe. tamale be jeame “ar hs Chus name. OA Conkrcley muct have. ng expat * Types \ befault Gonstrcker . | . Paramelefixed Consheclor- 1. Default — when Gb doeenst have a ; 4 prancky 2panamdenred — has speile fo-of Promelor. fo marke gvestions}anuvers . Expldin Ratores oft Oop engages Seatures of Javan \: imple Ge tbyect—orented tt Danamic Z D Seevre Th Multithiend 2+ gorlnile B: Ardtlecial -Aleutra| 4: Thtewpreled 1 AighperBninane 5 Robeat 10. DiskSbuked : 2 Eglde biel about ai chase sa: Diced Nie inalbods 4 in atBng chess uth example 9», cing 4 tsa ee of dharaclers SL can be , defred & Dermye \ i Bn : Where} Q. ] vfmg ‘neve! Regent \ veg airy Uheral ++ fas re wy Wheral %e "orened 4 vfng: doulle” quoted |: PAP ad Ey se Se “ice a Sra" Trew! cyuned Tey onsale shy Neck o8eg \new! Keqword ie . Ex sking ae natn Marme!) F . a. Vy Enq" yrowdes many, use] oan Methods t- Yau. kang. Sting pow 1 eho ty perm Operations. "Ose charatCinbSndey) — rebieis char value of yk, clar Index, a nt lena) ~ -rekvens length of akg a Sing aslostg Cok beffnstaden)' ~~ selume Subset ng 4 shg cubet ng (ut end Tider) — veby S Aedean He hedge 9 i896 ig conpfy 6. Sng Coneet (ng a Conestlenles jhe spelled | 1 Slalfe Bog Seas ivy = Th doce dec Cue , TE Compares another | aifing / 7 Tebyms, eee) of elf m8 ender ‘ute | b ah Folowerease Ly | w sting touppercase) — Aebuma py css, Bae B wile abouk Condilional dalemanlsye + c Onditional Skaleicnl’ ave wed ie rps: Hew om exeastion ‘wth Cordibione Apa | ceedion and Dede vl “4 Pelee) Nlesked ah; a ete 2. Loafing elabemers | 4 ¢! Br, while, do -uattle a vf R Brweing elulemenls A Brea, Conlinue, Rolo! \ galeclion & Neesion roto ‘ Prt cus Yvwwgle set Demo : pevm C3) psvm C9) ° } mera Bak ot {eCard) oy Sulla) £0pln(" positive") ate | SophC gun!) « 4 Cate Wt Sop Cram) eke bre ak, L = Care oy Lojhat! ean! Soph Cnegative!) reat, 4 4 | hae dh Airgeds = | pasloooec ns ee Wi om aw dooFing ahalementey- Exo dass mE pample class “antleDemo : L psvm C) b Dsymc)- acl; Frrtintic theessiny) as ny Oe “sople C3); 3 433 at ’ + Beweltg alolemati Ex class Grarea \ d if evm L . \ola > ‘ soplo Ci): SF Uiz=s) > soplltrentsstalement') : brent, al t : i G-=y) Sopa" cantiove clelenent’) Coninvey » y34 4 wile about the Console §lp and op uth an xml Wke all ther + Need Syplem.4n (Ghandard Soput> deRee) Septem oul: (handard “ouput: desies) ae er (handed Exo cae * Gye tn aN | lp ag “pod yea Supports alphip sheams 4 wlile ul demiout and Sten err Al) gives ele ob le rotor, ‘oy nedeclng eros. chwe vse Scanner ase etl ava. ull got Exi- “import 9 Favta. uli! scanners v public chase Scanner Test i pevml a t Sat My doutle m3 Shing ak, sha; ‘Seanney Sy = new oo Boete systems: So); Sony CH Exley tnbeger Value"): Wet nett TAtl 9; Sop (¥ telex Heating point nomseat) No = Sa neak Doublecy, 2 Sopln c Enter aby, a) cis “ 3 aS se: whe about all shore to Tava. Sth Examde ——rlas robes <—— a fo. What 4s method overloading) Define too mabeds. Uset have Same tame but different perameler Me Dene vo methods 9n a cbeee that have Identical method names avd -pacamder pobile uSth differert yelum yalve - ——* clas voles ame == r merane” any "mand t MOP Mien! FFB Rilynosstieo spay’ “o , c can achieve yolyroorplaiens Sah \ a means "forms" - ", ling a Leage \ Method eee | Compile Time | skalic Polyaerp bic Skatic Binding ‘ Same methed name but difference aw Wreix Parameler Viel corttrin dhe came chars Vo cred Methed overloading. Which method bas by cxecube Re decided by “the Tava, Compiler . Hence lvig a Compilation eee Nene ib te Known ae Compile Vine polyrnorphien, Example PrOq vam, chased a Gat = Fat v) velour ath: add Gel =, tent ) veburn AA, x Chace p i 7 Vim hag anal) 2 A A ob =rew AC): ob: add (10, 20); ob: add (U2); } f Method overiding| RunTime| Dynamic mathod dispabch :~ sha child clas fe ee Same method ne frente class Sb Ae Khown ae Method ovemidin he oe See Safar bn parent class and musk Wave Same parameter Wek wall ty’ clacced Should be Sr ThheSkance. - Bic 8s also Wnown as Ron Time Polymorphiens where which method is ty be execled te doaded Example pogqram:— Class Ban8 at Ror lL) vebum % } Chase get ertends Gan ME ROLL) elu 25 Bank q Claes FECT exter fet Ror ¢) 4 velum =) 3 } class: union extends Bent Sat Ror () t acto 6: 3 } Chass oA public static veid man L 5 \ Bank 0, =newRanh Ws S81 Or = New opt ( ): Teter 03> New Ielcr Oy: BARDS {) vurfan O04 = Hew ynion Oy 1 ROE CD: 02 Ror CDs bz. Ror C jy 04 RoE LY Ons “hevugh Tovn “udl-oo” 2ovarks}Qoestiosnnere L wale about- objeat ches Weck clase In Java % ae op most chase sero all “he classes Sn Jaw culled as 'guperdus! AN Ake chasse So Tava are deSved Gam Subclasses Babsir base chase 2 Object clase. a DeRne Abehad clase 9 wtle uth =n Example) Aiedion dares, “Wiig “he Srplementation ad shock Aion tothe veer... we -adgexe He ude : Kenn . labeteaidt Aedaie which dedared sag calctenst’ Ye. Khoon “ae! aloskeact clas . wae Exi- abseacl chose Bank rene Sot Rol (9 lace cat extents Bal ot Por) ~elom(a) i chase ) emo a Pevent t ir bull a 4 | | sal-S=new s6lC); | & Rortyy 2 Deve Trier Cbnsceee A class thal ts declawed Srfde andher class % called. _ ines clase « (0Ren used -ty crake helper classes). he. Ta Taner Claseat’ also. a Ay create ‘Wested dake Shodures. : 4 Deine mathed oat wk 7 ‘yas icin +4 mathod Srertitng me lem ent Tha dtd dace %e biisQne Quniee* o-wabk a! reat ches sthen St 95 called - (Malhod Over8di The Matod ovterbdieg Xe aleo Chowne patie oie En- Chase Ban} i | | | | | 1 i I | | | j | 4 | { ; | Sot Ror C) I | ! ey class 8) orkends Bank ‘ ; Sint Rr), eg web g, chars A, i psym ct) } Rawk ob}t = new Bank (); S68! objr= New SBI D; ofl Rol C35 bya, RL; } 5: wile Crag Taportg pboge). “Te allection of classes tatenfaces. & called race + We Can creale ovr own foekeges % lige ir / "pashage’ Keyoord: . er Syntax “padage wane of “the “pos wt ar lk pacing vig Vopr Reymond Syptenin Senport- packagenames. & DeRne Curssperriy Re ciasspaty Ye a Wanable used by stent locale and load the clase flee yi Th ddincs the path Het ty Gad vter—defhned classe which, ae nok erlended - sti Sinankg avec tons Anawers 14et- “Wea A SGheStances %y ‘Town 9 Tabettane a enechliay An which one object sca biy ail The propentler of et lune. “Ta chort ~acqiines pooped al one clue ty « atten okey at “oatend ? Kepoend Che Ry “Fes ohh Sov ~Leuel Tohetlance - 2. Mall: Level SPaheBlance PA fey fey cy 2 Mewachieat Senge pa. | 4: ae Take Standel ar ei | 5 Hy iba TinheFladee+ 2. Whe: Bral chassey, ee Hh an > excanpley Te Ral Reatard 4q in Tova Se vced iy. seated the, vier, cit can be applied b Yeates, fai cand aod ' BR cheatcoce: FP wt ra 74 clase au » & Crmnot ontend aE Exi- Ral clase Bie y yo Noid von C9: -PSum C9 af ral, ” class Honda enthends he Hlondy oJ) = New Mon dat Honda nl; . 1 : i alp.- Compile Time Exor oy Proll mathods.— TE Yoo make ang mathod as inal, You cannot OVverade jt. | En- chao ile | seve cts th Boal Wéid ‘aon (9. fey) wee A 4 chase Honda axtends Bike 7 / a shinies | » Honda lft = newHonda (Do) é Honda. von ts 3 ; olp:— Compile Wine Eroy. Le D eRe -Abehact- clauses =— Imarle— Qroy 4 DiBrenee bho “TrteeRices Ve fikideact-clay * : _gosrnetion!- “ding the Amplemertation and showiog} atep fing Kocchionrlity “tp “the User. lye can cacieve. “We vsing abehack clases Cieqsord) p dase Witch deckared ac -abshrac Is Shown -ac aabeivack dae Ik can have ~abshacd and not | aushieck methods. 1 ah Can malo Wave Constrctore, AN yon-raleshraack- methods wa muck Le elattc Gaal. fhmelhod wich Xe declared as alastrack Sill not have Jaaplementation & it uf be cline Im ctl desses. Bx payramt— abstvack clase Raml§ Bs ieenlo teed bass abshcack Sut Ror) ; j dace ch} ewhends Rank Sak ROELI reborn (B) 5 Chass Veo ealends Bani % wk Ror ( ) ae io: class Denno \ os ! puldic halve vid main (sag argst a) 4 SH f= new seit): & RoI (; vto w= nev veo); UROIC); 5 J Wale a Javea Program to erenale “tn ~abshadk dots wamed Shape ~that Conlin 2nbegars.--And “= en method mramed prt vareg, provide 2 dascese named reckengle, bangle and chele. Such ae chasses Com Cenk only the mahod pak aren , Ahat pinte the q rea of the ‘ind rape 4 abtad dacs Shape 4 oO tat a,b: abshact usid peat freaC int a, anak &), chase Circle erlends Shape véid pHinthren Crab a web): Sopln U" Area oP dete “yaa ward} y EN Abchact chase * abehrack Keguord 2% Subelaccece Neahends? abshnel clase a Mese: have abehact metheds and non--abekad- methods . : 4 Doessle soppons Mulliple TrheStance © We Types oh emnatbles rave stable. anid Non—thabior! & Dele Thettance 7 sk, =< Aan = Soescs l “werlace' Keyed 2. auldascces \venplements? : nkerPaces. a. The Aabealercen are default Poo “Parag, 4 Supports Multiple rhe lence act “he ype sf AbaPable We chalte B- write Evkending Taterfices uty Eagle} We Trterface Conlin YaGabler aad mathade \tke a dace. Buk the pettods In an Interface. ar" abehaok by debut: “Be Semplemenct ! Wertucid tts: uted tn Exlend. “TrleCieed Exi- SinlePace class 4° 3 iad Rrelon AC a chase 8 Snplenents A yaid-Ledion 8 (9, 4 Oras ¢ Implements B pubic void fordlion A eg Sophy (*thie be Sadr’) 4 class Demo i Pam ') Cob) = new/e Cy Ob) -frickion A Cy, j \o ones) Quealiony Jonswvers | Explato “the types Lf ‘Recece spedflene Eee Tain B “lluchate with a Ties Access -gpcen to Save “tpetlies “ne Scape of. Nbefalde j dhe and seis as toell’ a0? ‘Conckors ca We have Atypes LF Access Specifier \ pte 2 pode a = plead be Defi. . = Sppeelicr Wohenewer om vhaStitble method cand Consbockor % AcGned key “public | access apeder Then Val particule, Ninhiublc, method, class Can be used aaytohere Qa the Tava ca®inment- —e pRvaler- whenewey a NnSadle. acted 9 Conshwctor te ARred toy ‘pRvale! then a poitiedlar NlBable Ean be Vsed only and upb ov within aye! cum clase. Whe other Chascess Cuannct access: rat phvake Vatable method and Consbucksr - =, s The phate Weguord Ss os not weed By classese - —} protected Whenever a \peolected access Cpedhier%e, Adfmed ~Yhen VE \t accessed uth the Carme Rielpeditege B ovldide of the packing” Sng “¥rheBtanee. Pe PCat EE programmer doesn't sea any of ate, alge & woods, oy theo sthose Members oe an Soutee, end, dosaatie ; Wenked a deliaus. dy he Oe Pedqeuss Chet? a daert | Access vane Rpectiter | dare | Prvnbe ok, Yes Ractéc, Yea, Protecked Yes, default | Yes ia ‘exe clas Dale pivale sk8ng name; ' ; de ; public class M8, 2 : U pivmt ) t baka d= hew Dataty) 4 me = Tal SSsawtetla sa: He 1 ve is. 1 2 whl 4 thee ‘b soper-and ba. vol seine chess oles: ————_——~ 3. Extn she: prncess of alin x iin a, se y example) me Mite wale | | ee b wte Uses ot \ypped Rega j diceses —aceendeg othe member oF -a Sper chase - ——— Atos vp 24 Aw ‘ S |B ee of Shetances%, Java) Ta debales chew ae ‘ep Topic, od G. DBre an anh 8 % Java . Hows ie te ie Mow “they awe aedired!? i ep Rmorks ae ES | ile Chang et made Ay the ponent: ete BH ag “Nee betavtevy oF clad cls cho. ob The oveweenge of QnheRlaucs: mony land, , more. Com plex . Use oF \eupen’ Feqword Ra Tava 1 X ; aa ‘ Me 2 Soper’ Keqword Te ThA, 18 1 teflerence Meable alt “s Ne o1ed -fo telor Yrmedinle povenk cbse: obfect \s Goper? can be vsed - refer Iwmediale. poreat-ches Fashauk Variable. Er- class tubasto 5 Clare R oxkends fh ee MH og ob mee BU) e ok dicgly > 5 pay os be vred -to enwhe Smmediate parent dass petved- class A t Ghd method C1) t as Ceubelass') clats B exkends A Void mettod ¢ 9 t Sopls (au chars) wold daptay C9 \ Swper method ( ') method () 4 | class qublle shattc vald mala) L BR bby =new Rcd du a ob ploy ly © Uber ‘Quper! te vsed ty ewe Parent clan coh \ ctalement 7 . ™ But WL chould be nthe HF Stakement to cry chet ant =a clus A AC) t Sopht'suu dnee’); 3 1 eS ' clase extede § . Re) Super CQ; Sopla (Yea clare). Ne oF (Brel? Keyomd * “Tavares Tre Rial Keyuord 4s Tova Te used: 4p srechief He rth cam ' ws toe xpplied 4o" Variables, method: and.“ ve . val wegen! SH, Neatbler swe Conthauls Ewe “hy 4o a seak Teen eS enenale Comptitalion envoy qathods cave veed h chop method brent Ger! . «classe cannot be TnheShet. of tisha this, Tony vhoal ale ener. age" Takgs % Javer Taye packages are Collection af chases Quberfaces, we Wave 2p o yackages Rn Jevn £) guild Sap ages i Wh ave alrendy evils: “Ye An Java Compiler: Po Sava cio yosed hor Aupuk £ output sheaming =P Fava bong used tor ching chasces - 5 =P Java. ubil, To create aia lek, chads, \SnKer lie ~b fave n&, Used Loy yekwor Cig envivooments . ~Pfyava-awk ved creale Gur (Graphical vcerTuey ~Fixce) - Vie Text box ) Rubton Radio button de \ Merdefned packages: We Can Ceake ovr ow », ‘ages Gn Sava vling package Keyuonrd Si \ tnt eh YaKagqe name ot package; ce pack e “ay pack: | Be re We Can -accere he paces uaa vt aN ‘oa 4! st Packege edenert shold tet 7 Foun covce Code - Example poy: Poet a Py fulic chacs A \ Vsid method ) t siter oukepnth (Srsdeome Te podkges’) ‘ } 3 all douces Padage py © pated Smport pee ref chlsde ; ‘ = public chalice v&d mn (Fg aX \ gd) A a= new ALY rene ui oe -a.meth = matted Cy cote clot 5 Ais ia L- jovec- 4" MY Tore Whe 18 4 me Comeck E¥eedeh Yao -d 8 iy ody Googles yao joy" ‘owl an Abuse 18" 0 “Nod 1° ol

You might also like