0% found this document useful (0 votes)
21 views26 pages

Java Practical

The document contains Java code snippets demonstrating multithreading, database connectivity, and basic input/output operations. It includes examples of creating threads, handling exceptions, and executing SQL commands to manage a database. The code illustrates various functionalities such as printing thread names, inserting and updating records in a database, and generating random numbers.

Uploaded by

Sakshi
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)
21 views26 pages

Java Practical

The document contains Java code snippets demonstrating multithreading, database connectivity, and basic input/output operations. It includes examples of creating threads, handling exceptions, and executing SQL commands to manage a database. The code illustrates various functionalities such as printing thread names, inserting and updating records in a database, and generating random numbers.

Uploaded by

Sakshi
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
Assignment. 2 oo Mutt 1 ae oxie]oq ol) 25 a) = Sars nlulliaivdadinis © pladsaie ee wna Le ‘ for (te Ay Cee By pg ee package, abe 5 X public, demo extends threads than °O5\" aie pute, youd wun) G4 ) 33) System’: Out prinkn Gist te) s J try J Thread. Steep (3000); i y Caton ( Exceprion e) . = 8 poiptsenetrase 03 4 J t publi Static _vodd main (Shing 04 args) T t Demo t = new Demo 0); t: Start (5 5 y 7 aga No, +) owl Siok $ T_VsViW om VE WHite @ awn Lw04 to dk " Hello Joule” ae Hines Package abo + ‘was “mytintad implement Runnable Olos ABO DEF MHL KL M.N OP f Thread § 3 pubue misthnead. ( Shing HHe) 0 { v (f=: new Threads (thud; tthe), : + Start ()> ¢ Pudolice Vol Buin > for(int P= 05 (eto; itp) \ * System. owe statin s6:ChR GEES eyeadelame » + Thvead . Curent Thread 00. getnlame ) 5 bp Thread: Sleep. (100); i

Jona. 4 Threadniame: = Hele” Jawa. fi | | oe | | {ove} J LL - oo \: i 7 : 3.) Wuite a poo TBR. plod au > | the ae Ant ; t Earn Vowel, Doula, [. | 3 seconds {| | paseage abo. KS Alin pote Jawa. lang.* fl Import Youn. util. ¥, : il dass vowel extends Thread 1 4 i “Shing 315 I, vobbels.(. shag 8 {! 81-3585 f i SY Starks 6) 5 | ~pusuie votd run C) | | System. out mnintin (" vowels axe. ”); {{ forint |¥ = 0; 2 9), length 5 44) j f ax aie 8h. ear At Ct) ! h— - Qublie Atatio —yotd mauin (Siefn 0 args) 7 IS ¥ [i Sconney $= new Scanner ee | System. out ptintin O eutey a Abies ws 7 Shtaat Str =e oSn. next > \foulls vie? inew!i vowele Str), 4 — Olp : enkr a dhuug : ee Hels owortd © voweds are: e , 0 Paga No| 2) (bas SW) Puoquam 4 dajiwe a tivead 40 ng tere Tom output poe _in? MUU es vifimes Cuate 3 head. Oud Kun tem. nas the te Sn’ [iene Ds 18 dread afin” Kelle “ 1ookemes. Gi) 1294, Hyread. Pfnts ” Guied? Morning” 20 time (iii) 84 thyead Prints * SiviMam” 30 mes, fmport _jowa. fo. * » T uv : Emp ort jaua.1ang. Sting. "5 I v ovsins! cass emo \ exknds. thread ; Sting msque” os tnt p> aaa _( string sq tat nd. i. Hats. m3q = m3q > Hun C=" ng Le 3 pes yaid sun 0? fl hey t d for ( fA = glee Wis la). im System. out: printin ( msg 4 tie Himes” ; Cott ( Envepiton ett = Plubilt oe elaes abe ‘ me Ataliy. vod » maitn 6_ (rng 6 ares ) t fat = Integer. parseine ta demo di =" new demo. ( Helo nds dl. Stayk bd.5 demo dr = new demo (" a Morning’, # +10) d2- Start Os; demo dd = demo: C2SIR[ memM", nt 20)5 « Start Oy 5 86) Wie o pana _| ‘dat _mplements a mutt madly Iogptization tad Inad tice threodls = [St th quarate Handove " y wl i Value Le diukegty vu ovr10 accoud aud 4 Ve Lo mo. duc ted pone 37% paneacl Lill padi Hire vaUre 6 mabe: i mp ort. wan whl. Randomiiy omsh Coes Aguare wrttndls = Thkeaof ‘tnt © Bquore Cink nro vse w= 5 pubic votd sun int Sqy = UF my System “Out: pulaHn C" Square isi" ++ “=” ' 5 Hy + $qx)d > [ Chass Aube extturds Lreod d «fat w5 | tube ( int n) I wenF no] da, | puso void run () (Pecono] 4 a) (Gee tak wb = Uh KD __ System owt prfntin (* cube Ie te 4 = ! 4 wbd 2 } Claas Number 3 t wctends _Threod public voud youn t Random yvandom = new Kandom (5 | for. Cink 1205 TAIOy itt). “fink Tondo mfnkger = random. nextInt C100) 5 System. out: prinin Cy 4 Ranolom Sakeg es genvxated + Van dominkes er); Square $= new’ Square Lrandontntegerd , 8. Stout 0) 5 whe o= new ube Crrandorntateyr) s c- stark O35 Tou - } i _—Thacad - sleep C1000); ba 2 Coes ( Exception ett 4 } public. Atttic votd main CString C1 ange) 7 g Number num = new Number 05 num. Start 0), 3 site a pane _poungarn iw _dubsices ssead pe 6) 600) iw | he tw overse! gubten _purom (00 40 |! auy thamge ne mame 1 bead. \ | im port 4Ow a. fo. #5 tmport Yaqwanlang: ‘Shot , 7 Puchi cles { 4 bo 7 Past Atatin “Voldman (suing 63 Cas) “Thread Hakead = new Tread. 1 for(fabie 100; fr=ty i} n ~ Sesto ¢ Tasca. nncutTintad v.] ame +” % ae Foden tp (1000) +, NN Claterrup ed Db Oy 7 ee cinwttiben tose 2a4 ()- SetName ¢° Thxtod. errreutTrreadt ). getName). equals (" Forward!) 2” Reverse” t “forward” ), a ~ pos thread. setniame (~ Forward") 7] eae Atouk () , a) Ss ae ASSTGNMENT- | 6D weit a _ yam ; ; | a create ! oe puayearn i Ae fathaucc Inout —. date | a. Sequel é. Haplay ovt 4owa. io. #5 ort Yava. sql. * > tim port) “zowa. lang. £5 i § 1 Publ, cabs menu! —E———e IPBC_Progicam: ing. i (a jor 25 | i t t mp np f { } pubut Atatio valk main (Shing 3 args) Connection. ons : Realeset _ ¥S + Statement St > fant 0. th, String nd, Pers Shing. Sql > BufferedReader by = new BulferedReader ( new) InputStream Reader System. in Ds ’ mes Tease forNlame (1 wom. mysq) 4dbe.Dstver")s othe Dsutver Manager -gerCannection (" pabe : eq]: Locagwost \: 3805] couege *,\"vopt”,* vot’), at 0 =! co. createStatement Co” Sustem. out. printin C* connected ")5 Sql= "create table Stud (rn0 MEG), $name Varchar "(20D 5 per vardnar (2095 Fst. exeoute C sql) > a = a do iu { 408 | System . out: pink Cl __ insert") System, out. prin (2. “update Js System. aut: printin (°3 Sleauel~) » stem. aut: ipofatte ("4- oerete ")> System. owt, prinHa (" 5. aa 5 Susktm. dat. printla( "6. . ewe GJ sn System. aut Eenbln: ("Cuter teetune ch = Inte er. paxserat C br! readline O). Switth Cth) = case ti. — System. Ou. siren (" eutth tire _ATudent SAUL No nome and percentage ") As f 10 = Integer. arseint (br. veadline 1), na = by. readline Oo per_= br. readline 0» String . insert =” insert into Skid values Ci ano +" “tnat’ ',! Pe peri’ Jaye, i K = St exeurte Update ( fnsert), / felkro) ' 7 | 7 System. out. printte Co yews second fs \ ; inserte lt "> . | | ~ beaks - | cose 2: - System. ot: peonttn (* eter the rou 20 Utils ay Wamt +0 apabes Ds fat r= Faregen, pastsetnt (br. veaduine ()); 1 Systern ut. ( eutey Alideut name ds String nam = by. readline (3 Sysieh, Quit - Pruiakn ( eubtr pucentage “)s Shing pert = br. readline (5 Strin top = date Stud Sek Snamez(/ "tnam" | whebe "rno = "tas K= St. re tee MC Kro): : sapaahet Oe ee Mod és > beeak 5 Case 3° System. out. printio (—euith. iideuk att Ao Securely ") fat wr = Integer. paxseint (br. aetadline 0), Shing se = “sett * From Stuck Where TAO = Yt Tee wile C78. next) { Cx. gektat Cit." Le" + vs, gusting 0) + bt geshingC3), 4 buear 5 (ase H: Systere. out - pains ln (.* enter Mideut oll no Au waut 4d delete "+, int or= Inequs. posssernt ( br. yeadline oO); {ose J “aelele fuom » Maik Moths 70 Sti a4 hz = tay Ke St exerute Lipalade (A): (hOK ro). a aut: priate’: yas seco £v. oleloted*} becca 39a case 5: TS= St. executed uy (" Seteck * from Acid"), pAle C78» next OF L System. aut: fan (7S- eiar iy © n\e" + s_getShing C2!) + "LE" + #8. getstring G))5 mt j , case 6: v Syskem. exit C0) 5 4 i i wwe (W!= 6)4 Carn CE acepon € ) ie Syskm- ou: priatle (eds LED ae ~ 4 “ 3 : a De cake ataclenk L "ete wuthy atbucthaes end Snome »feh- t im port fowa. fo. %s | tmport fawn. sai .¥ > tee ae OU i ‘public atatie void orrain (String C3 oS) 5! ‘wnnection o> Statement $ 5 Py I, d “ uass. forName (com. mysql. qb0°- Oviver” )> C= Quiver Manager. gercihinention (7 polbe = ervgsql I Covaltvost : 2806 / college" woot”, " rode"), System. owe: prtntin C” Potnbase connected, , Jis= C. crcabeStatement 023 Sing Sql =" Ureate table atadent( ino tnt, Sndme Vaxchar (10); per tak)", By Facade paste (991 4s A S$: Wose 1c ose Os) TS Cakes CE nceptton eo 4 System. err. prfattn (25 ¥. T — System out: printn ("Sable wleated “Ds 3 a i, -~— 83) | Wits “a gown po ee II | able white aealece To Et Ename "anol: Aalasid oo NS ! To eabr Papa y Ox L—_| See ane Lt __ tmport a. to. *. bi - Public ckass demo i Lo | peed Atalic vord matin (String CI A id | Connection 65 Statem enti..Sty Rell Sek F835 Chass. forName-(" com. C= Brive manager, qeraal ‘Wtattrost. + 3306 / enploy ( _St=_C. CreateStatemen't S | Syskm. out. paintin (° " datecbase. “onnected); cafe Bidar 3, si git does, \ JE oo a a T T 4 a Sing Creat = Create able Ceno fatlu endme vorehar lio), gat Varenay (10))"; St. exewte (oreate) Wlumn = Sat”, System. Out. intl [* System. out. pufnttn: Ctoble Created "); “string del = "alter table emp drop a \ “onchose ; | Ulumn duo ped’ 3 ye LEneeption e) 7 pouiatln Cds: a any a Q4) | pucite a. pave gtom' +0 delle tre details oa by h tather bddume Tear “table Owithr aleuibutes tno foams Qnd Aub eet Tapert Lowa. to. *; import foun. Sql. e 7: i Uaas fet fal Atatic _vold main (Bring ed axgs ) ALS | S terrmeéSion Gy) ¢ Statement St Reautt$et 5 fnt_+no » K> Stin Sub, tname » Bubfercdl Reade br = neo BulperedReader Cnewo Enput StreamRead en (Syst tas Lh, v t ows. for Name (tom. musal. pdbo. Driver“); [C= Driver Manage. qgtttonnetivn ( 9" adbe : musa W! l lowthogt : 93306) couege “, Vr root", Soot"); Pagan] ic | St= C-oreatesinkement Odio. x : tin" Database Cueated"): 3 stem. out. prin Son out- peuantin Co euttr tno, name a), Sus : ~ Sub "> j tno = Integer: parseint (by. readline ©); t+nome = be. reoclline © + sub = br. rtodline + Shing tngert =~ insert fnto teacher Value i opt Senememin , tu Subs mtg Kes SE. exeuute Update Cinsevt > ie (K>0)d se System: ot: printlo (- spouse eeceowed FS uusocted “Js ‘ | (tebe —— System. Qut- fntle (* enter +o Wont J do aele . oo f 7 | tnt ty = Integer farsernt ( br. readline ty, String az ° “delete fer Halli Ltr he qo © tts | K = St. execute Update (d2>5 Z if Lk +0) | ye out: Pitetln weecnud Lb 7 Ss St - exewte Qu “Select * from feacher ‘ bile (7s. next ODE Fl ysiem Ouk- Prxntin Crs. qerine(s) t “le” +45 | gersining (2) + “Ve trsgetshng (33 - Popono] (oa a X tot CE Hon €) j cep ro : ystem Out peut (Ce), 2 5 a 7 3 V HN ASSIGINMENT- 3. eal TP ont Soler . ———— Qn) | wate a 0, 3 : — ———_} Puintiuiter pyr = ves | pw. peintin (" “Zbody > gn for MALiOn GeLueh Zibb clal> “do y (Zor > Sour Name: "+ eq. ger fof “geuuername 2? in (7 Shr? Sauter Pouk ' "+ veq. get pw. prin Pg ever Pome) > len. énHn UC" cbt > LP adduess +" + tq. Remote i? P ; Addr OD» a pr puddin (1
Cent BLOWS: '' t req. gerrleader (" UoeH - Sr | pe putin ( Hello © Java! Zthi>'); ! pi: uatin (" ” )5 7 p - Wose (5 } | Fa] LL et ao] | 6x) Wadite 0 Seletek —plunatiam 25 dlp il tue atl (Pro, Prame, Phddr. L Page , atuan ie ta_@ fab ular fx = import aio. * | tmport qokauta : Geunteh Sentetbacepti on fob powr pakouote Semel. fo pow © powa. ql. fe : —pudolie hans potent eetendls Hitpoenntet } -puluare Atatic psa Lonng, Serial Veriqus YEO = (Ls ] ae Wonnection on» rivare Statement $3 “private ReoultSet 85 puotic. vovd aoe [Rp Ss Rant ay fet oh enatsthaspanse ves) throws! Semler pepo 0) enception eS. Getton tent Type Ctext/ hem")-5 Pruat lactone out =. 1eS. getWeiter 6) 5 | iy tt ae inwame © tom. mysql. C7. fate Doriver'); = Diver Monagen- gertodnection ‘C Ci tobo » mysql : n ocalbatat © Hospital 73306", * wor’, “rot” \Y 3 = ton. Ueeatebtatement Os vs = $- executeAuerry (" Select * fom potent * ay ous. printin (" Ztable bord =| hacolor = yellows'+ " Lhh> Polient-n02ith> namecita> Ktn> Qddy Zl th> age lth> disease (Poa2n0 > (oa 9 A atile (v8. nextt)) “Qué NEC" Ltr y+" +" " + 9. getSrin "Std >" +78. GeeLor(') +" Zig. 4 (2)4" eitd> + “ftp >" 404s. gush) éltd>" + “Ctq>" +48. gettnt (ud ” t " + 15 _ GetSwring (5)+ ZItAS” HO Stet es Ly) 3) 7 Que. prtot Gs Puoduet Details tkitfeds Zoo rTM name =" FI" action = * Pabieuk * { a metnrod get" > \ | fatient Detacls. | <1 bo 2] htm) > | tite a payee mnake use Oy tmp hat el. foeaceng — np ob |< % Gpose Tenport = tp anis uli. Catewder" 1 | | Colendth ' C =~ Calewdars guiastance OU: } int dd = -ger( Calemolas. DATE) > i} | int ~ penne, qer( Cateudes. HOUR. OF. DAY); | | tnt m= ¢- Geel (alenda..MINUTE) » |_ int $= C-Get( (alendu.\ 9et0nd)» out: printin ("IN Dates "+ddt” |v Time: "tht" noakMtee es 1S is Sting 3 pee: = weguest. get Context Potty (2 » Qut- usp Hn (" ioe Poti : “pat )» = new "Cookie ("0") Patt.) » Saari onge. tee te (Cookie) < pvt 0 Cookie. Bdded’) », | =“ prinkn ("tn _Wnfig "D4 fiat prints Clots ubtig.. getieuadettlamed) due priatin Clo Bpplcchtion eat pleat lo" ¢ Cappliion questa Info. hs ramp —~ ~~ Date fe SR ge f——_ Tow fb . > site a fp 40 tne Fe a EF ll dime - ayy & ~ | —— ———_| 1 Ga

Z input. typeve ” dex” pame = Lusernam,” 2 ER ba 26) a t nik pzintla C good. Apter ngim ae name?) ie (ba > 16) ; ae Out pludntin C* L460. Evening eee, 2 tks y! ue a ceaind bs Ogplitatin. to b (Td, Tname » Gang) ol age ith a tobutar! ferro: <% @ page a =" powa” > Jase ag ia Zhead> SHee 7 Teacher Details Example LlttHe> Zl head > Lh 7 Teach Details Bator efht> Lbr> Thame + Zinput yee ="#HxtE" name *"fname'> i Etnput type =" text" Mame =" gals 2br>
Lbr>
ith Sting tid = request-aqetfaxnamucr ("Hol"); Stink tname = wequest: getfarameter (" tname’), || Pagano, | Date a | we nrequesb + getPaxam uu ~ & Stin 2 I j Sea C salting "Ds . L te Cid = nue $4 | tik. islempty U1 gp - tname! = nu &% | tname. EOE MO b teat! = nun &% | teal. isempty! I Kut: printin ( Zba> Teather §) ebcuils “thy o eut-printin (" Thame :*+ $name.
a5 WW out-prntin (2 Tid: " ttid+
"), Hi Out: printn (7 Teal i" t+ tal +" 39 I Zi body > + a Zl hehi> 4 HW \

You might also like