SlideShare a Scribd company logo
1 of 23
Java Exception Handling
&
Applets
Presented By
Tanmoy Roy
1
Roll : 34801216001
Content
 Introduction
 Exception Handling
 Exceptions in Java
 Hierarchy of Java Exception classes
 Types of Exceptions
 Exception Handling Java
 Java Applet
 What is Applet?
 Advantage & Drawback of Applet
 Some Important Points on Java Applet
 Lifecycle of Java Applet
2
Some Interesting Facts about Java
 The initial name of java was “Oak”. it had been modified to Java by Sun’s
marketing department once they found that name was already registered for a
computer company.
 Java is the second preferred language and is incredibly popular among the
developers.
 Java does not support the concept of pointer.
 Java is used by 95% of the companies as their primary language. Which is much
more than C and other languages.
3
Introduction
 The Exception Handling in Java is one amongst the powerful mechanism to
handle the runtime errors so traditional flow of the program will be maintained.
 Applet is a special type of program that is embedded in the webpage to generate
the dynamic content.
4
Exception Handling
5
Exceptions in Java
 An exception is an unwanted or unexpected event, which occurs during the
execution of a program i.e. at run time, that disrupts the normal flow of the
program’s instructions.
6
public class A{
public static void main(String args[])
{
int a=2, b=0, c;
c=a/b; //Exception
System.out.println(c);
}
}
Hierarchy of Java
Exception classes
7
Types of Exceptions
8
The classes which directly inherit Throwable class
except RuntimeException and Error are known as
checked exceptions
The classes which inherit RuntimeException are
known as unchecked exceptions
These are not exceptions at all, but problems that
arise beyond the control of the user or the
programmer.
Types of
Exceptions
9
unchecked exceptions
checked exceptions
Error
Exception Handling Java
10
 Exception Handling mechanism follows a flow which is depicted in the below figure. But if an
exception is not handled, it may lead to a system failure. That is why handling an exception is
very important.
Exception Handling Java
Keyword Description
try The "try" keyword is used to specify a block where we
should place exception code. The try block must be
followed by either catch or finally.
catch The "catch" block is used to handle the exception. It
must be preceded by try block
finally The "finally" block is used to execute the important code
of the program. It is executed whether an exception is
handled or not.
throw The "throw" keyword is used to throw an exception.
throws The "throws" keyword is used to declare exceptions. It
doesn't throw an exception.
11
Exception Handling Java(Example)
package ExceptionHandling;
public class Exception {
public static void main(String args[]) {
try {
int c=100/0;
}catch(ArithmeticException e) {
System.out.println("Exception caught");
}
}
}
12
Java Applet
13
What is Applet?
 An applet is a Java program that runs in a Web browser.
 An applet can be a fully functional Java application because it has the entire Java
API at its disposal.
14
Advantage & Drawback of Applet
 Advantage of Applet
 It works at client side so less response time.
 Secured
 It can be executed by browsers running under many platforms, including Linux,
Windows, Mac OS etc.
 Drawback of Applet
 Plugin is required at client browser to execute applet.
15
Some Important Points on Java Applet
 All applets are sub-classes (either directly or indirectly) of java.applet.Applet
class.
 Applets are not stand-alone programs. Instead, they run within either a web
browser or an applet viewer. JDK provides a standard applet viewer tool called
applet viewer.
 In general, execution of an applet does not begin at main() method.
 Output of an applet window is not performed by System.out.println(). Rather it is
handled with various AWT methods, such as drawString().
16
Lifecycle of Java Applet
17
Lifecycle methods for Applet
18
init( )
destroy( )
start( )
paint( )
stop( )
Lifecycle methods for Applet(Cont.)
19
init( )
destroy( )
start( )
paint( )
stop( )
is used to initialized the Applet. It is invoked only once.
is used to destroy the Applet. It is invoked only once.
is invoked after the init() method or browser is maximized. It is used to start the Applet
is used to paint the Applet. It provides Graphics class object.
is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
A "Hello, World" Applet
import java.applet.*;
import java.awt.*;
public class HelloWorldApplet extends Applet {
public void paint (Graphics g) {
g.drawString ("Hello World", 25, 50);
}
}
20
<html>
<title>The Hello, World Applet</title>
<hr>
<applet code = "HelloWorldApplet.class"
width = "320" height = "120">
</applet>
<hr>
</html>
HelloWorldApplet.java HelloWorldApplet.html
Conclusion
 Exceptions are used to improve error efficiency.
 The Exception Handling in Java is one of the powerful mechanism to handle
the runtime errors.
 Applet is a Java program that can be embedded into a web page. It runs inside
the web browser and works at client side.
21
References
 Head First Java, 2nd Edition [Book] - O'Reilly Media
 http://javatpoint.com/java-tutorial
 https://www.geeksforgeeks.org/java/
 http://www.programmingtutorials.com/java.aspx
22
Thank You
23

More Related Content

What's hot

What's hot (20)

Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java ppt
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
OOP java
OOP javaOOP java
OOP java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 

Similar to Java Exception Handling and Applets

Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
phanleson
 
