• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Applets » What is Applet?
Next →
← Prev

What is Applet?

By Dinesh Thakur

One of the main features of Java is the applet. Applets are dynamic and interactive programs. Applets are usually small in size and facilitate event-driven applications that can be transported over the web.

An applet is a Java code that must be executed within another program. It mostly executes in a Java-enabled web browser. An applet can be embedded in an HTML document using the tag <APPLET> and can be invoked by any web browser. Parameters can be passed to an applet using the tag <PARAM> in the HTML document. Applets can also be executed using the appletviewer utility provided in the J2SDK kit.

 Java applets are downloaded automatically and run by the web browser. Any web-browser that supports Java, such as Applet Viewer, can be used to transport applets to the Internet. An applet can perform many functions such as graphics, play sound, animation, arithmetic operations, play games etc.

Applets differ from application programs in the sense that they do not use main() program for initiating the execution of code. They do not run independently but from inside a web page that makes an efficient use of HTML tags. To build an applet code, we need to include certain packages like java.awt and java.applet that contains the Graphics class that provides methods where the output of all applet operations are performed. A simple program using applet looks like:

A Java applet must be a public class. Thus, the Applet class can be accessed when the applet is run in a web browser or in the Appletviewer. The applet code will be compiled even if the class is not declared as public, but the applet will not run. An applet code looks as shown below:


import java.applet.*;
public class SampleApplet extends Applet {
  //applet code
}

Like any other Java program, the applet’s class name must match with the name of the file in which it is written.

Applets do not contain the main () that is required to run a Java application and thus they cannot run on its own; however, usually applets run in a container that provides the missing code, The main features of applet include the following:

• It provides a GUI

• facilitates graphics, animation and multimedia

• provides a facility for frames

• enables a event handling

• avoids a risk and provides a secure two-way interaction between web pages.

Note that it is possible to execute applets using the Java interpreter (using the main () method) if the class is extended with Frame.

An applet can reside anywhere on the web and can be downloaded on any computer. Applets have limited access to the resources of the client into which they are installed from an Internet server. For this reason, applets avoid the risk of viruses or breaking the data integrity problems at the client. Applets provide security by reverifying the generated byte code and no memory space is allocated till the reverification process completes. Generally, a virus cannot be hidden in uninitialized memory. If the reverification process is not complete, the applet will be rejected. Further, applets cannot do the following:

• Read or write client file system (disks) unless specified explicitly; in such cases, the Applet is allowed only in certain directories

• Access the source code of the applets; the applet’s source code can be accessed only from the original server

• Execute local programs/libraries/ DLLs on the client

• Opening network connections other than to a HTTP server: applets only talk to the server that they live on

• Finding information about the user such as user name, directories and applications installed

Applets are very useful for the presentation and demonstration of a concept in an effective manner. For example, an applet designed for explaining the bubble sort algorithm shows visually how the bubble is moved during each pass of the algorithm, Usually, applets interact with the AWT controls and it is necessary to import the awt package (java.awt*) and also the event package (java.awt.event.*) for event handling. Input/Output streams are not commonly used for applets for the purpose of I/O. Figure illustrates the byte code of an applet running at a client.

             Byte code of an applet running at a client.

                                       In Table the main methods of Applet class.

Method

Description

destroy ( )Method triggered by the browser or applet viewer to indicate that the applet should release all the resources used .
getAppletContext ( )Returns the execution context of the applet allowing interaction with the browser.
getAppletInfo ( )Returns information associated with the applet .
getCodeBase ( )Returns the source URL of the applet .
getDocumentBase ( )Returns the source document for the applet.
getImage ( URL )obtained an image at the specified URL .
getParameter ( String )Gets the value of the specified parameter.
getParameterInfo ( )Returns parameters associated with the applet information.
init ( )Method triggered by the browser or applet viewer to indicate that the applet was loaded.
resize ( int , int )Resizes the applet for the given values ​​of width and time.
showStatus ( String )Displays the given message to the window or the status line.
start ()Method triggered by the browser or applet viewer to indicate that the applet should start its execution.
stop ()Method triggered by the browser or applet viewer to indicate that the applet should stop its execution.

import java.awt.*;
import java.applet.*;
/* <applet code="NewApplet" width=500 height=200> </applet>*/
public class NewApplet extends Applet {
    public void paint (Graphics g) {
       g.drawString("New Applet Program", 20, 100);
    }
}


The statement below draws the string New Applet Program at the pixel position (20, 100 )


g.drawString("New Applet Program", 20, 100);


To execute Java Applet, appletviewer is used. We pass the source filename as an argument to appletviewer because it will read the <applet> tag given in comment part of the source file. From there, it will find which class has to execute from the attribute code, what will be the width and the height of applet window, read from width and height attribute of <applet> tag respectively. The screenshot below explains the compilation and execution of a Java Applet.
                          What is Applet
