0% found this document useful (0 votes)
3 views70 pages

OOP in Java

The document provides an overview of Object-Oriented Programming (OOP) concepts and principles in Java, including core syntax and examples of various programming tasks. It covers topics such as class structure, variable naming conventions, and the history of the Java language. Additionally, it includes practical exercises for users to implement basic programming logic and data handling in Java.

Uploaded by

sudipbajgai56
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)
3 views70 pages

OOP in Java

The document provides an overview of Object-Oriented Programming (OOP) concepts and principles in Java, including core syntax and examples of various programming tasks. It covers topics such as class structure, variable naming conventions, and the history of the Java language. Additionally, it includes practical exercises for users to implement basic programming logic and data handling in Java.

Uploaded by

sudipbajgai56
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
OBJECT-ORIENTED PROGRAMMING (OOP) IN JAVA Core Concepts, Principles, and Implementation MW tiatstam =) a Pranish Praja Lecturer: Sameer Gautam PDF Made by: Aarohan Dangal Rivison Humagain To OTOP Le Javae Filemantt:d Town” yaa Aijenarre To print im yavas class first L public static yord wan (Svieg argaty) X [Link]-t CU Hello world"); \ r class varia le ane tho. pe _ Java ts Robust because of Sn hanquing, Crurn Gime ©rror] “ManagenenE. Reliable’ Double Security check. a....0hld HE Things to Remembers wna “ J)” elass name stedts trom capital letter. | “| Variable Name stares from Smqi( letter yo Metheol Aame starts from arog ll etter : q + a on . l Question’, wAP eat woread 1G niet re 4 user and check pf itIS9 fiponacey Number or Not (4) Comtant woritten in all capitate Ce) ava Fellow camel case Aa naming convenGery ~ or Nota), ad what Is camelease notation’ - eo aoe file one clas class Adgq = _ _ “static veld Main Useing...args) int a=, b=56) LIN sums ath; System. out. print an’ sum, =" 4 sum ]* a ase Wevartahle (er vs onaett wank | Class Scanner, tata type. pacraae Cheater hile seetat) Mmpeort fyavqugl % class User Leput Beran x public static yoiel mein (C seing...4r gs) < om Ht_aaqs, Scanner scanner =ned Scanner ([Link]) ; fhe A= Scanner “Reger YY inte b= scanner. nexetne Us Sytem. out print tn un sum = “4 Catb))y J what Ts camelease notqtion* > Treqavay Cameliage is a naming Conventey) where Multivwore} Telentifiers are Joined together without Spaces; arg each new word starts with q capital Letter. cy WAP that reads 4 Number oiven by user ang Check TF ft faq. fibonace? number or NE: import gave. util X 7 efass — Fibonaceicheee die x __ Syyeemoye: printin (!" Enter a a number | en int RUM= Scanner inert Ene j fot Q=0, b=4i _ — boolean found = = false, ee a MH Cnum==o It num==L) founc} = true; a etse : _ a pe hake i - vohi Le Cbe=senum) 7 if ( Foung) ‘ —~ Systemout-printiy("num + “te a Fibonacet Ourther, elseg Sysvemoyt: panel (nuret “Es met ¢ Fibonadti number) peas payredl M00” ce rpenane IE i e078 403% = reywit tr OF I at rs LUT ©) = an import qawa utils doanner ; — cass Cela siys To Parbrenheit — X public stave vatel mi (stig age 07) < = Scanner scanner = New Seeinner (Systermin) System. outspanttnc'' enter Eemperature 19 Celes4sJy - 3 . Float _ aS float cetsivs= saanner.0-ek th (35 ) — Float, [o% Celsius float farte fahrenheit =Retsres 7B t 37 System out pantan C'Tempeahre 7 Fahrenher t 27 + fahrenheit) scanner. close YZ History of ava language, Origin £ Evolution, > 1981 Lqurohs Created by James costing, Mite Sheridary and patick Neughtory at sur) Microgy- stems — | : a Gireen Teams Develofie under 4 secet Progee —tod@= Nai ef the “yreen prgerts __ Tatil Foss Designed ongirally fer qrgieqt = cable tefeycT VY bofes” andl enarl how app lia®-ncez —_ - - > Name change? Named Greentalk first, reramed ~~] oak ,ard Finally roamed “Java in 99S Core philosephy E Design, 7 1 = WORA CONEPES ProNeceq wie Ente, lun — — — Ainywokerey po tet tole run onary olevite without shangés > The JM used q virngl pachiN® ty uM jaberme Fate bytecode” Fnctead) Of Mychine= 7T - Shed Fic cod = a ™ (ae 0 + Salety Pirie. Permved cxing@werous feaNre like gncere ard aed] cutvrarte garbage collect. Joo te Prevent crashes Major NL tne 2% geleinie © 9b CDELO) 1 FIGE OF HAAT tommerckel vers, (Ie Cava 2) FSH BE ePUTE nts sarctard 7 re cE AME N qs de J2e ang Z 4 — + WOK Topen surte) Soto Cormack): Se Sun MiPaysberg oft Over > quut'> aevelQPine = DOT case releqws) T swjechey To a spice sTanenth release cycte to push ot Res feature facrer LS) WAP that asks User oO enter the Aure . her of boys and ovef iris in your class, Bisplq the eatio of boys tv girls, a import ava. util: Seannery class © Patio < ee _ ; : Pubic static viel main (searing args 7) Scanner seanner= news Scanner (Syscero Any, Syste. out print Ce ater ne «of bays) | nC" enter s pr Tnv_ fee ftott b= scanner. nett Flam Uy Syseemnoyt prine-t9 Leaver ne -of boys") * pay. CAS feat Qe scanner: nett FtoqtU', te fleat Ratio= “big 4 + — Syste out -printtyU! He Patio ISX" + patio): scanner c red 5 a WAP that reads a num ber froen User And abthe — feltewing ae, “SINT menudnven eeppreach (0 chee Gf the nbr PE oclet or eren 6) Cheek popes or negalive oO. é) Check Pime or composiee rp ert 20 import qara. util. @canner; _ Scanner seanner=New ~ Scanner Csystem in): [Link]:prinedin CEncer the numba to check the following actiity I int a= scanner nex tHeoett)' r 1 ef test W) Syscern. out: printM( 1. del Or even’): _ Septem. Out pri'nt-tn ("2 positive or nega tive — System wu tsprinttn ("2 pame or compete) Systerg s out: pintan UY. exe i —Syter out perneto (" Ereer Your choie int chen = scanner Neyt Int, Ses)t oh Cohsrle) x case Jt Vaf Cah 2 == 0) System, out printty CT Cura hers 1s eves'f else System out: print-in" The number is oda" _breale; case 2: if Care) aL Sytem out: printdn (‘' posi tive! WA else if Ca <0) Sy tem-out: prin tdn C" Negabvel): else Sys FEM. out printdn CX zero"}y brea i case ae ie ine Count =O a int \=41) if tai e=) if ia lager 4) x i Syston out: print (Neither Pree ror compo!) u else if lat?) 4 . . Sqreem oerstout: pants Ca +116 9 Prive Number") Y elce Syrtem out: pan LOC At! is a composite Number, . Go aaa ane ALOE fe epee ee ee case = = Eyer thy . acfault: — System outprintan (“ Tavalid chake" } iz h 4 a ne aus 7 cnr ting Systern, (Qe moTere Javee UHL Sean ners, clacs cnrade x Public StXtle votel main (Bering erg cD coe Scanner, Scammer = new Scanner (System io): —___ Systemeut pnnt4in Center the marks of ve en es _subyetts \")s 7 float math = Sanner. “Rext Fogel: flout science = Scanner. Next Float; flowt gk = scanner. Next Float floqt total = math+acent 5 ag - Float penent = tetat [5+ : - if Lperrent?=8 0) Syrem- out prinedn (You secured AN eleeif CDercen t= 6») Syseem-eut- prinety ( C" You secured BY else PH pertent 2= Un) _ _ _Syspem- due prone LU" You secureot C else _ System. out print, inti CU" You eeu] fy"): LM yeah | yu Beirne’, “Cogia, ‘Nepati”” Comp ber ry forint 1= 0) fe markaf + beng 1 1+4) x Sysvern.« outsprint-try (" The marks 1)" Cid + Tout of 400° marks Ci) = Bo: a f Coarksciy x00 L] marke Cry £0) K lt Subyect S wh Je n ayer. puts print n(“ was not) Pee tor rang * iy retirn ’ y / U4 Yr ar at | for int 190) Te roarks a tenger, dt) Xx . 74 Crdarks C1 J ¢ 49) 4 Syivem. put -prinetn UFait leat"); v eturd } 1 & Tn€ otal =0) forint T=0) je marks: lengenyiee) tba t= Marksciy) int percents9 Sterql/ sy if Crerten tage” See 2=20) Sper e ouesphoet n CA") —— _elseTF Cpertenteige 7st) Syirem. ouéspArntto cB") y else if (pertentage 7= 9 System -outsprintty CO) by Loop 2 €xPR, AN the loop available 1 Java with Byntap. ~) A loop fs tse be execute a block of escle repeattediy MNT a onal ter bewmes faite, te bejpe avetel WABDY the came ioe mulaple re (2). Fer teep ak 7 . used wren _syrtaK : : par Cini ral 2a9F Cond BON? xt _ - ’ — [| Code 4 — @) vcohile To °p. és ud ecl when the Qumber of Terabe iS Not jeNwor) _ : - 2 condilis® Js Chek) before is SK ECU Me | Coop bray a — | na ef~ecube Zeer EiMecy Syntay a Loki le (conatt tho) (1 tocts 1 Joreh} le [oop Conat ery fe checked af ter executing Che (oop body = — €keeut a at least ONE : _ ade — _ trestle __ TV vshile Conair ten) way ENhanced for (oop l fer~Each [eop) = uted to traverse Anraw ano collects) e Ne neecf to wre inex Marahle — SYMAR, OO 7 ; for ( (aataEype cyertable: array) 7 I besde checks condition he fore. Pray execute rery time Arrays] cotjecting , # je main We Exam Definitions A loop Ts q contol s truemire “that repea~ | kedly srecub et a blocle of lode ag 1999 AS Specitieq cond Tiny remains ove. : for— counter Conbellecl Lp, 7 while: Condiien combolied (op il Senerate and [Link] tits pattern ug} Nested) while too) “2 t 9 2Y 2, 2 @y§S * impet gava-Ubl- Seanrrer’, Pape Class Pattern pbc sabe static void main {stm C1. aig9 : — a - itty ae a out: “Pade (3 while (id= ) 2 7 in + r re Se System-out ‘print ® Cyan "ys qi) * systema pod 0 § - 12 34 S 2eus 24S 4S int Je 8) while U2 1) int gens white Ks e=\) * ’ uate isepers ite a Sytem out:print-tn(); > int Teag while €1<=5) x . Int 72S while C4 7=1) [Link] yeAnt ( ba 4‘ 5 oy [Link]: print tol) iar, u SHC V TOL S (variahle tree) a Array anal yeurable lel ta og abe there ye rg’ AP, Int arr CIe new jatesy: tee lh ‘colunn Ainrarijon O/Pera tor) chayelér ner ory allocat egarya col Int an CTE] = hes a ie Ey Yow Aimersi?? int yag 03 C= new eC C7; Jog Top new Int Crp gagc iy = new ine 034° gaged = new tnt C 27° > : ) Cd Ust all Ehe symbols that You ting ina keyboard cind name them, Ho WAP the Creates three arrays CL of) mabik Cea) © Jayged)» Read elements Int the Arrays and dieplay them, use Appropriate Coop of Ysur choite - _ ter sy Read tee dimension of 2 Matives, if matilea can he multiniied then Feaq Elements IN VE, multiply rmabites ang Afsptay the “feauit. if mraoices cannot he ~ maultipttee can qisplay appropriate Message, “I WAP t Print ' the Pascal !'S orangle Of height aes ony See — - UW) Use ary the syne that You fir} wa 1 Feybearc | OF pame them | symbol — Nante {ss a es ON Rat de Perrave Recent: Tt excawebay Mere At sign Hash] Nuther s19%) Pours a i” Deller siz) ¥f. Percent sign i caret mi & Aropercand a x Acverisk 7 ¢ Jefe parenthesis a y Right Parren thesis. - Hyphenf eainus sgn) = unclerscore += < - Equals sign t — + plus stg = c left square Bracket ~ 3 a Bight Spare Bracket x es “eft Carly Bracket A + Right conly Rracket- \ Backslash } Semicolon - 1 3 Colon — v Apoctmpnelayngte Quote . _ _guotabsy rark (Dwhle 2 com 2 (ess Tran sign s _ Perec} [Aur stp > : _ Areater Tan stgn t a forusar Sta QuesSn perk. 2) wep te Create three dimerion cirrepysl fof p Mabiy ed), @ TAqQge]) . Read elements Inte thearrays and display them, Use Appropriave loop of Your chotte . t gavautil Scanner, class Array ’ ‘ X 7 zat stqdc wid main (string lI args’) Leanner se = neta Scaroner (Sysrem-IN) y td Array ee jn C7 arrd = new yt sy EL _ Systemout: printdy (Enter S eternents for th Array sc(Ynt j= 0) fe and. lengths p44) Orde iJ= se-NextEnt Uy jt CILD arr2= Aevorrc2icg;, System out cprinetn COE REE Taternenge for 20 array") i —fertirt fc te Tete J= © j Je curr2eid tegen; 5+) Te arr? are 2 fength | chet) "| C career Cj] = Se-nextIneU; (ne Oo Ugaqged Array ; int gagyzeqC ICI = new tne C2] 025 Tagged Cod= New int erry) paggel C17 = rewint ¢ 8] sagged C2) = New Int CVD” rniny tprinttn CM Eneer elements for gagged TY") < ul £20 Pegegged-tergth 1 itt) : : jt ferlint 5-07 eaagged Ei Hiergth 75+) a Tagged Ci CGIE senextEnely —¥ ae cr Display 2D Array jis System) out prints {" \N LD Peay), feclint T= > peand. erg th, itty ah Sn yee. out sparat Caray +" Jo tl Display, 21 Array [Link] prima UCU In 20 real forte Ss ; ie arr Daterpthe mit) Jz 4 for Lint j=) jz anrciz lerqeh; it < be . Syston) A out -pring da Corr2 Cizej I$" wy & Sysvera out prinetn (I Dispray — yaqy eet Array, Syscergout printan C" Wn gagged Arey My, ee Teo fe qaggectssterg thy i441) a Lint 4=0 4 7% qagqyed CHI-length 54+) Syseemout print gacpyect CHIE] le", x Sys LEM) OL print QO secloteUj 4 | : 2 a (3) Read the dimension of 2 rogotes (if mabptes Can bE mquleplied Enen ceaq efements tnt ity eoulply matrices and dispey the resyfe . Tf Merbites, —_cannet he rultipiied candispay the Appopnait | message 1 qayece | __wnport Ova UBL Sernner) : : 7 class Meabix Fi public sratic verel rain’ Csbtng exrqs CI) __ st Stmabig - Syyeern-out int BCC) x Seanne® 9¢20eW Seanner Coupeorrin)y [] Read dimensions of first abit, Systemout print C" Enter pot ard Coleen of Mayiy AS") int T= sc-nexeTntuy Joe C1 = SC-Mexe Ine Y) (I Peaq inmendtens of Setere Matis, Syscemoue: print ("Enter rows and Colum * "Vy we _iot rie ent Lnel) joe cr = Senentlnelfy [Leneck it Noulepieby is passinte. tf et sss ro) : a.) ee a _ _ eqvoutsprintlin UY Mawie route pirates is not pussible.")) ae oe _ seUlosel)) retrn; — jing ACITJAMew inttnJCa), New inttr Y] ce2d) int CCItl™ res ine Crsyterdyy __UfFead elererts of prait A. _ Sysee morte print-tn (Enter etements of ayh ne OULOF Mourd LT Cef ery fer nnerterty Ay "lp for Unt 188) 14 FL bene | r++) 4 / for Lint g=0 7 4eeh yj tt) AcityI= Se. nek EInt UY) { 1 [{ Bead elements of mab} B. Syseemmout printtn (enter elements { Mati oy for Unt iso) perry itt) 4 for (int gee pect pga) € RCIA senext nr; t Ip Muttiply Mabices for Link i=oy levis 7 144) Ss fern FEO, : zor pat) forth k=o) ke aye tt) — coeds += AGILKIT* BrkI ty) , ~~ « b Y =] neTr™ oh ow) fom C1 disp tay result: : Sycermout: at UD Vie yivernoutprinean UN Besyl bent matty"! forlint imo, per y 144) : rR forLint 4=0 bas Coy 5+t) Syremott print CHF I+ ey ~ B syreemout printinUy ns seretore 5 nthe gos erste J) WAP & pr ‘ ReIghe aks the paseattS btangie oF Tea port, Zavaru BL Scanner 5 class PasalsTrargle a pus sabe wiel main (Stiry agstJ) Seanner sc = Neto tanner (sy ceria jn): Syseemourpant (Enter the height of Pascal's! triangle 2%) : fret N= sc-nexttn t OF Pe or Pas, ? veh eer petinh i=0 ) fenyitt) fre nue d > —— dno, gent) ty) S yutemout pales YY aun enum © Gj) hay, System, out printinl) H ~ scctoret): .——— - a - yi, eae : seing ; 7 2 - oie ~ g — tnnute ble Es birg c= SHetre e t aI = —— ie Voor C = 7 a a @ on Dein’ “Hello tog a Sviry Ruy fter | wy MUEADIE, Oh Fr —, - 5 7 atte) Fs IND SO Hep beng Dwiejoy Pemp-yewrg, ; ) clase Division Nemo x void main’) x sting name) Tot md.t% map MU) 0S, totaly fivat per? [Link]-Seanner ac New ave. Udl Scanner Coysvem 9) 7 : . Sgycera. put sprinet fencer Your name i nanje= [Link] nel) H Sysrem ue peintt Enter marks of S su byecd) mit acne t Trev, mre aonexe tnt) mee se-nert Ent, ray= scney ETRE; mgs senext Int Vj a “gotal mLam2 +m stron ms: ae er = total | 5-0 FY oe tL _ System. out-printty CM Name | ~ Seto) Syter-outprintin CN Total.~ "4 toot. Sysrewnouc prints (*penentsge ped) _ int r= Und) per (10) Sertch Ws CSe 10! Zz ___= case 9° case Bs Syscem out pninety (a AY; break; defautt® Systemout + panes" — = rs ot Explore and destrihe with proper syntax and_ Skanes , Lo commenty usec sbirg trethed.,_ —D_ bength O ry — 7 _ Returns _ the num ber i characters | tha Ot isting Syntay) ——— [Link] thUs me Aa —_| 7 |. _ Serine “a= Hette” F [Link]. print-tn (8-Leng th Ub _ Sutnye s&s 4 char A&C) a ~~ Rheturne the chara ther ct ct spect free 10a Syntay * [Link] tUreer)y Ekamples OS — aa = ————_Syrtermout:paintin (s-charAay - _ Autpat Tv. 2) bopper Care — Converts atl Characters uppercase ~ Syn tar? : _- aoe! Name. Pepper eyarples — ~ Sting 35" henie"s _ Syptemmout: printty Ls. Upped | Sve pe TT Hello. WM te Lower Cece () SS tonverts all Charaltere to levoer tare, syntey’ String Name. to Lower(aset)*, ! Exaraple: —Sytenmout-printia Us. toloveer (ase O)y Swing s= "J AVAY _sutnue? Jor (s) __equatsU _ - = Compares wo Soings for qualiy, fc — Syntar’. string 1. equals (sting): Bramples a Seirg “SLE qua) Seng 82> Agave tlle — Syeemiout: printin Cals equals (89))¥ (er gd Sut puts bve, (4) equals IgmwrelaseY Conmperres tro sbinga "ening. we clitfere- — neces, : —Sgpears ie ~ sag spat gpl tog Ds I Exarople: / ae — Spang st “dava"y i. = ta Sping 3% = “yaval; Sauer ate prineln Ust-equqleTgnere Coe SA) output: Gwe. a subewring U a> Eybatts part of a siting, Syntay: StriegName Sees: cess. satsth, LM a or, / sting Name. aubturing (begin Pnetex, ened tren), examples { Seting ==" Programing J Syseemout: printAN Cs. subteing (Jy ____Syjbenroutprintin Cs: substring CaD)y output: Geer — gram) hal = - (3) Contatnsc) 2 chectee whether 9. sing Contdins q Speci Fe Sequeme of Characters. | gynbae ee am __ebingName . contains! Eext"); | Strings = “Hetle save" | System, sutsprint ) Cs contains Cava) UBM Lote, pe NX Qs Q a) Index OF U —) Returns the pestbon of the First SCtene nce of a character or substring, - Syntax \ siriry Name. inter Chara tbe)s or, soing Name. indey of Fisitaeieg Mp __ Bangle. | _ - String : +F Programm? " _Syeenrant printty ts: Teexof Ug sutpt > 2 - Terni) Go) reptacet) > Peplaces” characters ~s Subseings boi th _) few values syntax? a Swing Name. replat] Lol Va tue, AewValugy Example’ cn Seng TUR Spey Sqacer out: print Ce. relate Cn saver, " Python): Owe pur > IT Uke Python , (2) Difference be tocen Strirq’ butlder and sping butter. Also ctst thelr comme) Use Methods — tnth examptes, | Both — SbingBullder are sorgiaiier are used _ creqte Mutable Spings Gstings” tet that Can He edt tied wotthou te creating ae neo | iE obyect} Rag ye A Tea! | Basis StingRuNcer sbing Butter, wa) Thre Not thread ~Saferso _Threaq -sefer so} It I safely anu Tepe threads tan fan he safety cause jssues tf they “used by raul ape raed fy the same obyee threads. = = ‘Stent baneosly aS) Coy pet Methods tre Not, | Methods dire eq Ben Syne Rea ny 2e0f _ =. __SaNthronfee < Se) Perfrmane faster mauiaT no Slower becuse — |! sy nchrnni 2 Bey syne brent 2 Ger) —_ overhead fs _ tet urret in vwelved ERE process) Ng usage Reat suited for Sin Sher ter Seale atiweqel eg muld three applies beng applica 6. Trtratuction — Entedyted 19 treetucel 19 ase >, “Jawa bo. Example: ~ : SoigBNeer Sting Butider abarecs Sting Buller ("Helto™ sh-appere| ("yava"ll, _ _ Syster .0ut-printlo tsb] — output: Helte dave. stra Giffer, String Puffer -sb=nevo SoirgRuftert™ Hettey> _sbretpnend| C" ava" Syycenns. aut: pin? ta) eutputs Hello avg, > Comma) Methods of ctrirg Muyjleler fsertrg nulfer, > Mete metholS are the Same for beth Ctasrec _____eby-appeng Cteerely example? StringRullder sb=ne® SwingRuilae Chenidh at

You might also like