Friday, 13 May 2016

Java Tutorial : Java Exception Handling


Click here to watch in Youtube :
https://www.youtube.com/watch?v=3WfBUqHxqKE&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Exception Handling 
ExceptionHandlingDemo1.java
/*
 * With out exception handling
 */
public class ExceptionHandlingDemo1
{

    public static void main(String[] args)
    {
        int intValue = 50;
        System.out.println("intValue = " + intValue);

        double doubleValue = 45.9;
        System.out.println("doubleValue = " + doubleValue);

        String str = null;
        System.out.println("str = " + str.toString());

        float floatValue = 10.f;
        System.out.println("floatValue = " + floatValue);

        long longValue = 45000;
        System.out.println("longValue = " + longValue);

    }

}
Output
intValue = 50
doubleValue = 45.9
Exception in thread "main" java.lang.NullPointerException
    at ExceptionHandlingDemo1.main(ExceptionHandlingDemo1.java:16)

ExceptionHandlingDemo2.java
/*
 * With exception handling.
 */
public class ExceptionHandlingDemo2
{

    public static void main(String[] args)
    {
        int intValue = 50;
        System.out.println("intValue = " + intValue);

        double doubleValue = 45.9;
        System.out.println("doubleValue = " + doubleValue);

        try
        {
            String str = null;
            System.out.println("str = " + str.toString());
        }
        catch(Exception exe)
        {
             System.out.println("String value is null");
        }
        

        float floatValue = 10.f;
        System.out.println("floatValue = " + floatValue);

        long longValue = 45000;
        System.out.println("longValue = " + longValue);

    }

}
Output
intValue = 50
doubleValue = 45.9
String value is null
floatValue = 10.0
longValue = 45000
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ExceptionDemo_Exception_handling_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ExceptionDemo_Exception_handling_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/ExceptionDemo_Exception_handling_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge