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. |
Applets are two types 1.) Untrusted Applets 2.) trusted Applets |
Servlet are two types 1.) Generic Servlet 2.) HTTP Servlet |
Applets is a part of JSE(JAVA Standard Edition) Modules. |
Servlet is a part of JEE(Java Enterprise Edition ) Modules. |
Examples:
- Creating “hello world” Applet.
Java
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet {
@Override
public void paint(Graphics g)
{
g.drawString("Hello World", 20 , 20 );
}
}
|
- Creating “hello world” Servlet.
Java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
private String message;
public void init() throws ServletException
{
message = "Hello World";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy()
{
}
}
|
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
05 Jun, 2023
Like Article
Save Article