SlideShare uma empresa Scribd logo
1 de 18
1
Presented by
Mariena A. A.
Asst. Professor and Head, Department of Computer Science
Little Flower College, Guruvayoor.
Java Programming
Java can be used to create two types of program
1.Java Applications 2.Applet
An application is a stand alone program that runs on your computer
under the operating system. No need of other softwares to run and
Main is the beginning function of application.
Applet is a java program that runs on web browser and embedded on
web page. It has strict security rules that are enforced by web
browser.
Java applet is a tiny application program transmitted over the internet
to users in the form of java bytecode and executed by java enabled
web browser.
It provides interactive features to web applications that cannot
provided by HTML alone.
Applets do not have main method.
To write an applet program you have to derive a subclass from Applet
class and override a number of standard methods. 2
Working of Applet
3
Applets
Browser from the client machine gives request to the server and server returns the
webpage.
If the HTML page contains an applet tag which includes the class file, then browser
displays the webpage and executes the applet program contained in the webpage.
Applets are run under the control of a browser.
It can’t access the resources of native machine.It access the resources of browser.
Import two packages because Graphics class is a member of AWT.
We are embedding the applet class file into webpage using HTML file. Use Applet
tag in the HTML file and specify the class name and the width and hight of the
applet.
HTML program executed by the browser and class file executed by the JVM of the
browser.
We can execute with the help of Appletviewer.
Compile using javac simple.java
Appletviewer view.html
4
Example
5
Applet life cycle
Already inbuilt on the Applet class. Redefine the existing method by the
technique of override.
6
Applet life cycle
The lifecycle of applet: The browser calls four methods of the applet class to
execute the applet.
Public void init(): It is called once when the applet is first loaded. The body
includes statements related to variable initialization, object creation, load images
or sound files, set up the screen, get parameters out of the HTML file. After the
invocation of init() method the applet enters into the born state.
public void start():This method is automatically invoked after init() method.
Unlike init() it can be invoked more than once. It is called every time the browser
displays the webpage containing the applet. it often starts the threads. Plays sound
files, or does computation. It is executed when browser is maximized.
7
Applet life cycle
public void stop(): It is invoked automatically when the webpage containing the
applet is closed. After this method applet enters into idle state. The user can stop
the running applet by invoking stop() method. It is executed when browser is
minimized. For ex: stop playing sound files and suspend any threads.
public void destroy(): After stop() it is called. It is invoked to remove the applet
permanently from the memory. It releases all the resources held by the applet.
This method is invoked only once during the entire life cycle of an applet. The
applet is dead when this method is invoked. If the browser needs to display the
applet again it will reload the applet and call the applet’s init() method.
Again we have to call init() to initialization.
8
Applet life cycle
9
Example
10
Example
import java.io.*;
import java.awt.*;
public class FirstApplet extends Applet
{
public void paint(Graphics g)
{
g.drawstring(“My First Applet”,25,50);
}
}
The applet begins with two import statements. The first one imports AWT classes
and second imports the applet package. Every applet you create is a subclass of
Applet class.
The class should be public because it will be accessed by code that is outside the
program. Inside FirstApplet paint() is declared. This method is defined by the
AWT and must be overridden by the applet. It has one parameter of type
Graphics.
11
Execution
Applet could not run its own. It needs to be inserted into the HTML document
that contain applet code.
HTML document can be executed by web browser or appletviewer.
<applet code=FirstAppplet.class
width=600
height=250>
</applet>
To run using Appletviewer we have to use the following in the command line.
AppletViewer FirstApplet.html
We can execute applet in two ways
1.Using java compatible web browser( like execution of HTML file)
2.Appletviewer
12
Execution
13
Example1
14
Execution
We have to compile this program using javac HelloIndia.java
Take notepad and type HTML document
Save the HTML with the same name of the class and run in the command line
using
Appletviewer HelloIndia.html
15
Example2
16
17
18

Mais conteúdo relacionado

Semelhante a Applet1 (1).pptx

Semelhante a Applet1 (1).pptx (20)

Advanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.pptAdvanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.ppt
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Lecture1 oopj
Lecture1 oopjLecture1 oopj
Lecture1 oopj
 
