Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Applet in Java? How to Create & Run?

By Pavan Vadapalli

Updated on Nov 30, 2022 | 7 min read

Share:

Java applets are short programs created in Java or another programming language that combines Java bytecode and is provided to users as Java bytecode. Java applet was launched by the user from a web page, and it was then processed within a Java virtual machine (JVM) in a procedure distinct from the web browser. A Java applet might appear in a web page frame, a new application window, Sun’s AppletViewer, or a standalone applet testing tool.

Applets give interactive capabilities to web applications that HTML cannot deliver. They can record mouse input and feature controls such as buttons or checkboxes. In addition, an applet can modify the offered graphic information in response to user activities. As a result, applets are ideal for presentation, visualisation, and education.

An applet is a web application embedded in an HTML page with the APPLET or OBJECT tag and hosted on a web server. Applets are utilised to enhance the website’s dynamic and engaging nature.

 Example of an Applet

 import java.applet.*;

import java.awt.*;

public class MyApplet extends Applet

{

 int height, width;

 public void init()

 {

  height = getSize().height;

  width = getSize().width;

  setName(“MyApplet”);

 }

 public void paint(Graphics g)

 {

  g.drawRoundRect(10, 30, 120, 120, 2, 3);

 }

}

 Here’s an example of a Java source code for making a simple calculator using an Applet. The result of the application is also presented below:

/*Java Program to Demonstrate a Basic Calculator using Applet*/

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class Calculator extends Applet implements ActionListener

{

TextField inp;

//Function to add features to the frame

public void init()

{

         setBackground(Color.white);

         setLayout(null);

         int i;

         inp = new TextField();

         inp.setBounds(150,100,270,50);

         this.add(inp);

         Button button[] = new Button[10];

         for(i=0;i<10;i++)

         {

         button[i] = new Button(String.valueOf(9-i));

         button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);

         this.add(button[i]);

         button[i].addActionListener(this);

         }

         Button dec=new Button(“.”);

         dec.setBounds(200,300,50,50);

         this.add(dec);

         dec.addActionListener(this);

     Button clr=new Button(“C”);

         clr.setBounds(250,300,50,50);

         this.add(clr);

         clr.addActionListener(this)

         Button operator[] = new Button[5];

         operator[0]=new Button(“/”);

         operator[1]=new Button(“*”);

         operator[2]=new Button(“-“);

         operator[3]=new Button(“+”);

         operator[4]=new Button(“=”);

         for(i=0;i<4;i++)

         {

         operator[i].setBounds(300,150+(i*50),50,50);

         this.add(operator[i]);

         operator[i].addActionListener(this);

         }

         operator[4].setBounds(350,300,70,50);

         this.add(operator[4]);

         operator[4].addActionListener(this);

}

String num1=””;

String op=””;

String num2=””;

//Function to calculate the expression

public void actionPerformed(ActionEvent e)

{

         String button = e.getActionCommand();

     char ch = button.charAt(0);

         if(ch>=’0′ && ch<=’9’|| ch==’.’)

         {

         if (!op.equals(“”))

                     num2 = num2 + button;

         else

                     num1 = num1 + button;  

         inp.setText(num1+op+num2);

         }

         else if(ch==’C’)

         {

         num1 = op = num2 = “”;

         inp.setText(“”);

         }

         else if (ch ==’=’)

         {

         if(!num1.equals(“”) && !num2.equals(“”))

         {

                     double temp;

                 double n1=Double.parseDouble(num1);

                     double n2=Double.parseDouble(num2);

                     if(n2==0 && op.equals(“/”))

                     {

                     inp.setText(num1+op+num2+” = Zero Division Error”);

                     num1 = op = num2 = “”;

                     }

                     else

                     {

                     if (op.equals(“+”))

                         temp = n1 + n2;

                     else if (op.equals(“-“))

                         temp = n1 – n2;

                     else if (op.equals(“/”))

                         temp = n1/n2;

                     else

                         temp = n1*n2;

                     inp.setText(num1+op+num2+” = “+temp);

                     num1 = Double.toString(temp);

                     op = num2 = “”;

             }

         }

         else

         {

                     num1 = op = num2 = “”;

                     inp.setText(“”);

         }

     }

         else

         {

         if (op.equals(“”) || num2.equals(“”))

                     op = button;

         else

         {

                     double temp;

                     double n1=Double.parseDouble(num1);

                     double n2=Double.parseDouble(num2);

                     if(n2==0 && op.equals(“/”))

                     {

                     inp.setText(num1+op+num2+” = Zero Division Error”);

                     num1 = op = num2 = “”;

                     }

                     else

                     {

                     if (op.equals(“+”))

                         temp = n1 + n2;

                     else if (op.equals(“-“))

                         temp = n1 – n2;

                     else if (op.equals(“/”))

                         temp = n1/n2;

                     else

                         temp = n1*n2;

                     num1 = Double.toString(temp);

                     op = button;

                     num2 = “”;

             }

         }

         inp.setText(num1+op+num2);

     }

}

}

