Friday 13 May 2016

Java Tutorial : Java checked exception and unchecked exception(Version3)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=-8aXVJhMqLk&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java checked exception and unchecked exception(Version3) 
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
  • Java Tutorial : Java checked exception and unchecked exception(Version2)


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

    Click the below Image to Enlarge
    Java Tutorial : Java checked exception and unchecked exception(Version2) 
    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
  • Java checked exception and unchecked exception - Playlist

    Java Tutorial : Java checked exception and unchecked exception(Version1)


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

    Click the below Image to Enlarge
    Java Tutorial : Java checked exception and unchecked exception(Version1) 
    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
  • Java Tutorial : Java Exception class hierarchy - Playlist

    Java Tutorial : Java Exception class hierarchy(Version3)

    Java Tutorial : Java Exception class hierarchy(Version2)

    Java Tutorial : Java Exception class hierarchy(Version1)


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

    Click the below Image to Enlarge
    Java Tutorial : Java Exception class hierarchy(Version1) 
    Java Tutorial : Java Exception class hierarchy(Version1) 
    Java Tutorial : Java Exception class hierarchy(Version1) 
    Java Tutorial : Java Exception class hierarchy(Version1) 
    Java Tutorial : Java Exception class hierarchy(Version1) 
    Refer: 
    https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Throwable.html

    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
  • 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
  • Java Tutorial : Java exception handling - Playlist

    Java Tutorial : Java what is an Exception


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

    Click the below Image to Enlarge
    Java Tutorial : Java what is an Exception 
    ExceptionDemo.java
    public class ExceptionDemo
    {
    
        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 ExceptionDemo.main(ExceptionDemo.java:14)
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/ExceptionDemo_What_is_an_Exception_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/ExceptionDemo_What_is_an_Exception_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
  • Java Tutorial : Java Autoboxing and Unboxing - Playlist

    Java Tutorial : Java Unboxing

    UnBoxingDemo.java
    import java.util.ArrayList;
    import java.util.List;
    
    public class UnBoxingDemo
    {
    
        public static void main(String[] args)
        {
            Integer integerObj = new Integer(-8);
    
            // 1. Unboxing through method invocation
            int absVal = absoluteValue(integerObj);
            System.out.println("absolute value of " + integerObj + " = " + absVal);
    
            List<Double> list = new ArrayList<>();
            list.add(new Double(12.3)); 
    
            // 2. Unboxing through assignment
            double doubleValue = list.get(0);
            System.out.println("doubleValue = " + doubleValue);
    
        }
    
        public static int absoluteValue(int i)
        {
            return (i < 0) ? -i : i;
        }
    
    }
    
    Output
    absolute value of -8 = 8
    doubleValue = 12.3
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/UnBoxingDemo_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/UnBoxingDemo_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
  • Wednesday 11 May 2016

    Java Tutorial : Java Unboxing (list)


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

    Click the below Image to Enlarge
    Java Tutorial : Java Unboxing (list)
    Java Tutorial : Java Unboxing (list)
    UnBoxingDemo.java
    import java.util.ArrayList;
    import java.util.List;
    
    public class UnBoxingDemo
    {
    
        public static void main(String[] args)
        {
            List<Integer> list = new ArrayList<>();
            list.add(new Integer(1));
            list.add(new Integer(2));
            for (Integer integerObj : list)
            {
                int i = integerObj; // Unboxing
                System.out.println(i);
            }
    
        }
    
    }
    
    Output
    1
    2
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/UnBoxingDemo_list_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/UnBoxingDemo_list_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
  • Java Tutorial : Java Autoboxing (list)


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

    Click the below Image to Enlarge
    Java Tutorial : Java Autoboxing (list) 
    Java Tutorial : Java Autoboxing (list) 
    AutoBoxingDemo.java
    import java.util.ArrayList;
    import java.util.List;
    
    public class AutoBoxingDemo
    {
    
        public static void main(String[] args)
        {
            List<Integer> li = new ArrayList<>();
    
            for (int i = 1; i < 20; i += 2)
            {
                li.add(i);
            }
            System.out.println(li);
            System.out.println(li.get(0).getClass());
        }
    
    }
    
    Output
    [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
    class java.lang.Integer
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/AutoBoxing_Demo_List_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/AutoBoxing_Demo_List_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
  • Java Tutorial : Java Autoboxing and Unboxing


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

    Click the below Image to Enlarge
    Java Tutorial : Java Autoboxing and Unboxing 
    Java Tutorial : Java Autoboxing and Unboxing 
    Java Tutorial : Java Autoboxing and Unboxing 

    AutoBoxingDemo.java
    public class AutoBoxingDemo
    {
    
        public static void main(String[] args)
        {
            int intValue = 50;
            Integer integerObj = intValue;// Boxing
            System.out.println(integerObj);
            
            display(intValue); //Boxing
        }
        
        public static void display(Integer integerObj)
        {
            System.out.println(integerObj);
        }
    
    }
    Output
    50
    50
    UnboxingDemo.java
    public class UnboxingDemo
    {
        public static void main(String[] args)
        {
            Integer integerObj = new Integer(100);
            int intValue = integerObj; // UnBoxing
            System.out.println(intValue);
            
            display(integerObj);//UnBoxing
        }
    
        public static void display(int intValue)
        {
            System.out.println(intValue);
        }
    }
    
    Output
    100
    100
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/AutoBoxing_UnBoxingDemo_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/AutoBoxing_UnBoxingDemo_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
  • Java Tutorial : Java StringBuilder [supported methods]


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

    Click the below Image to Enlarge
    Java Tutorial : Java StringBuilder [supported methods] 
    Java Tutorial : Java StringBuilder [supported methods] 
    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
  • Java Tutorial : Java StringBuilder [length and Capacity]

    Java Tutorial : Java String vs StringBuffer vs StringBuilder(memory test)


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

    StringMemoryTest.java
    public class StringMemoryTest
    {
    
        private static final int KBinBytes = 1024;
    
        /**
         * Perform GC
         */
        private void performGC()
        {
            for (int i = 0; i < 10; i++)
            {
                System.gc();
                try
                {
                    Thread.sleep(100);
                }
                catch (InterruptedException e)
                {
                    Thread.currentThread().interrupt();
                }
            }
        }
    
        /**
         * Get the memory used value.
         * 
         * @return long
         */
        private long memoryUsed()
        {
            return ((Runtime.getRuntime().totalMemory() / KBinBytes) - (Runtime
                    .getRuntime().freeMemory() / KBinBytes));
        }
    
        /**
         * Method to test String object memory consumption in a
         * BIG loop
         */
        public void testStringMemory()
        {
            System.out
                    .println("Initial Total memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().totalMemory()
                            / KBinBytes);
            System.out
                    .println("Initial Free memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().freeMemory()
                            / KBinBytes);
            long initialmemory = memoryUsed();
            long startTime = System.currentTimeMillis();
            String str = "";
            for (int i = 1; i < 50000; i++)
            {
                str = str + "Hello";
            }
            long stopTime = System.currentTimeMillis();
            long elapsedTime = stopTime - startTime;
            System.out.println("Time taken to complete the process in MilliSeconds:"
                    + elapsedTime);
    
            System.out.println("Memory used by String in KBs="
                    + (memoryUsed() - initialmemory));
            str = null;
            performGC();
            System.out.println("Free Memory after GC in KBs="
                    + Runtime.getRuntime().freeMemory() / KBinBytes);
    
        }
    
        /**
         * Method to test StringBuilder object memory
         * consumption in a BIG loop
         */
        public void testStringBuilderMemory()
        {
            System.out
                    .println("Initial Total memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().totalMemory()
                            / KBinBytes);
            System.out
                    .println("Initial Free memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().freeMemory()
                            / KBinBytes);
            long initialmemory = memoryUsed();
            long startTime = System.currentTimeMillis();
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i < 50000; i++)
            {
                sb.append("Hello");
            }
            long stopTime = System.currentTimeMillis();
            long elapsedTime = stopTime - startTime;
            System.out
                    .println("Time taken to complete the process in MilliSeconds:"
                            + elapsedTime);
            System.out.println("Memory used by StringBuilder in KBs="
                    + (memoryUsed() - initialmemory));
            sb = null;
            performGC();
            System.out.println("Free Memory after GC in KBs="
                    + Runtime.getRuntime().freeMemory() / KBinBytes);
    
        }
    
        /**
         * Method to test StringBuffer object memory consumption
         * in a BIG loop
         */
        public void testStringBufferMemory()
        {
            System.out
                    .println("Initial Total memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().totalMemory()
                            / KBinBytes);
            System.out
                    .println("Initial Free memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().freeMemory()
                            / KBinBytes);
            long initialmemory = memoryUsed();
            long startTime = System.currentTimeMillis();
            StringBuffer sb = new StringBuffer();
    
            for (int i = 1; i < 50000; i++)
            {
                sb.append("Hello");
            }
            long stopTime = System.currentTimeMillis();
            long elapsedTime = stopTime - startTime;
            System.out.println("Time taken to complete the process in MilliSeconds:"
                    + elapsedTime);
            System.out.println("Memory used by StringBuffer in KBs="
                    + (memoryUsed() - initialmemory));
            sb = null;
            performGC();
            System.out.println("Free Memory after GC in KBs="
                    + Runtime.getRuntime().freeMemory() / KBinBytes);
    
        }
    
        /**
         * Main class
         * 
         * @param args
         */
        public static void main(String[] args)
        {
            System.out
                    .println("Initial Max memory in Java virtual machine in KBs="
                            + Runtime.getRuntime().maxMemory()
                            / KBinBytes);
            StringMemoryTest memoryTest = new StringMemoryTest();
            System.out.println(".....................................................\nString memory test\n");
            memoryTest.testStringMemory();
            System.out.println(".................................................\nStringBuffer memory test\n");
            memoryTest.testStringBufferMemory();
            System.out.println("...............................................\nStringBuilder memory test\n");
            memoryTest.testStringBuilderMemory();
    
        }
    
    }
    
    Output
    Initial Max memory in Java virtual machine in KBs=919552
    ...........................................................
    String memory test
    
    Initial Total memory in Java virtual machine in KBs=62976
    Initial Free memory in Java virtual machine in KBs=61992
    Time taken to complete the process in MilliSeconds:7729
    Memory used by String in KBs=130666
    Free Memory after GC in KBs=349431
    ...........................................................
    StringBuffer memory test
    
    Initial Total memory in Java virtual machine in KBs=355840
    Initial Free memory in Java virtual machine in KBs=349431
    Time taken to complete the process in MilliSeconds:11
    Memory used by StringBuffer in KBs=0
    Free Memory after GC in KBs=348918
    ............................................................
    StringBuilder memory test
    
    Initial Total memory in Java virtual machine in KBs=355328
    Initial Free memory in Java virtual machine in KBs=348918
    Time taken to complete the process in MilliSeconds:5
    Memory used by StringBuilder in KBs=0
    Free Memory after GC in KBs=348406
    
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringBuilderDemo_MemoryTest_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/StringBuilderDemo_MemoryTest_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