Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, September 26, 2016

Thread Exampale Of CurrentThread In java Programming

CurrentThread Exampale
class currentthreadex
{
       public static void main(String arg[])

     {

           Thread th=Thread.current.Thread();

          System.out.println("Current Thread Is:"+th);

         th.setName("exampale thread");

        System.out.println("After Name Change:"+th); //after change thread name of exampale thread

       try

      {

           for(int i=5;i>0;i--)

           {

                   System.out.println(i);

            }

      }

      catch(InterruptedException h)

     {

           System.out.println("Main Thread Interrrupted");


      }

     }

}

Exception Handling Examplae Using Try And Catch in Java Programming

//Exception Handling In Try Catch Examplae

class excep
{
     public static void main(String args[])
    {
       int p,q;
        try
{
         p=0;
         q=45/p;
         System.out.println("A Not Exicute"); //This not run but it above error generated
    }
catch(ArithmeticException s)
{
   System.out.println("Division By Zero Not Possible");

}
System.out.println("It Will be Exicute After Catch Statement");
}
}


Output:

  Division By Zero Not Possible
It Will be Exicute After Catch Statement