Prerequisite: Servlets and Applets
| Applets | Servlets |
|---|---|
| A Java applet is a small application which is written in Java and delivered to users in the form of bytecode. | A servlet is a Java programming language class used to extend the capabilities of a server. |
| Applets are executed on client side. | Servlets are executed on server side. |
| Applets are used to provide interactive features to web applications that cannot be provided by HTML alone like capture mouse input etc. | Servlets are the Java counterpart to other dynamic Web content technologies such as PHP and ASP.NET. |
| Life cycle of Applets init(), stop(), paint(), start(), destroy(). | Lifecycle of servlets are:- init( ), service( ), and destroy( ). |
| Packages available in Applets are :- import java.applet.*; and import java.awt.*. | Packages available in servlets are:- import javax.servlet.*; and import java.servlet.http.*; |
| Applets use user interface classes like AWT and Swing. | No User interface required. |
| Applets are more prone to risk as it is on the client machine. | Servlets are under the server security. |
| Applets utilize more network bandwidth as it executes on the client machine. | Servlets are executed on the servers and hence require less bandwidth. |
| Requires java compatible browser for execution. | It accepts input from browser and generates response in the form of HTML Page, Javascript Object, Applets etc. |
Examples:
- Creating “hello world” Applet.
// A Hello World Applet// Save file as HelloWorld.javaimportjava.applet.Applet;importjava.awt.Graphics;// HelloWorld class extends AppletpublicclassHelloWorldextendsApplet {// Overriding paint() method@Overridepublicvoidpaint(Graphics g){g.drawString("Hello World",20,20);}}chevron_rightfilter_none - Creating “hello world” Servlet.
// Import required java librariesimportjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;// Extend HttpServlet classpublicclassHelloWorldextendsHttpServlet {privateString message;publicvoidinit()throwsServletException{// Do required initializationmessage ="Hello World";}publicvoiddoGet(HttpServletRequest request,HttpServletResponse response)throwsServletException, IOException{// Set response content typeresponse.setContentType("text/html");// Actual logic goes here.PrintWriter out = response.getWriter();out.println("<h1>"+ message +"</h1>");}publicvoiddestroy(){// do nothing.}}chevron_rightfilter_none
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- HTML | DOM applets Collection
- Web Browsers that support Java Applets and how to enable them
- Introduction to Java Servlets
- Attributes in Servlets | Java
- Java Servlets | Need of Filters
- What is the difference between GUI and CUI?
- Difference between “!==” and “==!” in PHP
- What is the difference between MEAN.js and MEAN.io?
- What is the difference between (NaN != NaN) & (NaN !== NaN)?
- Difference between T-SQL and PL-SQL
- Difference Between Blu-Ray and DVD
- Difference Between JSP and PHP
- Difference between Where and Having Clause in SQL
- Difference between 2NF and 3NF in DBMS
- Difference between 1NF and 2NF in DBMS
- Difference Between Hive and Hue
- Difference between CSS and JavaScript
- Difference between Where and Group By
- Difference between Python and C++
- What is the difference between the | and || or operator in php?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

