You are on page 1of 28
+> WWrire a Preegnom in Jova to take an aura and Cokeaflate gum oP even and mubtipLretéoo seod Numbers in the arutat Any i 2. Im porte Java. cub)él. Scanner} Chars addition f public static void create Lint ancl]; int size) 4 Scanner Gc= neo Seanner (System: in) 5 for (int isos ic sizes i4n 5 System: out. painkln ( Ente -element”)5 over li] = $e+ nextlat Ly use : public Static int addikeon(int ancl], int Size) 4 int scum = 04 for(int i= 0s tQsizes iad) 4 ie tann Ci 42 - = 9 4 Sam= sum + anclils metus Sum >} publee state int mulbipltwteoo Unt are (), int siz \ int mul =1 3 For Cnt 103 TX sizes jaa) @ scanned with OKEN Scanner ee 4 | ie Caen (il Ye2 l= 0) oe mut* onli) 5 5 3 metunn mulls Seuvtic ebarte! vod coatn (Stung angs 05) 4 Scanner $C. 92H Systons oth - paint ec Enter ize o int. ne se nent lntQy int acl J = new ina Los creabe Case s.9) 3 ing pulls muds epticateon (are 9}5 int gums addition Cac, OJ} ‘ ie Syston out: paint hln(“Add ition SPO VER OOS tour); Sysrem + ouk - print ls Comurbep lr eatton oR a odd nos” s ‘ a Me mud); 3 Me ‘ 1 > What ss type “casting ? Exphoin diffecent tyre oe type castiag with, example: © tea Type casting means change oR dakokyre de a) net dakabype which "és compaksabse te previous one’ Ly Java’ Supports to, iy Widening tyre carting Compr) seannercOysren: in); an aucay”); 08 * vostable the wypes oe type costing - i) Nar ousing type costing COxplicit) @ scanned with OKEN Scanner iy Widening Aype casting te Here the smaller datatype Can be automate ally converted too Qaseg ext datatype by the compile: , Exe public chass A 4 ‘ publirc gtokte void mata (sung axgs 3) Hhakars lon 8 saves oe dloubte c= 9/5 MWidening Tyre costing Sysien: ou pan tbo ECS si ‘ ; : ef ‘ts passing & HY Klar owing Eye Casting = TE ETS E Ly ea i higher size data type fe % Lower Sie YP ext: public choss:-A uote gtatic void matn (Seeing angst) q } “ | int a= 3005 . 4 byte Leyte) 5, Ibm assco0oi” 9 Sypeen out: purotls Cb) 5 5 iy | 3Y Beef hy explain V Ant: Dava has various VY Java ts very gimple - HY Object ~ Oriented - ne “features oP ‘Java features oF Qike oo: @ scanned with OKEN Scanner (ii) Pon tablle WY Plat form, independent Vy Secuned vby Robust vily Dynamic Ni) prrep Inserpreled VX) High pot-forem ance XY Distrabukes| — Uy Write o Davo progr up to so. Aas> class Print Rume a bo pont pume numbert 4 public ‘static void main (Sting angst) f int ne SO} Syasem oud: pint in("Paime numbers ute SO axe!”) 5 forlint i225 igang te) int bes dy forint j-L 3 sgets j+4) 4 PLC jie's Oo) CH 5 Veua: eles -a Syston oud: print (i aEN »), $ @ scanned with OKEN Scanner SY WOrste Progam to Swap value oR OO Vota Ley by accepting them uding. Sconnexe “Eoas . NA im pont yava- util: Scanners Cass Swap { Public stake void main (Seen oregp C1) | i ! | Scannen gc new Scannert (sysrers in); Sygrem- cok- paiortn ("Enter swo no? Oe Int as ge nentInt hs : int. B= sc next Intl) System out: priattn © Before ‘swappiag vate ob a 4a Vahae oP b*” +b); Int temp = a3 webs : b= temps ; f Syavem: out paint by (“Ateex swapping valine oB 4 asta +t“ vopgue oP b=" +b)5 if i Gy Wre'te a Jove progcam to input O& temperate Wo Fahbrenhett and Convert it to Celavus teat, the Following Conversion Formula. Ca(F-38)/i-5- Anse import javarctil: Stanners closs Tempecatane PUWohic gtakic void mata (Seratng ary U3) { @ scanned with OKEN Scanner news Stanner (System 1m): tempexohurce’ in Fane hey j Scannet SC = | Syston: out: punt (" Enter double temp = St: next Dounle temp = Leemp- Sy fie | : : : | Sysrems ok - print hn CL" Temperature in cebsiuss” | + tep)s a) s eae wary *0 create ond Atse yc" | Ay Wrst. a Tova prog | Unit waded x 08 See. Rasy “Chars punted set baited j public. taste, void nein sorry orga) | Int NA 4 | int ati} ened int Cro\ Cro}5 fon Cink fe 45 den tat) 4 ebaedl fou Line jad s Scans 34) We ee ehv} alijtset ys else altyti) =o; J to nea wt Cint ides Ben's yay) @ scanned with OKEN Scanner 5 5 ah For Unk Jah 5 deena SED y J Sypren: oat? pune Cali Li] + Ds . 3 ; System: ouk -erint bn LVS 3 5 i 5 Unit-2_ 4) ‘ te Pao D> Creake a cass fore product er ‘Wijabed fadtancet, Neo ee tol, Name, prace. Create two pasduct ete Using parameteictxes “Constitute: ini talline S Tnbtance “Variables and aisploy them using another method - Maa; : CeLeaa Ans> class product { private String name ; private int vauiatobepmodtied Td, Recess peaduet (58079 name, int vaxtable puodues aid hot peice) this.name. = Name 5 this: Vasciable preoduct—l4 =vanitable product_? Huls+ putce = prtce § 5 votd disphoy Y { System. oud: pretattlo \n Feaduck name 1” name + @ scanned with OKEN Scanner An Product tet! + voru'able product wid + "\o Produces peice \ +putce) 3 ae tes i public static void main (Secing oye i ee pl = new product (“Manch”, 6644, 50)5 product p& = new paoduct Cparay Milk", 1595, 95)5 i pis dispfleg 15 | pr+ disployls; +° : | at 1 S hnatd 9 ; Lfenentrake the feokune o8 Static | & Wrarter a pragcan 2 dh | Vertobhe — and,.,mbtance” Vasctabte- | An> class Varah le | seh | Statec int a =S05 int b=103 Stake voto showl J Sys-tem + OUL- praintLn( “a=” +a); | 5 votd display oO) { Syston. out: punt a=" 4a); Sytem: out: prints (* b=” +b); } ; : Chass SratteVaulable 4 public static vot main (Seeing aregs'3) @ scanned with OKEN Scanner Variable obj = oe Variable L) 3 P Varurable: ghowl )3 © Obj. display 05 Oby + b = Q05 Varrable » show); by. dis ploy C)s i v3 dis ploy 0) SD | & Greate an object fore complex numbers | say nat Imaginary park» Usin Seqncaie eles elned ad cisplay the complex “dbjects: Define, ano ek Perform the addition oP two complex pln contd rebemn the rcesudh compe v, object” [Aer public cars Corn pilex Add j int eal, image; hue paublre fomplex Add Cint et, int i) ; 1 nis. eal = 13 this + image = i; } ¥ publrc void show () f . System oud paintly( this: weal + “4+ "4 this: imgge. asynyy 3 @ scanned with OKEN Scanner public Static ComplexAdd ace! (Com pilex Add § ComphexAdd ea = new. Compile xAdd (0,0)3 es. read = nds neal t+ aimreals Tes - imag = ab imag AnQ- imag’ Medkwuy reed 3 Ay nee Static void main (Seeing angst 3) Complex Add cl =new Compllex Add Cws)s Complexadd eax neo Gmplexhdd ( lo S)S Quyatem: ouk- print C Pieest Complex nesmbere”) 5 ei: ghowl)3 : : Systeme oul: print (" \n Second Complex numbet ays eX: Showl 33 Compllex Add ees = ada Celts 2), System out: pant Addi ton sow) ttex. Show) pce k SP Tate nd Re a eee eae 5 5 Ly [hat is method Overwiding ? Explain with o peascom Anat- When two or morte methods with game name § Same no. oR acqumenks urea in Aiffecemt forms then i.e Known ad Method Oveuciding » pene nea ienphement “Method Overniding by he hebp 08 Inheritance - @ scanned with OKEN Scanner cYoss Ov 4 Void showl) ‘* tayaes: owe prunt bn U'ghow oF super choss )3 ¥ ‘ Class. nev, extends Ovt Void show L) : is System: Out: print ia C Show 08 Sub ¢lors yy ye : ; &: : 8) public Statice void rian (_geming ang newOv «Ob = Neo newOv ds Obs show 5 Ov cas new OVO; oa: show Ls Ss . : Sy) With an example, explain widening and nascscoewing oP metenenced datatype Cedars type) achieved th tnhemttance : Ans > class... base : { votd “show L) J " System. ouk. pint dy (exten eerbae chars \s 3 a @ scanned with OKEN Scanner closs Deu'ved extends base { void disaploy 3) z System oud" pained (" Display a derived chase): Noid Showl) Sysrem- out peintdn Co Show oR Aereives| clors")s s § s ’ Coors nastoa wide 1 4 public stakte votd mary (Strctag axga 03) 2 base ob=new Derived C75 ordering Ob: show 9; Deniveo| ‘ocl3 ‘ od = (Wesetved) ob 5 Iniaiticowing od. Show (15 3 oq. display C15 5 pect 6> Write a Program to A> cosy Antinal ti 4 Votd. eat) show Muttilevel inheritance syptup -fouby puntha, CO asag”); 37 Choass deg Lextends Animale @ scanned with OKEN Scanner | Void bat O) { Syarem out: peintin( Bax Kay!) 5 A Cdass baby deg extends clog Tie : f Votd, weep ld { | System - out pretnt On US weeping ”)3 | 3 Coss test inher tance oariee geakte Void sain (Seeing, arcga 3) 4 bakydey obj = Ne@ babydog (1: Obj: weep OI; é Obj. barnl)y, obj - eakL)5 3 | t | | YW Wrut+e Shock notes on Polyynoxphssro 2. Anst- ‘In Object Onrented Preogcaramin a a. method ot a vearwable Can be Yatqd in more than d0e foun to penton Atttenent tars ts /Callesl pollymonphism. 7 Poly means Many 4 Moxph means foam . uy Tava Suppodls S types oe poly ma «phism @ scanned with OKEN Scanner —— TY Consircuctor Ov ex Loading iy Method Over Loashing iy Method over ruding presen theese three WE can apply 5 je Known ad Ly Excerpt polymorcp ht Sr) on varutables also 4 wy) Variable Overuciding ° Unira-3s- j dy Ditfenente béebween Absewact class and Interface. Awl: “Abst aaed Choa’ Eoveciocs dy Absamact class” con have -4Y Taterfoce Con a abstract and non-absivact anhy abstmock m ods methods > Brace ava Byte Con have. default and): static methods also - RY Absinact chass doesn’t AY Interface SP Perks Support mutti ple metkiple | inheritance - Inhercttance - erface har only grade 5) Abstract ‘class Con have, a¥ln Pinal, nen-final 1 stake and ‘fmol voswobles. and non- Stabte variables edoas con provide — YyIntecface can't provide DY Absinact the implementakéen oB intettoce. © Ne imp Llementak eon OP abstract class: SY The |‘ abstitact KEG 0K fs JhGy ae. Jinan face used to decloce abstract Keyword ts used to class : decdone intaface- @ scanned with OKEN Scanner S> an qbstnact class GYAn interface Con be Can be extended implemented usin “aing Wor dend otk Kegwored, “imp ements”. WD pubdic abstract 4y “publsee interface Chass Shape { Drowable pubdsse abstcact void anand) 5 Void draw lly 5 i Dlhat es the Fal Keyword in. Jove ? Anse To: Sova, the final, Key worl ts used to denote Conatants, Ik can be Used | ewith Varlahfes, onethods » and § classes. > Once any entity Lvarraole, method ot class) is decloxes Sino , tt can be aasignesl only ‘once: Thak tS. % the final vasutable cannot be teini tralix eo} with anothec value , % the final method can’t be overmidden . wk the Final class can’t be’ extended. Ext- eloss Main & public static vord main’ ( String cuca C3) L fi final int AGE =32Q 5://. Final: voutabbe . AGEs4S3 I try to change the finds Vasetabbe- yen. oud print Cage: "Sy AGG) ~ @ scanned with OKEN Scanner above Progam. We coed ean ithe thoLion Gee When we assign a cannot thak ererlort ge a comp value. fino ‘varvable AGE to 2 AGE =4S yo UXO Out i uo ywopndap 394 gy LogF 17ND sat & spphoasae St maa 31 We patio a FPA pq by aq = yenf fa7NVI “Gap 0 porns TD ae Ryuo pagan 2eAPUd Mh gj Noma Arps pre? %! polgaw ues th 3 fe Pee : suogannA@p: AL PLAT Be i : E yr {ho 38 yadwu = ae Spas tpw 4 304) foxy Gen BABES uy far PO pir) Wore, HON PAO POA = Ruyooy> aA HAOped ot Ae Qypoos de pout “pa sopap a1) 8 hypeuly dF porhsy aye 8} PU G ORY pee @ scanned with OKEN Scanner 4y Explain about ExcepHon Preo pa gazton 2 2 Daas tae exieption tei haar Hiceen $ror, the . bP the siacw ond Mf it Ts Net cought’, it aoe clown the cafl stack to the previous os dps “ROE cought swetes he oe ne mat aght j : then caecanane gee ee Meg mE called u ao call stack: This. ts lect bottom a8 the ex ception | prea pagak ton ‘ s Ext odass Test Exception Peopagareent { Votd mt) f= 3 a int daba = 50/0 5 5 void nO) f mO)> DOS SS ae ¥eakch LEx ception e)fdysrem. out: pant by : Bes 2. (“exception handed st Tinie atatte old main (Sicing argc), Test Ex ception Propagakton ob} = new Testéx- ception Prcopagaktor 4-C Ma oep. POS SG 9a < nets uk: preintin (noamals Lista 2a") 5 @ scanned with OKEN Scanner 3 3 Sy hot ase the Excepteon hand Ling sions i Javea Ansty Exception hand Ling in Tayo is see 4o Improvise ,o Java apphicatton's BN ae es porforrmance capabilities - Exceptions» iP not ere property rmay, pose a, Severe, thrieak Ane. OFF 3 Program In real - me . > ERY: catch block :- Syntax t- ey a : Ncode t catch Cexception t) { Mode WW) frnadly block 2 Syotaxt- ty { Mode ah Céxceptionlypbed el)h Match block t Fenabty 3 ; HLnably block alsoays execubed Sy Hi) throw ang theo w Mequon @ scanned with OKEN Scanner SD hab ace the advantages a8. Exception handLing 9 Ang). u _ Regadax" code » Peapagating Erstows Up the Coll Stack WS Qeouping. an Differentiating | Gewet Types 'y Sepanaking Enno e ~ Hapd Leng code Freom *} What as Jove ‘package and) howd is it cared ? a In Java, Pac kage Yb a group oR giro i Sose types cB closses, interfaced. and Sub Pacwagey - Bee Parkas es can be ckegorixed inte’ tod ype i}Guilt-in package Vi) Usere ol e-fin eof package 4 There ane many belk-in package Wne fang, Quwt , swing, mek, to, ubel, szl. Gavax ele: ied 3 Te define / Creake a NU package ee have to use the key wwortoh “pacnlage” Syntax tr Package rackagenamey } eyie Package Hypackage ; @ scanned with OKEN Scanner Unreny ek Se au uu: Ohad aes Gx plein how can a thread is Creaked ip Java. - ‘Amat Thread is a predefined chors ig Jove. thak Can be used to creake usec defin ae IL abso gives the flexibility Be mat SRC ens ne: Steps to create a thread by extending thrieao| clars iy Firat we need b- ovecnide unt) oavatlable ts thrcead elaass + “This method provided ON ent poling forL the threaol and you have to pub the entire Logic code om the program body inaide the man mMekhoo - : : Wy Once thread object is creaked we can cool Start methoo which executes a call’ to rw method . package ® scanned with OKEN Scanner g . 8 & 4 & $ 5 1a) = eo 8, z| s worap manger, 5 i wrens ery) wamangelengprety al ee Spreng nny ven wag ATOPY Geo ndynQvay ply wong rab hooyat ogre 35 oS ; ae brrang dyn) @ scanned with OKEN Scanner iy Input Strear Hictorcaly, in Weerap dg 0g 4m wera AT) tema plitpey | womag 7 lujopeg, wrong larva} wwearag podbean omg yah wong | urowag meer poppy sl, | @ scanned with OKEN Scanner display | TI S> Loritte a melsitheeaded Java program te eas Cntents o@ two arco oB too threads simi Ans > Impont java+ to: a | impor java ubed: * $ Choss A f public static void main (Seeing aregs(3) int aC Jsnew int(SJ} Theead td ~ ned Threas| (new Runnable) 1 public void munl) ee la) teiiras sc = ned Scanner (System: in) Syston out: printin(" Ente the elements’ MNS fon Lint t= 05 i Tava Swin qo compared 40: a Vely Ges functional'ty San etvonali® mL as compasted #0 Swing: AWT - pee >The err Ti kimme oe Ly The exedubkedd! me 08 Going AWT. 1s mone ‘than Slag: Mess? eho AWTs fei dogh le Tre. components o® Java The comparient s! oe AvoT are platform dependent- Sewing ane Ta independent IMUC pattern fg pot Sve, pattern, iS supporcke') sup porkesl by AT. by. Swing < Se PAWT provides compatakevely