Java
JavaJava
Java
 
Java applets
Java appletsJava applets
Java applets
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
Java applet
Java appletJava applet
Java applet
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
JAVA INTRODUCTION
JAVA INTRODUCTIONJAVA INTRODUCTION
JAVA INTRODUCTION
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Till applet skeleton
Till applet skeletonTill applet skeleton
Till applet skeleton
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Java Applets
Java AppletsJava Applets
Java Applets
 

Último

All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxjana861314
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptxRajatChauhan518211
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 

Último (20)

All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Engler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomyEngler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomy
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptx
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 

Applet1 (1).pptx

  • 1. 1 Presented by Mariena A. A. Asst. Professor and Head, Department of Computer Science Little Flower College, Guruvayoor. Java Programming
  • 2. Java can be used to create two types of program 1.Java Applications 2.Applet An application is a stand alone program that runs on your computer under the operating system. No need of other softwares to run and Main is the beginning function of application. Applet is a java program that runs on web browser and embedded on web page. It has strict security rules that are enforced by web browser. Java applet is a tiny application program transmitted over the internet to users in the form of java bytecode and executed by java enabled web browser. It provides interactive features to web applications that cannot provided by HTML alone. Applets do not have main method. To write an applet program you have to derive a subclass from Applet class and override a number of standard methods. 2
  • 4. Applets Browser from the client machine gives request to the server and server returns the webpage. If the HTML page contains an applet tag which includes the class file, then browser displays the webpage and executes the applet program contained in the webpage. Applets are run under the control of a browser. It can’t access the resources of native machine.It access the resources of browser. Import two packages because Graphics class is a member of AWT. We are embedding the applet class file into webpage using HTML file. Use Applet tag in the HTML file and specify the class name and the width and hight of the applet. HTML program executed by the browser and class file executed by the JVM of the browser. We can execute with the help of Appletviewer. Compile using javac simple.java Appletviewer view.html 4
  • 6. Applet life cycle Already inbuilt on the Applet class. Redefine the existing method by the technique of override. 6
  • 7. Applet life cycle The lifecycle of applet: The browser calls four methods of the applet class to execute the applet. Public void init(): It is called once when the applet is first loaded. The body includes statements related to variable initialization, object creation, load images or sound files, set up the screen, get parameters out of the HTML file. After the invocation of init() method the applet enters into the born state. public void start():This method is automatically invoked after init() method. Unlike init() it can be invoked more than once. It is called every time the browser displays the webpage containing the applet. it often starts the threads. Plays sound files, or does computation. It is executed when browser is maximized. 7
  • 8. Applet life cycle public void stop(): It is invoked automatically when the webpage containing the applet is closed. After this method applet enters into idle state. The user can stop the running applet by invoking stop() method. It is executed when browser is minimized. For ex: stop playing sound files and suspend any threads. public void destroy(): After stop() it is called. It is invoked to remove the applet permanently from the memory. It releases all the resources held by the applet. This method is invoked only once during the entire life cycle of an applet. The applet is dead when this method is invoked. If the browser needs to display the applet again it will reload the applet and call the applet’s init() method. Again we have to call init() to initialization. 8
  • 11. Example import java.io.*; import java.awt.*; public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawstring(“My First Applet”,25,50); } } The applet begins with two import statements. The first one imports AWT classes and second imports the applet package. Every applet you create is a subclass of Applet class. The class should be public because it will be accessed by code that is outside the program. Inside FirstApplet paint() is declared. This method is defined by the AWT and must be overridden by the applet. It has one parameter of type Graphics. 11
  • 12. Execution Applet could not run its own. It needs to be inserted into the HTML document that contain applet code. HTML document can be executed by web browser or appletviewer. <applet code=FirstAppplet.class width=600 height=250> </applet> To run using Appletviewer we have to use the following in the command line. AppletViewer FirstApplet.html We can execute applet in two ways 1.Using java compatible web browser( like execution of HTML file) 2.Appletviewer 12
  • 15. Execution We have to compile this program using javac HelloIndia.java Take notepad and type HTML document Save the HTML with the same name of the class and run in the command line using Appletviewer HelloIndia.html 15
  • 17. 17
  • 18. 18