SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Applet vs Servlet
Presenting by
Bharat Sahu
MCA Vth Sem., MSIT
Outline
• Applet
• Introduction
• Life Cycle
• Implementation
• Servlet
• Introduction
• Life Cycle
• Implementation
• Difference Between Applet and Servlet
Applet
Introduction
• Applications are stand alone programs
• Executed by Java Interpreter.
• Applet is small program
• Can be placed on web page.
• It will be executed by web browser.
• Provide web page interactive content with power of Java.
• An applet is a Panel that allows interaction with a Java program.
• A applet is typically embedded in a Web page and can be run from a browser.
• You need special HTML in the Web page to tell the browser about the applet.
• Applets run in a sandbox: they have no access to the client’s file system.
• You can run Applet in any browser.
• The best support isn't a browser, but the standalone program appletviewer.
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
Applet
Class Hierarchy
init()
start()
stop()
destroy()
Do Some
Work
Life Cycle of An Applet
• Applet Method
• public void init ()
• public void start ()
• public void stop ()
• public void destroy ()
• public void paint (Graphics g)
note: repaint(), update()
import java.awt.*;
import java.applet.*;
public class WelcomeApplet extends Applet {
public void init() {
}
public void paint(Graphics g) {
g.drawString("Welcome to Java Programming!",
25, 25 );
}
}
<html>
<applet code = "WelcomeApplet.class"
width = "300" height = "45">
</applet>
</html>
Servlet
Introduction
• Server
• Servers are those machine which is responds the clients request.
• Servlets – Web-based solutions executes by Server
• Dynamically generate custom HTML documents
• Replacement to CGI
• Secure access to Website
• Interact with databases
• Servlet are as Applet but Server side
Servlet
How it works?
• Client sends a request to server
• Server starts a servlet
• Servlet computes a result for server and does not quit
• Server returns response to client
• Another client sends a request
• Server calls the servlet again
Server
Client
Client
Servlet
• A servlet is any class that implements the javax.servlet.Servlet
interface
• In practice, most servlets extend the javax.servlet.http.HttpServlet class
• Some servlets extend javax.servlet.GenericServlet instead
• Tomcat is the Servlet Engine than handles servlet requests for Apache
• It’s best to think of Tomcat as a “servlet container”
• Apache can handle many types of web services
• Apache can be installed without Tomcat
• Tomcat can be installed without Apache
Life cycle of Servlet
Initialization
(load resource)
Service
(accept requests)
Destruction
(unload resource)
• Initialize
• Service
• Destroy
Response
Request
• Initialize: init() method called once, when any request occur.
• Service: Any requests will be forwarded to the service() method
• doGet()
• doPost()
• doDelete()
• doOptions()
• doPut()
• doTrace()
• Destroy: called once
• destroy() method called when: Application is stopped or Servlet container shuts down
• Allows resources to be free
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet {
protected void doGet( HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println( “<html><body>" );
out.println( “<h1>Hello World</h1>" );
out.println( “</body></html>" );
out.close
}
}
Applet vs Servlet
• Similarities
• Neither has a main()
• Both have init() and destroy()
• Both are part of a larger application made for the web
• Dissimilarity
• Applets run on the client (browser) while servlets run on the HTTP server
• Applets are having limited functionality to look at the local file system, establish
network connections, etc.
• Servlets are generally built to handle multiple clients at once, whereas applets
generally service one client at a time.
• Servlets handle HTTP request
• Applets used for static web pages, Servlet used for dynamic web pages.
Reference
• Sun’s Website
1. http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.htm
2. http://java.sun.com/docs/books/tutorial/applets/lifecycle/index.htm

Weitere ähnliche Inhalte

Was ist angesagt?

Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQLAdil Mehmoood
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1Julie Iskander
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web DevelopmentRobert J. Stein
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET CoreAvanade Nederland
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentationguest0df6b0
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVCzeeshanhanif
 
MVC architecture
MVC architectureMVC architecture
MVC architectureEmily Bauman
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)WebStackAcademy
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.Ni
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3sandeep54552
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 

Was ist angesagt? (20)

MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentation
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
.Net Core
.Net Core.Net Core
.Net Core
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Spring boot
Spring bootSpring boot
Spring boot
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
REST API
REST APIREST API
REST API
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 

Andere mochten auch

Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsTrinity Dwarka
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in javaVidya Bharti
 
L18 applets
L18 appletsL18 applets
L18 appletsteach4uin
 
Java applets
Java appletsJava applets
Java appletslopjuan
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java AppletsTareq Hasan
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And AppletsAdil Jafri
 
Applet intro
Applet introApplet intro
Applet introNitin Birari
 
Java Servlet
Java Servlet Java Servlet
Java Servlet Rajiv Gupta
 
Java Applets
Java AppletsJava Applets
Java AppletsDanial Mirza
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technologyTanmoy Barman
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in javaDeepak Sharma
 
Java swing
Java swingJava swing
Java swingNataraj Dg
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Appletsamitksaha
 

Andere mochten auch (20)

Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet Programs
 
Java applets
Java appletsJava applets
Java applets
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
 
L18 applets
L18 appletsL18 applets
L18 applets
 
Java applets
Java appletsJava applets
Java applets
 
Java applets
Java appletsJava applets
Java applets
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
Asif
AsifAsif
Asif
 
21servers And Applets
21servers And Applets21servers And Applets
21servers And Applets
 
Applet intro
Applet introApplet intro
Applet intro
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Java Applets
Java AppletsJava Applets
Java Applets
 
applet using java
applet using javaapplet using java
applet using java
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Java Applet
Java AppletJava Applet
Java Applet
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
Java swing
Java swingJava swing
Java swing
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 

Ă„hnlich wie Applet Vs Servlet

Ă„hnlich wie Applet Vs Servlet (20)

Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Servlets
ServletsServlets
Servlets
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
CS8651 IP Unit 3.pptx
CS8651 IP Unit 3.pptxCS8651 IP Unit 3.pptx
CS8651 IP Unit 3.pptx
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
Servlets
ServletsServlets
Servlets
 

KĂĽrzlich hochgeladen

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

KĂĽrzlich hochgeladen (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Applet Vs Servlet

  • 1. Applet vs Servlet Presenting by Bharat Sahu MCA Vth Sem., MSIT
  • 2. Outline • Applet • Introduction • Life Cycle • Implementation • Servlet • Introduction • Life Cycle • Implementation • Difference Between Applet and Servlet
  • 3. Applet Introduction • Applications are stand alone programs • Executed by Java Interpreter. • Applet is small program • Can be placed on web page. • It will be executed by web browser. • Provide web page interactive content with power of Java.
  • 4. • An applet is a Panel that allows interaction with a Java program. • A applet is typically embedded in a Web page and can be run from a browser. • You need special HTML in the Web page to tell the browser about the applet. • Applets run in a sandbox: they have no access to the client’s file system. • You can run Applet in any browser. • The best support isn't a browser, but the standalone program appletviewer.
  • 6. init() start() stop() destroy() Do Some Work Life Cycle of An Applet • Applet Method • public void init () • public void start () • public void stop () • public void destroy () • public void paint (Graphics g) note: repaint(), update()
  • 7. import java.awt.*; import java.applet.*; public class WelcomeApplet extends Applet { public void init() { } public void paint(Graphics g) { g.drawString("Welcome to Java Programming!", 25, 25 ); } } <html> <applet code = "WelcomeApplet.class" width = "300" height = "45"> </applet> </html>
  • 8. Servlet Introduction • Server • Servers are those machine which is responds the clients request. • Servlets – Web-based solutions executes by Server • Dynamically generate custom HTML documents • Replacement to CGI • Secure access to Website • Interact with databases • Servlet are as Applet but Server side
  • 9. Servlet How it works? • Client sends a request to server • Server starts a servlet • Servlet computes a result for server and does not quit • Server returns response to client • Another client sends a request • Server calls the servlet again Server Client Client Servlet
  • 10. • A servlet is any class that implements the javax.servlet.Servlet interface • In practice, most servlets extend the javax.servlet.http.HttpServlet class • Some servlets extend javax.servlet.GenericServlet instead • Tomcat is the Servlet Engine than handles servlet requests for Apache • It’s best to think of Tomcat as a “servlet container” • Apache can handle many types of web services • Apache can be installed without Tomcat • Tomcat can be installed without Apache
  • 11. Life cycle of Servlet Initialization (load resource) Service (accept requests) Destruction (unload resource) • Initialize • Service • Destroy Response Request
  • 12. • Initialize: init() method called once, when any request occur. • Service: Any requests will be forwarded to the service() method • doGet() • doPost() • doDelete() • doOptions() • doPut() • doTrace() • Destroy: called once • destroy() method called when: Application is stopped or Servlet container shuts down • Allows resources to be free
  • 13. import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class WelcomeServlet extends HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType( "text/html" ); PrintWriter out = response.getWriter(); out.println( “<html><body>" ); out.println( “<h1>Hello World</h1>" ); out.println( “</body></html>" ); out.close } }
  • 14.
  • 15. Applet vs Servlet • Similarities • Neither has a main() • Both have init() and destroy() • Both are part of a larger application made for the web
  • 16. • Dissimilarity • Applets run on the client (browser) while servlets run on the HTTP server • Applets are having limited functionality to look at the local file system, establish network connections, etc. • Servlets are generally built to handle multiple clients at once, whereas applets generally service one client at a time. • Servlets handle HTTP request • Applets used for static web pages, Servlet used for dynamic web pages.
  • 17. Reference • Sun’s Website 1. http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.htm 2. http://java.sun.com/docs/books/tutorial/applets/lifecycle/index.htm

Hinweis der Redaktion

  1. Normal java program has main method on code. Applet doesn't have main method.
  2. Plateform independent Secure
  3. JApplet extends Applet Class
  4. Init(): execute first, initialize variables, best place define buttons, textfields, layouts, slider, every applet have init method. Start(): called after init, not always needed. Conjuction with strop(). Stop(): not always needed, called when browser leaves the page, called before destroy, conjuction with start(). Destroy(): Seldom needed, Called after stop( ), Use to explicitly release system resources (like threads), System resources are usually released automatically. Paint(): almost always needed, don’t call its called automatically call instead repaint, any painting done here or call by here. Repaint(): it’s a request that internally call update(Graphics g), any changes happened then call repaint.
  5. Servlet communicate to Clients and Server through HTTP
  6. About 50% and above websites uses Apache server Apache is server, tomcat is container; apache uses tomcat as container both are free source There is also other server available