/*

<applet code = Calculator.class width=600 height=600>

</applet>

*/

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

 Advantages of an Applet:

  1. Since an applet is a short Java application, it is a platform-neutral code that can run on any browser.
  2. On client-side computers, applets may execute various minor activities. They can play music, display images, receive user inputs, mouse clicks, and even keystrokes, among other things.
  3. Applets are client-side visuals that are distinct and independent of the client-side platform.
  4. Although applets are less in size than stand-alone applications, their ability to be shared across a network makes them more usable.
  5. Since applets run on client browsers, they may import graphics and audio snippets depending on URLs.
  6. Due to their access to resources, applets are highly secure.
  7. Applets are safe and protected to use since they cannot modify the local system.
  8. Applets operating via Intranets may perform multiple tiny activities such as login, inventory checking, and task scheduling.

 Limitations of an Applet:

 Since applets are received from distant workstations and might affect client-side machines, they are subject to several security constraints. Here are a few examples:

  1. If someone is running an applet from an unreliable supplier, security is critical.
  2. Any programme on the local system cannot be started or modified by the applet.
  3. Applets do not have access to client-side resources such as files, operating systems, and so on.
  4. Applets may be granted specific rights. They must be labelled as trustworthy applets and registered with APS (Applet Security Manager).
  5. When it comes to interacting, Applet has few constraints. It can only communicate with the machine that loaded it.
  6. Applets are unable to interact with native methods.
  7. The only information an applet may collect about a client machine is its name, java edition, operating system, version, and so on.
  8. Applets are notoriously sluggish to execute because all of the classes and resources they require must be sent across the network.

 Life Cycle of an Applet:

 There are five techniques in the applet life cycle. Init(), start(), paint(), stop(), and destroy() are the methods.

init(): The init() function is used to launch an applet. It is only called once throughout the startup process. The internet browser generates objects that have already been initialised. This technique is equivalent to the Thread class’s condition of being born.

start(): The start() function is used to initiate the execution of the applet. It is invoked after the init() function has been called. Whenever the browser loads or refreshes, it is called. The start() function is dormant until the init() method is called. This function is comparable to the Thread class’s start state.

 paint(): The paint() function is used to paint any form such as a square, rectangle, trapezium, eclipse, etc. ClassGraphics is a parameter of the paint() function. This Graphics class provides painting functionality in the form of an applet. This technique is comparable to the Thread class’s runnable state.

 stop(): The stop() function is used to terminate the applet. Whenever the browser is closed, minimised, or the application crashes unexpectedly, it is called. After using the stop() function, we may use the start() method. This approach is mainly concerned with code cleanup. This function can be compared to the Thread class’s state of being blocked

 destroy(): When we have finished our applet work, we utilise the destroy() function to kill the application. It will only be used once. We can no longer start() the applet once it has been destroyed. This function is analogous to the Thread class’s dead state paint() method, which may be used to paint any shape, such as a square, rectangle, trapezium, eclipse, etc. The paint() method takes an argument called ClassGraphics. This Graphics class provides painting functionality in the form of an applet.

 Using an HTML file, implement the Applet Life Cycle in the following way:

 Wondering where to learn Java?

 upGrad’s Executive PG Program in Software Development is where your hunt ends!

 Key Highlights-

  • Top-Notch Faculty Members & Industry Experts
  • Free exclusive access to Data Science and Machine Learning
  • Option for no-cost EMI
  • 10 Programming Languages and Tools

 Conclusion

 Java is a highly significant programming Language that you must know if you are a software enthusiast. A course on this topic will definitely enhance your prospects as a software developer in the long run and open new avenues for a prosperous career.

Frequently Asked Questions (FAQs)

1. What is the purpose of the applet class?

2. How many types of applets are there?

3. What is the difference between applet and application in Java?

Pavan Vadapalli

971 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

Suggested Blogs