Basics of Applet




                   1
Objective

On completion of this period, you will be able
  to learn
• Basics of applet




                                                 2
Recap

In the previous classes, we have studied about

• The various I/O streams and classes

• How to write console based Java programs or
  applications




                                                 3
Basics of Applets

• Applets are small Java programs that are used
  in Internet computing
• Applets
  •   Transported over the Internet
  •   Automatically installed in client machine
  •   Run as part of a web document
  •   Applets can be run using a tool ‘appletviewer’




                                                       4
Basics of Applets       contd..

• Applets interact with the user through the AWT,
  not through the console-based I/O classes
• Clients download applets via Web browser
• Browser runs applet in a Java Virtual Machine
  (JVM)




                                                5
Basics of Applets contd..

• Applets can be classified into two types
  • Local applets
  • Remote applets

• Local applet
  • Developed and stored in local system
  • No need for internet connection for the local system
  • Local directories were searched to locate the
    specified applet

                                                           6
Basics of Applets                contd..
• Remote applet
  • Developed by someone else
  • Stored on a remote computer connected to the
    internet
  • Our system needs an internet connection
  • The applet is downloaded into our local system via
    internet
  • Run it on our system


                                                         7
Loading of Remote Applet



      Applet


                             Internet



Local Computer                                        Remote Computer
    (Client)                                             (Server)

                         Remote Applet

                 Fig. 53.1 Loading of remote applet

                                                                   8
Web Browsers Requests Applet

1. Browser shows      web
   document
                                              4
                                                                       4
2. Web document contains
   an applet tag                   3
3. Web browser identifies
   the tag
                                         Client                  Web Server
4. Client computer makes    1, 2         Computer
   a request to web         Browser showing
   browser via internet     web document

                                              Fig. 53.2 Request for applet




                                                                              9
Web Server Transmits Applet along with HTML

5. Web server locates the
   applet
6. Sends the applet code to           4
                                                                         4
   the web browser
7. Through internet it is
                            3
   downloaded to client                           7       6                           5
8. Applet is executed
                                 8    Client                                 5
                                      Computer
                    1, 2
                    Browser showing
                    web document
                                                                    HTML, applets etc

                                          Fig. 53.3 Applet downloading


                                                                                 10
Some Points About Applets

• Applets do not use main() method
• They run in a browser
• They cannot read or write the files from the
  local system
• Applets cannot run any other program from the
  local computer




                                              11
Some Points About Applets contd..

• Applets are restricted from using libraries from
  other languages such as C or C++
• They cannot communicate with other servers
  on the local network




                                                 12
Discussion
• What are the differences between applications and applets ?

                       Applications            Applets

 main() method         Needed               Not needed

 Run stand-alone       Possible             Not possible

 Access local files    Can access           Cannot access

 Run local programs    Can run              Cannot run

 Internet connection   Generally not     Needed for Remote
                         needed               applet

  GUI                  May or may not         GUI based


                                                                13
Summary

• Java programs are two types
  • application
  • applet
• Java applications are the console based
  programs
• Applets are web enabled internet applications
• Two types of applets
  • Local applets
  • Remote applets

                                                  14
Quiz

1. Applets are console based applications
   1. true
   2. false




                                            15
Quiz         contd..

2. Internet browser runs Java applets
   1. true
   2. false




                                        16
Quiz         contd..

3. Java applications are web enabled internet
    applications
   1. true
   2. false




                                                17
Frequently Asked Questions


• Explain about Java applets
• List the differences between applets
  and applications




                                         18

Basics of applets.53

  • 1.
  • 2.
    Objective On completion ofthis period, you will be able to learn • Basics of applet 2
  • 3.
    Recap In the previousclasses, we have studied about • The various I/O streams and classes • How to write console based Java programs or applications 3
  • 4.
    Basics of Applets •Applets are small Java programs that are used in Internet computing • Applets • Transported over the Internet • Automatically installed in client machine • Run as part of a web document • Applets can be run using a tool ‘appletviewer’ 4
  • 5.
    Basics of Applets contd.. • Applets interact with the user through the AWT, not through the console-based I/O classes • Clients download applets via Web browser • Browser runs applet in a Java Virtual Machine (JVM) 5
  • 6.
    Basics of Appletscontd.. • Applets can be classified into two types • Local applets • Remote applets • Local applet • Developed and stored in local system • No need for internet connection for the local system • Local directories were searched to locate the specified applet 6
  • 7.
    Basics of Applets contd.. • Remote applet • Developed by someone else • Stored on a remote computer connected to the internet • Our system needs an internet connection • The applet is downloaded into our local system via internet • Run it on our system 7
  • 8.
    Loading of RemoteApplet Applet Internet Local Computer Remote Computer (Client) (Server) Remote Applet Fig. 53.1 Loading of remote applet 8
  • 9.
    Web Browsers RequestsApplet 1. Browser shows web document 4 4 2. Web document contains an applet tag 3 3. Web browser identifies the tag Client Web Server 4. Client computer makes 1, 2 Computer a request to web Browser showing browser via internet web document Fig. 53.2 Request for applet 9
  • 10.
    Web Server TransmitsApplet along with HTML 5. Web server locates the applet 6. Sends the applet code to 4 4 the web browser 7. Through internet it is 3 downloaded to client 7 6 5 8. Applet is executed 8 Client 5 Computer 1, 2 Browser showing web document HTML, applets etc Fig. 53.3 Applet downloading 10
  • 11.
    Some Points AboutApplets • Applets do not use main() method • They run in a browser • They cannot read or write the files from the local system • Applets cannot run any other program from the local computer 11
  • 12.
    Some Points AboutApplets contd.. • Applets are restricted from using libraries from other languages such as C or C++ • They cannot communicate with other servers on the local network 12
  • 13.
    Discussion • What arethe differences between applications and applets ? Applications Applets main() method Needed Not needed Run stand-alone Possible Not possible Access local files Can access Cannot access Run local programs Can run Cannot run Internet connection Generally not Needed for Remote needed applet GUI May or may not GUI based 13
  • 14.
    Summary • Java programsare two types • application • applet • Java applications are the console based programs • Applets are web enabled internet applications • Two types of applets • Local applets • Remote applets 14
  • 15.
    Quiz 1. Applets areconsole based applications 1. true 2. false 15
  • 16.
    Quiz contd.. 2. Internet browser runs Java applets 1. true 2. false 16
  • 17.
    Quiz contd.. 3. Java applications are web enabled internet applications 1. true 2. false 17
  • 18.
    Frequently Asked Questions •Explain about Java applets • List the differences between applets and applications 18