Java programming-Event Handling
Java programming-Event HandlingJava programming-Event Handling
Java programming-Event Handling
Java Programming
 

Similar to Java Exception Handling and Applets (20)

Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
 
Applet1 (1).pptx
Applet1 (1).pptxApplet1 (1).pptx
Applet1 (1).pptx
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and Multithreading
 
Applet
AppletApplet
Applet
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
B.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & Multithreading
B.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & MultithreadingB.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & Multithreading
B.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & Multithreading
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
 
Java applet
Java appletJava applet
Java applet
 
Applet
 Applet Applet
Applet
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java programming-Event Handling
Java programming-Event HandlingJava programming-Event Handling
Java programming-Event Handling
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Exception handling
Exception handlingException handling
Exception handling
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Java Exception Handling and Applets

  • 1. Java Exception Handling & Applets Presented By Tanmoy Roy 1 Roll : 34801216001
  • 2. Content  Introduction  Exception Handling  Exceptions in Java  Hierarchy of Java Exception classes  Types of Exceptions  Exception Handling Java  Java Applet  What is Applet?  Advantage & Drawback of Applet  Some Important Points on Java Applet  Lifecycle of Java Applet 2
  • 3. Some Interesting Facts about Java  The initial name of java was “Oak”. it had been modified to Java by Sun’s marketing department once they found that name was already registered for a computer company.  Java is the second preferred language and is incredibly popular among the developers.  Java does not support the concept of pointer.  Java is used by 95% of the companies as their primary language. Which is much more than C and other languages. 3
  • 4. Introduction  The Exception Handling in Java is one amongst the powerful mechanism to handle the runtime errors so traditional flow of the program will be maintained.  Applet is a special type of program that is embedded in the webpage to generate the dynamic content. 4
  • 6. Exceptions in Java  An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e. at run time, that disrupts the normal flow of the program’s instructions. 6 public class A{ public static void main(String args[]) { int a=2, b=0, c; c=a/b; //Exception System.out.println(c); } }
  • 8. Types of Exceptions 8 The classes which directly inherit Throwable class except RuntimeException and Error are known as checked exceptions The classes which inherit RuntimeException are known as unchecked exceptions These are not exceptions at all, but problems that arise beyond the control of the user or the programmer.
  • 10. Exception Handling Java 10  Exception Handling mechanism follows a flow which is depicted in the below figure. But if an exception is not handled, it may lead to a system failure. That is why handling an exception is very important.
  • 11. Exception Handling Java Keyword Description try The "try" keyword is used to specify a block where we should place exception code. The try block must be followed by either catch or finally. catch The "catch" block is used to handle the exception. It must be preceded by try block finally The "finally" block is used to execute the important code of the program. It is executed whether an exception is handled or not. throw The "throw" keyword is used to throw an exception. throws The "throws" keyword is used to declare exceptions. It doesn't throw an exception. 11
  • 12. Exception Handling Java(Example) package ExceptionHandling; public class Exception { public static void main(String args[]) { try { int c=100/0; }catch(ArithmeticException e) { System.out.println("Exception caught"); } } } 12
  • 14. What is Applet?  An applet is a Java program that runs in a Web browser.  An applet can be a fully functional Java application because it has the entire Java API at its disposal. 14
  • 15. Advantage & Drawback of Applet  Advantage of Applet  It works at client side so less response time.  Secured  It can be executed by browsers running under many platforms, including Linux, Windows, Mac OS etc.  Drawback of Applet  Plugin is required at client browser to execute applet. 15
  • 16. Some Important Points on Java Applet  All applets are sub-classes (either directly or indirectly) of java.applet.Applet class.  Applets are not stand-alone programs. Instead, they run within either a web browser or an applet viewer. JDK provides a standard applet viewer tool called applet viewer.  In general, execution of an applet does not begin at main() method.  Output of an applet window is not performed by System.out.println(). Rather it is handled with various AWT methods, such as drawString(). 16
  • 17. Lifecycle of Java Applet 17
  • 18. Lifecycle methods for Applet 18 init( ) destroy( ) start( ) paint( ) stop( )
  • 19. Lifecycle methods for Applet(Cont.) 19 init( ) destroy( ) start( ) paint( ) stop( ) is used to initialized the Applet. It is invoked only once. is used to destroy the Applet. It is invoked only once. is invoked after the init() method or browser is maximized. It is used to start the Applet is used to paint the Applet. It provides Graphics class object. is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
  • 20. A "Hello, World" Applet import java.applet.*; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello World", 25, 50); } } 20 <html> <title>The Hello, World Applet</title> <hr> <applet code = "HelloWorldApplet.class" width = "320" height = "120"> </applet> <hr> </html> HelloWorldApplet.java HelloWorldApplet.html
  • 21. Conclusion  Exceptions are used to improve error efficiency.  The Exception Handling in Java is one of the powerful mechanism to handle the runtime errors.  Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. 21
  • 22. References  Head First Java, 2nd Edition [Book] - O'Reilly Media  http://javatpoint.com/java-tutorial  https://www.geeksforgeeks.org/java/  http://www.programmingtutorials.com/java.aspx 22