wt + * Prublic cQars - stretn - Using —pascarackere extends Applet { pric void parnt (Graphics 9) ( String nm = get Parcamekent (“ no")5 String enrollment oo = get Parameter enna llmentoc!); 3+ SCE Colon (Color. ted) 5 Font f= new Font (“Cadibai?, Font- OLD |: Font: ITALIC, 24) 3 2 9: Set Font Ct)3 Sher ey 3 rao Sting CON AME I1S4 "40m, 40) 50) 5 Jed aw Suing CS ENROLLMENT Not "4 enrollment no, 4 Fo, 100)5 Js /* applet eode = "seeing —using—paxoreter” herght= 600 width = GOO» (Param names “nm value =“Compuberkath sala" \ @ scanned with OKEN Scanner v ‘hat do you Maow by tortappert eloss in Java? : Ute the name op all cweeappest elorsers egecscenporclinn, © ate primitive typed - ; Am\- The Lor a.ppert chars in Java provide the Mechanism to convert pa'mitive into objet ane} Object into paimitive » : “Since Jaw version 8:0 supp Unboxing Peatune converck object Ond primitive to object axite mast ¢: pets aratoboxing ans : into primi ve + Gaver$eon oB preemittye into a7 rabject fs Nnew9 O38 autoboxing and vice VeXsa vs unboxing - Permit ive ire Wenpper_Choas icon Boolean chen Chanactest Sut By te pred Short ink Integer Ang 5 bong ee Floak aueeks Double @ scanned with OKEN Scanner SY Explain the event delegation model used) in Java, for event handlin, Ani The Delegakeon, Event model is defined hand he events ta GUI PRogrtamrotng Danguager- “ The GUT stands for Gitaphical, User Interface, where a eo -urert graphically / visually interacts with the system - “The: GUT. progtararain ® nS Mhenently event-driven s whenevere a UsEr Inittakes on activity such as a mouse activity + chicks , Serolsing Petex., each, tsi Known as on event shay £8 enapped to a code to KeSpord © Fuinctronality te the user» This) is Known ad event hand Ling » @ scanned with OKEN Scanner

You might also like