The screenshot below shows the starting of an Applet.

                          NewApplet Appletviewer

You’ll also like:

  1. Java Applet – How to Shapes Drawn in applet.
  2. Draw Arc in Applet Window Example
  3. Textarea in Java Applet Example
  4. Check Images in Java Applet Example
  5. Find in Java Applet Example
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Java Tutorials

Java Tutorials

  • Java - Home
  • Java - IDE
  • Java - Features
  • Java - History
  • Java - this Keyword
  • Java - Tokens
  • Java - Jump Statements
  • Java - Control Statements
  • Java - Literals
  • Java - Data Types
  • Java - Type Casting
  • Java - Constant
  • Java - Differences
  • Java - Keyword
  • Java - Static Keyword
  • Java - Variable Scope
  • Java - Identifiers
  • Java - Nested For Loop
  • Java - Vector
  • Java - Type Conversion Vs Casting
  • Java - Access Protection
  • Java - Implicit Type Conversion
  • Java - Type Casting
  • Java - Call by Value Vs Reference
  • Java - Collections
  • Java - Garbage Collection
  • Java - Scanner Class
  • Java - this Keyword
  • Java - Final Keyword
  • Java - Access Modifiers
  • Java - Design Patterns in Java

OOPS Concepts

  • Java - OOPS Concepts
  • Java - Characteristics of OOP
  • Java - OOPS Benefits
  • Java - Procedural Vs OOP's
  • Java - Polymorphism
  • Java - Encapsulation
  • Java - Multithreading
  • Java - Serialization

Java Operator & Types

  • Java - Operator
  • Java - Logical Operators
  • Java - Conditional Operator
  • Java - Assignment Operator
  • Java - Shift Operators
  • Java - Bitwise Complement Operator

Java Constructor & Types

  • Java - Constructor
  • Java - Copy Constructor
  • Java - String Constructors
  • Java - Parameterized Constructor

Java Array

  • Java - Array
  • Java - Accessing Array Elements
  • Java - ArrayList
  • Java - Passing Arrays to Methods
  • Java - Wrapper Class
  • Java - Singleton Class
  • Java - Access Specifiers
  • Java - Substring

Java Inheritance & Interfaces

  • Java - Inheritance
  • Java - Multilevel Inheritance
  • Java - Single Inheritance
  • Java - Abstract Class
  • Java - Abstraction
  • Java - Interfaces
  • Java - Extending Interfaces
  • Java - Method Overriding
  • Java - Method Overloading
  • Java - Super Keyword
  • Java - Multiple Inheritance

Exception Handling Tutorials

  • Java - Exception Handling
  • Java - Exception-Handling Advantages
  • Java - Final, Finally and Finalize

Data Structures

  • Java - Data Structures
  • Java - Bubble Sort

Advance Java

  • Java - Applet Life Cycle
  • Java - Applet Explaination
  • Java - Thread Model
  • Java - RMI Architecture
  • Java - Applet
  • Java - Swing Features
  • Java - Choice and list Control
  • Java - JFrame with Multiple JPanels
  • Java - Java Adapter Classes
  • Java - AWT Vs Swing
  • Java - Checkbox
  • Java - Byte Stream Classes
  • Java - Character Stream Classes
  • Java - Change Color of Applet
  • Java - Passing Parameters
  • Java - Html Applet Tag
  • Java - JComboBox
  • Java - CardLayout
  • Java - Keyboard Events
  • Java - Applet Run From CLI
  • Java - Applet Update Method
  • Java - Applet Display Methods
  • Java - Event Handling
  • Java - Scrollbar
  • Java - JFrame ContentPane Layout
  • Java - Class Rectangle
  • Java - Event Handling Model

Java programs

  • Java - Armstrong Number
  • Java - Program Structure
  • Java - Java Programs Types
  • Java - Font Class
  • Java - repaint()
  • Java - Thread Priority
  • Java - 1D Array
  • Java - 3x3 Matrix
  • Java - drawline()
  • Java - Prime Number Program
  • Java - Copy Data
  • Java - Calculate Area of Rectangle
  • Java - Strong Number Program
  • Java - Swap Elements of an Array
  • Java - Parameterized Constructor
  • Java - ActionListener
  • Java - Print Number
  • Java - Find Average Program
  • Java - Simple and Compound Interest
  • Java - Area of Rectangle
  • Java - Default Constructor Program
  • Java - Single Inheritance Program
  • Java - Array of Objects
  • Java - Passing 2D Array
  • Java - Compute the Bill
  • Java - BufferedReader Example
  • Java - Sum of First N Number
  • Java - Check Number
  • Java - Sum of Two 3x3 Matrices
  • Java - Calculate Circumference
  • Java - Perfect Number Program
  • Java - Factorial Program
  • Java - Reverse a String

Other Links

  • Java - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW