0% found this document useful (0 votes)
78 views

UNIT - 5 APPLET PROGRAMMING Chapter - 1 (AND) JAVA Data Base Connectivity Chepter-2

Uploaded by

Bapuji DCP1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
78 views

UNIT - 5 APPLET PROGRAMMING Chapter - 1 (AND) JAVA Data Base Connectivity Chepter-2

Uploaded by

Bapuji DCP1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 19
Unit .5 | 7 a APPLET PROGRAMMING chapler-1- ~Q Explain about different types of Applet. Apples are sel Java programs that are primly uscd in Internet computing, They ean be transported Gere ntemet from one computer to another an run sing the Applet Viewer orany Web browser that supports Java. An applet, ike any application program, ean do many ‘things for us. It can perform arithmetic operations, display graphics, play sounds, necept user input, create animation, cad play interactive games, Java has revolutionized the way the Intemet network. Java has enabled them to ereate and use age can now contain not only a simple text ora static £20 produce graphies, sounds and moving images. Signisicant impact on the World Wide Web, Local and Remote Applets em retrieve and use documents on the world wide internetive multimedia Web documents. A web image but also a Java applet which, when sun, java applets therefore have begun’ to make @ We can embed applets into Web pages in two ways, One, we can write our own applets and embed them into Web pages. Second, we can download an applet from a remote computer system and then embed it into a Web page. LocalApplet;An applet developed locally applet. When a Web page is trying to fi Internet It simply searches the directo} specified applet. ly and stored in a local system is known as a local ind a jocal applet, it does not need to use the ries in the local system and locates and loads the Remote Applet:A remote applet is that which is developed by someone else and stored cn a remote computer connected to the Internet, To access a remote apple: we require an internet connection and the URL of the applet. Oo. Oo T totemert ‘Local Computer Applet Remota Computes (Cin) (Soren Q. Explain about Applets and Applications. Although doth the applets and stand-alone appheations are Java. programs, there are styntticant differences between them. Applets are not full-featured application programs. They are usually written to acoomplish a small fask or a component of a task, Sinee they are usually designed for use on the Tntemet, they impose cestain limitations and restrictions in their design. ing the execution of the code. Applets do not use the main() method for initiz methods of Applet class to start Applets, when loaded, automatically call cert and execute the applet code. Unlike stand-alone applications, applets cannot be run independently. They are run from inside a Web page usinga special feature known as HTML tag. Applets cannot read from or write to the files in the local computer. Applets cannot communicate with other servers on the network. Applets cannot run any program from the local computer. Applets provide security by verifying the generated byte code and no memory space isallocated till the reverification process completes Applet ByteCode 74177 Reverification Execution Memory Allocation Client ByteCode — wewowrvrvvrveiwevrew wrwwwe ney ancl UNNI 4, Apple nognams in Taw Q. How to build an Applet. J maples mye o Before we try to write applets, also ensure that either the jav: ‘The steps involved in develop Wwe must make sure that java installed properly and a appletviewer or java enabled browser is available. ing and testing in applet are : * Building an applet code. * Creating an executable applet code. * Creating a web page using HTML tags. * Preparing tag * Incorporating the tag into the webpage. * Creating HTML file. * Running & Testing the applet code., Building an appletcode:To build an applet code we require two important class namely Applet, Grapinics which is available in java.applet and java.awt packages respectively. The applet includes methods such as init( ), start( Jand paint(). The paint() method displays the result of the applet code on the screen. The general form of applet code is: import java.awt.; import java.applet.* public class applet name extends Applet { public void paint(Graphics g) Creating an executableApplet:Executable applet is nothing but the -.class|| file of the applet, which is obtained by compiling the source code of the applet. Compiling an applet is exactly the same as compiling an application. Therefore, we can use the java compiler to compile the applet. Create an applet and store it in the current working directory. Compile the applet using the following code Javac helloapplet.java ‘The compiled output file helloapplet.class is placed in the directory. Many errors occur, correct them and recompile the applet agai Design aweh page:A web page is necessary to run the a java applet. A web page ls basically made of text and HTML tags, that can be interpreted by web browse! an appletviewer. A web page is also known as HTMLdocument. Applet tag: An tag must include wit The ‘ tag supplies the name of the applet to be loaded and tells the browser how much space the applet requires. I< PARAM NAME = AttributeName VALUE = AttributeValue>] [< PARAM NAME = AttributeName2 VALUE =AttributeValue>] the HTML tags to run an applet. {alternateHTML Displayed in the absence of Java} CODEBASE; It is an optional attribute that specifies the base URL of the applet code, which is the directory that will be searched for the applet’s executable class file (specified by the CODE tag). CODELItis a required attribute that gives the name of the file containing your applet’s compiled .class file. ALT: The ALT tag is an optional attribute used to specify a short text message that should be dispiayed if the browser understands the APPLET tag but can‘t currently run Javaapplets. NAME:Itis an optional attribute used to 5 Appleis must be named in order for othe: name and communicate with them. pecify a name for the applet instance. T applets on the same page to find them by WIDTH AND HEIGHT: These are required attributes that give the size (in Pixels) of the applet displayarea, ALIGNSI is an optional attribute that specifies the alignment of the applet. Possible values are : LEFT, RIGHT, TOP, BOTTOM, MIDDLE, BASELINE, TEXTTOP, ABSMIDDLE, andABSBOTTOM, SPACE AND HSPACE:These attributes are optional. VSPACE spe pixels, above and below the applet. HSPACE specifie: side of theapplet. jes the space, in 's the space, in pixels, on each AAA RRA AA a HAA HH m e RARAMNAME AND VALUE arguments in an HEME The PARAM tag allows you to specify applet specific page, AIM I the applet t alternatemarkup.lf}av: tags a ‘ou will see the kupbetweenthe available, itwille dl ignore the alte cod = “applet name.cl Incorporating the tag to htm the place where the output of the a "400" heigh e:nsert the ta pplet must appear. 00"> he page a stitle> applet example
‘helloapplet” width="300" heig] "300"> Creating the HTMLfile:Creating the HTML file with applet tag and necessary tags. Running & Testing the appletcode; After creating the applet files as well as HTML file containing the applet run the HTML file in browser or appletviewer. The appletview therefore it ignores all the HTML ta; the applet. e any java compatible web is nota full-fledged web bi owser and #85 except the part pertaining to the running of | appletviewer helloapplet.html oR appletviewer helloappletjava Ex: import B.awe import Java appiet.*: public class UserIn extenas Applet TextField textl. textz: public void tnite > { text] = new TextFserace: text? = new TextField(s): add (texta>: add (text2>: text1.netteat text2. setText 4 Public vord paint (Graphics 9} int x0, yO. 2-0: String sl. s2. s: g.drawString(-Input o nuxber tm each box ~. 10. 50): try 1 sl = text? gettext >: Integer parsetae(s1> textzZ.getteate >: Integer .porselnt(s2). ' catch (Exception ex? { } ze Ke yt S = String.valucOf (2): 9.drawString ("THE SUA IS: -. 16. 75): a.drawString €s. 100. 75): * public Boolean action (Event event. Gbject object) { repaint (>). return true: > DL Bw e +e 2@o¢ Ee Svssvvvdvdvdvsswswvoeseseeseseevvvsy ‘Nun the applet Userta using the following steps: 4. Aye anal save the program (java file) 2 Cosnpite the applet (class file) 3, Wiitea HFM document (htm file) sntols sapplet code = Userin class width = 300 hotght = 200 > x/apple> s/ntals 4. Use the appletviewer to display the results When the apptctis up and ran ning, enter a umber into cash text field bex displayed in the applet ‘area, aan then press the Return Key. Now, the applet computes the sum of these two aumbers and isplays the result as shown in Fig, 1412. snptettoades stated Q. Explain about Applet Life cycle. Every java applet inherits a set of default behaviors result when an applet is loaded from the Applet class. As a applet states include: itundergoes a series of changes in its state an Born or initializationstate, Runningstate, Idlestate, Deadstate. {nitialization State: Applet enters the initialization state whe} ‘This is achieved by e: alling the init () method of Applet el this stage, we may do the following if required Create objects needed by the applet Set up initial value Load images or fonts Set up colors. ‘The initialization occurs only once in the applets life eyel behaviors mentioned above we must overrule the in tis first loaded, - The applet is bor: © provide any of the eCmethod, Public void init ()¢ (action) Unlike init ( may override the a “ll Se ee ee BRBvVv2wvevwees le or Stopped State :An applet becomes idle when it is stopped from running. Stopping occurs automatically when we leave the page containing the currently running applet, We can also do so by calling stop () method explicitly. If we use a thread to run the applet , then we must use stop () method to terminate the thread. We can achieve this by overriding the stop () method. public void stop() { Dead State () :An applet is said to be dead when it is removed from memory. This occurs automatically by invoking the destroy method when we quit the browser. Like initialization, destroying stage occurs only once in the applet's life cycle. We may override the destroy () method to clean up the resources. public void destroy (){ | Antroduction; Packages are containers for classes that are used to keep the class name space compart. sntalized. A package refers simply to a group of related class files in the same directory. A package is the Java version ofa library. Ex java.io java.applet javaawt ADVANTAGES OF PACKAGES; Packages are useful to arrange related classes and interfaces makes all the classes package, Packages hide the classes in a separ: classes will not takeplace. The classes of a package are isolated from the classes and inte: package. This means that we can use same names for classes classes to a group. This performing the same task to put together in the same ‘ate sub directory, so that accidental deletion of rfaces of another of two different Q Explain about Types of Packages. ‘There are two types of Built-inpackages User-definedpackages Packages in Java. They are: ‘HBuiltsin packages ‘These are the packages which are aiready language. These packages provide all most all necessary clas: methods available in java ses, interfaces and for the programmer to perform any task in his programs. javaang: lang stands for language, interfaces essential for developing a basic Java program. String StringBuffer, classes to handle strings, various individual processes. 2 java.lang package which contai There are classes like There isa Thread class to create ‘untime and System classes are also present in n methods to execute an application Uri 5 lil 54-ch Tova Database Come | Tnkyconneck, cH) mere \o are nection bls 2) more compolons 14 called ‘ Vehoas A nehoae con dishy — mamy clienls ¥ servers. Datobo Servers %— RK databoar wo repeahiy A dota Doda is shied in Ake Fh db tribles in tha dlottaboxe- To wetriue dota from dofa bo jy we raed Sone pregrams- tx ‘r Oxacle, Syboa, MySat., SQrseaveR Databom Clie! i Te progrem ene | coltod —atabou dient eh do relrive dota fran ovacle. Ex > SaL*plos: ® wh SAL Coramandl ine | te Fbniove, dob Son dobehor 33 SQL > Connect Enter Der ners" scott Ener pomAmwdd ” connected sar? SQL Fla Ww Me cNient Sofhsare in aythrr and Onoten Ayshn womeded gakobot SeaRen Poyran Is oo neko - ned to MysQl sag He simile SZ OE com om OAS, mysau commondbine* oracle exe «) Mysau: exe voll! ren Te “a senuen pogeums , cNedk -Senuen communication. Tay will chen spies bo prewi da. ae seem im Winans Tank Ponagen ° => blot i TBC) Jove DelaBose Connectivity an APT: that elt OO programmer to wnle Sava programa do connec A a data ete So dada From tHe dota bar & ob) ae é a m & Java progtem: ee Fi « ¢ ¢ dgiabor clied- ‘— Sower, Miceo soft hos OP BE Coren dobbo cormechviy) comneck lo © icvo Seyvars: o s0Bc gont of Feats Stundand Edin ChwvaS6) TDBC APE 6 vases ID BC dawerr A connect Xv Joka bow » Thane ans. z © G 10% diver’ * c hye c dsjwen 3 Coady bls soe r DBC): “ vy) oBc- ope i bat vr) Rokhue Anwo- ie ceed Biedkrda Ube ie m foods Drive) Crmiddile ore appaDvend, 3) antes mee oe sn bus at Follows) re acces deka bow 7 S (SPEC asi) dona) > | Peta bas : a Gave pe] —— te Sa-S ot package corluins “chat B inbr faces fh c JOB APL © Exo dose bork mds ual ae beconee: Cc ging, ML commend he connect ond hlige dada bade = %& cabled APT i ees L decument seek docomen featur YAH & & @- Connechng to oracle dota bo ilk Jove. Yovse alog() Sunclion te comect with oracle 2) ure Oexecl) Fonchon th execvle a command. 3) To disconect from oracle vs ologsff C) fonchin, | Conne cling fe MySQL database olf, java ‘) vse ) r) Use mysqt- execuke () fonchon to execu a command D 3) To disconnect ure my syl—disconnect ¢) fonch'o, } mysql — connect () 40 connect wi ft MySQc. p ODBC - Copen dalabax commecty vity) BP ODBC 13 A document +thad Combing — Common Poneks ni BT Commvnicale WIA any database. If an x Y ov 071 Bath; > cveakes a sf dspendaney o ODBC docment, iro, caldsct” Bp OVBC doiven. > - bw a : TF amy slo ceothing ty JOR APC, ik 14 caltodg WGC chivers We com connect B opbe oring, TPBC-OD Be dyiiven foot dod. by Soh m D Aye jure a WDaleng th oracle dodo soy » 5 ° . A\Pten comacking 7 wade dudub ete, SQL> Pao ph appesy Ge can operok Ser tow: SQL Commamdy - = 1) SQL conmamh ts Craade table ® SAL> Credle fable empl 2 ith, erame wrehan Cra),); e Table Created i) 2Q- fr nr rte 4 \ x) po clde SQL Client Ue exit SQL> ext ; s To Anterty dows in ty Me emp fable the Poort ‘ SQL> WIE mboemp (geno ,\s enamre’) 5 ‘4 é Enley value An eno (9 | ‘ enkx Volt fA Chores So r \ you msaled ¢ ts oveagake addy Ran ( set >/ ¢ Enty Vals fo eno. lob « enh, Value & OER | PAC : a\ 5 3) Te save deg changes OR Commif. 4 SQL > Commit ; ‘ Commit Complete» « L) ; < S) WR seo ta conknh Ga table ow Alken ng command - < seL> selad * dren orp? s E00 Enos $ Sas let or ; - 4 ve Epdale comnd 2) 40 xd conkmba § fle we , ? oN \ Sory vpdole emo set Enama = whore eno= (al) § V YOR Lpdseed ©) + sadoke — conbemabs Hy Jadle vae dalahe command § Sac yz dolele Som emy cdr @0 =o] ” : \ vous dodoled,, s +) + vode the Choma, o%® — llback s gar > vol Kae | BA\ back complele » oxking oll, My sau Delahaye, & me MYSBL TS free dalaba sofhane «TY is proviled by 9 MYST com. In MySQL I} i powable be creole moltiple T+ bes fella commardy Ss vw @ dolahas Tt hay mys@LS_ promph » 2) Vo see dalaboyey Wy MySQL - Cormamd. 14 wnysgi > Show databers Data Bays my sq Tear 2) be cam rt amy G He dobabor bowed on He sable MySQL > UAE sesh) Vekubore changed . 3) Nous fe ven ble Oe Common mysar 7 Shoe Fables’, ~—_ —_— = rl OOO TrhlCUTC Table — in-tegk Tv cok robles oF comamd, CSamc oracle ) eo et rey > coke dable emp C ene wh, ename than drs) ) 2 Query Ok ,O Yor affected. 5) to inph tous iin myYsal wx Ommamd meq) > vient anby emp Value C rol, > nc!) “ arr Of, VO sow affected , we peed ose common Av que YAR your in be dable - ¢) Te Saplay tea conten bs rable, ve commameh wysy-ySelecl- fren emp ' eno © Name ro} xx / lor YY i (og, zr SVs gol FR GV One the able comberf vaingy command YSIL> opiate emp see ehame - gq! whens eho = 16)" BLY OF, LyW9 offer feck ~ 8) re am dele tea fable conlernse valeg Comer f MIL > delle — fen ENO = [a3 - Remy of J | vos affected , 7 ™ysqt > Quit * ee > Stages in a WBe Progam co hk lowing, oe shagey Iq Qa Prey 2am ers hile wens IDB - | 4 Ragiatering fhe doiwme- A dale boxe bie 1) § She con-karrng Clos % inkr faces Nien MCOBing to § ~ é TB APT - . A a : on ‘ . oun § ' on object te doiven i) “By “_ ” a creale an object te drive, ‘ . Sus: lous» driven KdheOhbe Daver , 03 Shan below ‘ eee 4 Daiu Obj = New sun yhbe oie gabe sweat)’ Svh “Wbe -odbe “be Odbe aor - be ‘6 > @® Te Aecend Woy xe requaly ey by by he yepasier Doren ( ) makhod Clay THA og, folly Sendancy driven clay a Dawoon Mamagerr Driveallonags, - segisfoDaissen( hes svn 'flbe. odbc Mba beDaive ()) 3) Te Md Woy AD reafalen Abe dover clay name de dinoctly to faNomne() mokrod of * class. fa Nome C* sun. jdbe oWke HbeOd beDaiven” J; K) vse get Propenty) GQ Sysfem clos to seceive the drivan Nownd - Siving dram = System geb propenky c’ di vex) : Clan fi) Name Cdrarne) * 1) Sennecting te 8 _dalnbew'S— To conneck to databot, we thal Kno 3 hing. ) URL A tre dakabaye yD VR@ mara | 2) folgwad. 2 a a D BsTo tonne Ye __ ovacke _dalabare*- wx OM Command 3 g > D Doyen Manages» ge Connection C jdberodbe : ovadsn”, Scott u yigey"" 4 Orden veprernds dokasounce a ' Js Seok WH wie Nome ai 1A ponwod. Pike enecok SQL Sbhwenbss — WE shorld go% SQL shRmeds to exeche Querry () 2 ear Weed which V2 Wy Resul}Sef clots - b _ — oe ek Bie oe creale stebment -To execute Abe atalinent Fins cveale skdment obyect Skarmen} stmt = con. orele Stabrnent C) and, ton; Woe should pS@L stohnent Ae execo# Update () method \ —e lnk wz stmb-execvieipate (ereale Aable emp no run ben ; gPRnePr anne 7 ener Werdhoe a Fhe 1 veproygmis de vo -Q- mot “Updated. “YG Fe abeve Alatmenk 1 vd £4 Select sbitmentytnon sleet & golock stra on telpful b> retriea data fiom dota bow, 6 ———— Nen ~ Selec gabments/— Tye rbreds of vied bh change § a Tay jie conte Ex + vpdele , \nignt , Del oft te. € ste RagltSef hos follwing rratvoda- é \) bopleam rox te) s 2) tht gc Powc ) § 3) Shing gerStting C) s 4) ine gakTnkO) 5 5) Sloat get Foal ) § S) Dele gekDale C) ‘ s 6 ‘ a. ) . ig Relieving Me Yesvltas, — & y —__——- s##$#———_. ; The wervlts obimined by execlting He SQL stubnenh ; com be shed in on object wath te lelp & y —-_Merfoces Co) claws Gke Pasol{Sek , ResultSet Mela Dae ; and — Daa bate Meta Bote - YY) Ciding Heo connechon! — ) we shoold clye He connechion. behoeom he. ) Jonon program ond He Jobuboie by owng cl&eC) y Wethod « . eee con a cle) 5 Sys & Gerwlt setsr— 9 WolkSet 1% an object Hak contuins tte ae > rvesolks dy executing a SQL shatment on a dedabaic. PD Tog ow zu fyper db yersolt Aeks . B §) Farad Rervltset DB 2) Scelloble ResultSek - Stahment shmh < con» cv@akeStatmentC ) / PasslbSek we = stb, execot Query Cselect © From emp"): te yerolts gar available iv vee), we com whoiene 4te uy pe cee Hak A Rte Seale ees cere ec FF we wake welaie fe dake WW ¥Yevense ncdtion He 62 Yt Serollable esol pre > move in pe dincchot: be cam apecity “Tyla sewlt ref Follows Resolt Seb . Type - SCROLL - SENSTTIVE ResoltSeb - TYPE _ scrour INSENT TrvE Te cam eseseeoewvtus eee

You might also like