0% found this document useful (0 votes)
500 views3 pages

Difference Between Applets and Servlets

DIFFERENCE BETWEEN APPLETS AND SERVLETS

Uploaded by

rooba vathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
500 views3 pages

Difference Between Applets and Servlets

DIFFERENCE BETWEEN APPLETS AND SERVLETS

Uploaded by

rooba vathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DIFFERENCE BETWEEN APPLETS AND SERVLETS

Prerequisite: Servlets and Applets


Applets Servlets
A Java applet is a small application A servlet is a Java programming
which is written in Java and delivered to language class used to extend the
users in the form of bytecode. capabilities of a server.
Applets are executed on client side. Servlets are executed on server side.
Applets are used to provide interactive Servlets are the Java counterpart to
features to web applications that cannot other dynamic Web content
be provided by HTML alone like technologies such as PHP and
capture mouse input etc. [Link].
Life cycle of Applets init(), stop(), Lifecycle of servlets are:- init( ),
paint(), start(), destroy(). service( ), and destroy( ).
Packages available in Applets are :- Packages available in servlets are:-
import [Link].*; and import import [Link].*; and import
[Link].*. [Link].*;
Applets use user interface classes like
No User interface required.
AWT and Swing.
Applets are more prone to risk as it is on
Servlets are under the server security.
the client machine.
Applets utilize more network bandwidth Servlets are executed on the servers
as it executes on the client machine. and hence require less bandwidth.
It accepts input from browser and
Requires java compatible browser for generates response in the form of
execution. HTML Page, Javascript Object,
Applets etc.
Applets are two types 1.) Untrusted Servlet are two types 1.) Generic
Applets 2.) trusted Applets Servlet 2.) HTTP Servlet
Applets is a part of JSE(JAVA Standard Servlet is a part of JEE(Java Enterprise
Applets Servlets
Edition) Modules. Edition ) Modules.
Examples:
Creating “hello world” applet.
// A Hello World Applet
// Save file as [Link]
import [Link];
import [Link];
// HelloWorld class extends Applet
public class HelloWorld extends Applet {
// Overriding paint() method
@Override
public void paint(Graphics g)
{
[Link]("Hello World", 20, 20);
}
}
Creating “hello world” Servlet.
// Import required java libraries
import [Link].*;
import [Link].*;
import [Link].*;
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {

private String message;

public void init() throws ServletException


{
// Do required initialization
message = "Hello World";
}
public void doGet(HttpServletRequest
request,
HttpServletResponse response)
throws ServletException, IOException
{
// Set response content type
[Link]("text/html");
// Actual logic goes here.
PrintWriter out = [Link]();
[Link]("<h1>" + message + "</h1>");
}
public void destroy()
{
// do nothing.
}
}

You might also like