Saturday, January 14, 2012

6 Exceptions

Will Come soon ;)

7a Multiple Threading


//MULTITHREAD

class mul1 implements Runnable
{
  public void run()
   {
try
{
    for(int i=1;i<=10;i++)
    {
         System.out.println(i+"x2="+(i*2));
         Thread.sleep(800);
     }
  }        
  catch(Exception e)
    {     }    
 }
}
class multible
  {
 public static void main(String args[])

   {
    mul1 ob=new mul1();  
    Thread t1=new Thread(ob);
    Thread t2=new Thread(ob);
    Thread t3=new Thread(ob);

    t1.start();
    t2.start();
    t3.start();
   }
 }

7b Inter-Thread Communication

Will come Soon ;)

5b Text Field and Label Applet

Will come Soon ;)

4c Stack Class


import java.util.*;

public class StackDemo
{
  public static void main(String[] args)
  {
    Stack stack=new Stack();
    stack.push(new Integer(10));
    stack.push("a");
    System.out.println("The contents of Stack is" + stack);
    System.out.println("The size of an Stack is" + stack.size());
    System.out.println("The number poped out is" + stack.pop());
    System.out.println("The number poped out is " + stack.pop());
    System.out.println("The contents of stack is" + stack);
    System.out.println("The size of an stack is" + stack.size());
  }
}

5a Applet Program


import java.applet.*;
import java.awt.*;

public class SampleApplet extends Applet
  {
     public void init()
       {
           setBackground(Color.blue);
           setForeground(Color.red);
       }
    public void paint(Graphics g)
      {
          g.drawString("Welcome to java",20,20);
      }
 }

//<applet code="SampleApplet" width=300 height=200>
//</applet>

3b String Class and String Buffer Calss


import java.io.*;

public class stringBuffer
  {
    public static void main(String[] args) throws Exception
     {
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       String str;
       try
{
   //String

   String s=new String("Welcome");

   //length
   System.out.println("String Length:  "+s.length());

   //concat
     s=s.concat(" to BDU");
                System.out.println("New String   "+ s);

                //charat
                System.out.println("Character at 2nd position: "+s.charAt(2));

                //Substring

                System.out.println("Sub String: "+ s.substring(0,5));

   //String Buffer

                StringBuffer strbuf=new StringBuffer();
       
                //append
           strbuf.append("Hello");
             strbuf.append("World");          
                System.out.println(strbuf);
   
                //insert
                strbuf.insert(5,"_Java ");        
                System.out.println(strbuf);
   
                //reverse
                strbuf.reverse();
                System.out.print("Reversed string : ");
                System.out.println(strbuf);        
                strbuf.reverse();
                System.out.println(strbuf);        
   
                //setCharAt
                strbuf.setCharAt(5,' ');
                System.out.println(strbuf);        
   
                //charAt
                System.out.print("Character at 6th position : ");
                System.out.println(strbuf.charAt(6));  

                //substring
                System.out.print("Substring from position 3 to 6 : ");
       System.out.println(strbuf.substring(3,7));
         
                //deleteCharAt
       strbuf.deleteCharAt(3);
               System.out.println(strbuf);        
   
               //capacity
        System.out.print("Capacity of StringBuffer object : ");
       System.out.println(strbuf.capacity());    
   
          }
       catch(StringIndexOutOfBoundsException e)
         {
                System.out.println(e.getMessage());
         }
     }
  }