Tuesday, 29 November 2011

Growing text

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

//<applet code="Growing" height=700 width=800> </applet>

public class Growing extends Applet
{
    int size=10;
    Thrd tt=new Thrd();
    Image img;
    public void init()
    {
        tt.start();
        img=getImage(getDocumentBase(),"Water lilies.jpg");
    }
   
   
    public void paint(Graphics g) 
    {
        g.setColor(Color.yellow);
        g.setFont(new Font("Arial",Font.BOLD,size));
        g.drawImage( img, size,size ,this);
        g.drawString("Welcome to All",200,350);
    }
    public void destroy()
    {
        tt.stop();
        System.out.print("finished");
       
    }


    class Thrd extends Thread
    {
        public void run()
        {
            do
            {
                try
                {
                    Thread.sleep(200);
                    size++;
                    if(size==70) size=10;
                    repaint();
                }
                catch(InterruptedException ie)
                {
                    System.out.println ("Thread Exception");
                }
            }while(true);
        }
    }
}

Tuesday, 15 November 2011

Face

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

/*
<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=prg9.class width=500 height=350>
</applet>
</body>
</html>
*/

public class prg9 extends Applet
{
  Label l1;
  private int mouseX, mouseY;
  private boolean mouseclicked = false;
  public void init()
  {
   l1=new Label("Click Any Where On The Window.");
   add(l1);
  }
 public void paint(Graphics g)
 {
  g.drawOval(40, 40, 120, 150);
  g.drawOval(57, 75, 30, 30);
  g.drawOval(110, 75, 30, 30);
  g.fillOval(68, 81, 10, 10);
  g.fillOval(121, 81, 10, 10);
  g.drawLine(100, 100, 100, 117);
  g.fillRect(60, 139, 80, 10);
  if (mouseclicked)
  {
   g.clearRect(60, 139, 80, 10);
   g.drawArc(70, 100, 60, 60, 0, -180);
   mouseclicked = false;
  }
 }
 public boolean mouseDown(Event e, int x, int y)
 {
  mouseX = x;
  mouseY = y;
  mouseclicked = true;
  repaint();
  return true;
 }
}

shapes

import java.awt.*;
import java.applet.*;
public class shapes extends Applet
{
public void paint(Graphics g)
{
try
{
// cone

g.drawOval(100,100,100,50); //cone base
g.drawLine(100,125,150,15); //cone left side
g.drawLine(200,125,150,15); //cone right side

//cylinder

g.drawOval(100,200,100,50);//top circle
g.drawOval(100,400,100,50);//bottom circle
g.drawLine(100,225,100,425);//left side line
g.drawLine(200,225,200,425);//right side line

//square inside circle
g.drawOval(300,400,200,200);//circle
g.drawRect(350,450,100,100);//square

//circle inside square
g.drawRect(300,100,200,200);//square
g.drawOval(350,150,100,100);//circle

//CUBE
g.drawRect(600,200,150,150);
g.drawRect(650,250,150,150);
//LINES TO FORM TOP OF CUBE
g.drawLine(600,200,650,250);
g.drawLine(750,200,800,250);
//LINES TO FORM BOTTOM OF CUBE
g.drawLine(600,350,650,400);
g.drawLine(750,350,800,400);
}
catch(Exception e)
{ }
}
}

Linked List

import java.util.*;
import java.util.Scanner;
class linklist
{
public static void main(String[] args)
{
LinkedList<Integer> ll=new LinkedList<Integer>();
int ch;
for(;;)
{
System.out.println("1:Append \n 2:Add At First \n 3:Add At Last \n 4:Add At Location \n5:Remove Location \n 6:Remove First \n 7:Remove Last \n 8: Display \n 9:Exit\n");
System.out.println("Enter the choice:");
Scanner in=new Scanner(System.in);
ch=in.nextInt();
switch(ch)
{
case 1:     System.out.println("Enter The Item:");
            int a=in.nextInt();
            ll.add(a);
            break;
case 2:     System.out.println("Enter The Item:");
            a=in.nextInt();
            ll.addFirst(a);
            break;
case 3:     System.out.println("Enter  The Item:");
            a=in.nextInt();
            ll.addLast(a);
            break;
case 4:     System.out.println("Enter the location:");
            int b=in.nextInt();
            System.out.println("Enter  The Item:");
            a=in.nextInt();
            ll.add(b,a);
            break;
case 5:     System.out.println("Enter The location to delete:");
            a=in.nextInt();
            ll.remove(a);
            break;
case 6:     ll.removeFirst();
            break;
case 7:     ll.removeLast();
            break;
case 8:    System.out.println("ELEMENTS ARE:"+ll);
           System.out.println("size of linklist="+ll.size());
           System.out.print("Reverse Data :[ ");
           for(int i=ll.size(); i>0;i--)
             {
             int x=ll.get(i-1);
             System.out.print(+x+" ");
            }
            System.out.print("]\n");
             break;
case 9:   System.exit(0);
default:
              System.out.println("invalid choice:");
             
         }
     }
   }
}
            

Area - Interface

import java.io.*;
import java.util.Scanner;
interface area
{
float pi=3.14F;
void circle();
void square();
}
class imp implements area
{
public void circle()
{
System.out.print("enter the value of Radius:");
Scanner in=new Scanner(System.in);
float r=in.nextFloat();
float carea=pi*r*r;
System.out.println("\nArea of circle ="+carea);
}
public void square()
{
System.out.println("enter the value of side:");
Scanner in=new Scanner(System.in);
float x=in.nextFloat();
float sarea=x*x;
System.out.println("\n Area of circle:"+sarea);
}
}
class Interface
{
public static void main(String[] args)
{
imp obj=new imp();
obj.circle();
obj.square();
}
}

hash table

import java.util.*;
import java.io.*;

public class hash1{
  public static void main(String[] args) throws IOException{
  int key;
  try{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  System.out.print("How many elements you want to enter to the hash table : ");
  int n = Integer.parseInt(in.readLine());
  Hashtable<Integer, String> hashTable = new Hashtable<Integer, String>();
  for(int i = 0; i < n; i++){
  System.out.print("Enter key for the hash table : ");
  key = Integer.parseInt(in.readLine());
  System.out.print("Enter value for the key : ");
  hashTable.put(key, in.readLine());
  }
  Map<Integer, String> map = new TreeMap<Integer, String>(hashTable);
  System.out.println(map);
  }
  catch(NumberFormatException ne){
  System.out.println(ne.getMessage() + " is not a legal value.");
  System.out.println("Please enter a numeric value.");
  System.exit(1);
  }
  }
}

flag

import java.io.*;
import java.applet.*;
import java.awt.*;
public class flag extends Applet
{
public void paint(Graphics g)
{
g.fillOval(60,450,120,50);
g.fillRect(110,60,10,400);
g.setColor(Color.red);
g.fillRect(120,80,150,30);
g.setColor(Color.white);
g.fillRect(120,110,150,30);
g.setColor(Color.green);
g.fillRect(120,140,150,30);
g.setColor(Color.black);
g.drawRect(120,80,150,90);
g.setColor(Color.blue);
g.drawOval(180,110,30,30);
int t=0;
int x=195,y=125;
double x1,y1;
double r=15;
double d;
for(int i=1;i<=24;i++)
{
d=(double)t*3.14/180.0;
x1=x+(double)r*Math.cos(d);
y1=y+(double)r*Math.sin(d);
g.drawLine(x,y,(int)x1,(int)y1);
t+=360/24;
}
}
}

File attributes

import java.io.File;
public class fileats
 {
  public static void main(String[] argv) throws Exception
{
    File f = new File("c:/INSTALL.LOG");

    if (!f.exists()) {
      System.out.println("File not found.");
      return;
    }
    if (f.canRead())
      System.out.println("  Readable");
    else
      System.out.println("  Not Readable");

    if (f.canWrite())
      System.out.println("  Writable");
    else
      System.out.println("  Not Writable");
  
      if(f.isHidden())
      
            System.out.println( " is Hidden.");
else
System.out.println(" Not a Hidden file");
     
  }
}

datediff

import java.io.*;
import java.util.*;
import java.text.*;

public class DiffDate
{
    public static void main(String[] args) throws ParseException, IOException
    {
        DataInputStream in=new DataInputStream(System.in);
       
        DateFormat df = new SimpleDateFormat ("dd-MM-yyyy");
        // Get Date 1
        System.out.print("\nEnter the First Date : ");
        Date d1 = df.parse(in.readLine().trim());
        // Get Date 2
        System.out.print("\nEnter the Second Date : ");
        Date d2 = df.parse(in.readLine().trim());
       
        String relation;
        if (d1.equals(d2))
            relation = "the same date as";
        else if (d1.before(d2))
                relation = "before";
             else
                relation = "after";
        System.out.println(d1 + " is " + relation +" "+ d2);
        long diff = d2.getTime() - d1.getTime( );
        System.out.print("\n\nThe Difference between d1 and d2 is : "+(diff / (1000*60*60*24)));
    }
}

stack

import java.util.*;
import java.io.*;
class StackD {
static void showpush(Stack st, int a) {
st.push(new Integer(a));
System.out.println("push(" + a + ")");
System.out.println("stack: " + st);
}
static void showpop(Stack st) {
System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}
public static void main(String args[])throws IOException
 {
Stack st = new Stack();
DataInputStream d=new DataInputStream(System.in);
int will=1;
System.out.println("stack: " + st);
while(will==1)
{
System.out.println("Enter your choice:");
System.out.println("*****1.Push      2.Pop   3.Exit*****");

int c=Integer.parseInt(d.readLine());
switch(c)
{
case 1:
{
System.out.println("Enter a number to stack:");
int n=Integer.parseInt(d.readLine());
showpush(st, n);
}
break;
case 2:
{
try {
showpop(st);
} catch (EmptyStackException e) {
System.out.println("empty stack");
}
}
break;
default:
System.out.println("Invalid Choice");
}
System.out.println("Do U Want To Continue? 1.Yes 2.No");
will=Integer.parseInt(d.readLine());
}
}
}

Current date and time using applet

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

/*
<APPLET CODE = "curtime.class" WIDTH = "500" HEIGHT = "400">
Download Java Plug In Please
</APPLET>
*/
public class curtime extends Applet implements Runnable
{
  Thread t,t1;
  Label l1,l2;
  TextField t2,t3;
  int day, month, year;
  public void init()
  {
   t2=new TextField(20);
   l1=new Label("Time");
   t3=new TextField(20);
   l2=new Label("Date");
   add(l1);
   add(t2);
   add(l2);
   add(t3); 
  }
  public void start()
  {
   t = new Thread(this);
   t.start();
  }
  public void run()
  {
   t1 = Thread.currentThread();
   while(t1 == t){
   repaint();
   try
   {
    t1.sleep(1000); 
   }
   catch(InterruptedException e)
   {
   }
   }
 }

  public void paint(Graphics g)
  {
    Calendar cal = new GregorianCalendar();
    GregorianCalendar date = new GregorianCalendar();
    String hour = String.valueOf(cal.get(Calendar.HOUR));
    String minute = String.valueOf(cal.get(Calendar.MINUTE));
    String second = String.valueOf(cal.get(Calendar.SECOND));
    String msg=""+hour + ":" + minute + ":" + second;
    t2.setText(msg);
    day = date.get(Calendar.DAY_OF_MONTH);
    month = date.get(Calendar.MONTH);
    year = date.get(Calendar.YEAR);
    String msg1=""+day + ":" + month + ":" + year;
    t3.setText(msg1);
  }
}


Biggest of 3 nos. Using Applet

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
  public class big extends Applet implements ActionListener
  {
        TextField t1,t2,t3,t4;
        Label Result;
        Button b1;
        public void init()
       {
           t1=new TextField(10);
          add(t1);
           
          t2=new TextField(10);
          add(t2);
       
        t3=new TextField(10);
        add(t3);

          b1=new Button("Result");
          add(b1);
             
          b1.addActionListener(this);

          t4=new TextField(10);
          add(t4);
     }
      public void actionPerformed(ActionEvent e)
         {
         if(e.getSource()==b1)
          {
           if((Integer.parseInt(t1.getText())>Integer.parseInt(t2.getText())) && (Integer.parseInt(t1.getText())>Integer.parseInt(t3.getText())))
         
        {
         t4.setText(String.valueOf(t1.getText()));
        }
   
        else if(Integer.parseInt(t2.getText())>Integer.parseInt(t3.getText()))
   
        {
        t4.setText(String.valueOf(t2.getText()));
        }

        else

        {
        t4.setText(String.valueOf(t3.getText()));
        }
              }
         }
  }
/*
<applet code=big.class
width=300
height=400>
</applet>
*/

Thursday, 8 September 2011

Read a File

import java.io.*;
class file
{
public static void main(String args[])throws IOException
{
try
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter the File-Name u want to read");
String f=in.readLine();
FileInputStream f1=new FileInputStream(f);
in=new DataInputStream(f1);
String strline;
while((strline=in.readLine())!=null)
{
System.out.println(strline);
}
in.close();
}
catch(Exception e)
{
System.out.println("error"+ e.getMessage());
}
}
}

Martix Multiplication

import java.io.*;
class matmul
{
public static void main(String args[])throws IOException
{
int a[][]=new int[5][5];
int b[][]=new int[5][5];
int c[][]=new int[5][5];
int i,j,r1,r2,c1,c2,k;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter row & column of Matrix A:");
r1=Integer.parseInt(in.readLine());
c1=Integer.parseInt(in.readLine());
System.out.println("Enter row & column of Matrix B:");
r2=Integer.parseInt(in.readLine());
c2=Integer.parseInt(in.readLine());
if(c1==r2)
{
System.out.println("enter the elements for matrix a");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
a[i][j]=Integer.parseInt(in.readLine());
}
}
System.out.println("enter the elements for matrix b");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
b[i][j]=Integer.parseInt(in.readLine());
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
System.out.println("matrix a is");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println("");
}
System.out.println("matrix b is");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println("");
}
System.out.println("matrix c is");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println("");
}
}
else
System.out.println("matrix can't be multiplied");
}
};

Interface

import java.io.*;

class student
{
int rno;
void getno(int n)
{
rno=n;
}
void dispno()
{
System.out.println("Roll No:"+rno);
}
}

class exam extends student
{
int m1,m2;
void getmarks(int mark1,int mark2)
{
m1=mark1;
m2=mark2;
}
void dispmarks()
{
System.out.println("mark 1:"+m1);
System.out.println("mark 2:"+m2);
}
}
interface sports
{
int sprt=50;
void disp_sprt();
}


class result extends exam implements sports
{
int total;
public void disp_sprt()
{
System.out.println("sports mark="+sprt);
}
void display()
{
dispno();
dispmarks();
disp_sprt();
total=m1+m2+sprt;
System.out.println("total="+total);
}
}

class inheri
{
public static void main(String args[])
{
result s=new result();
s.getno(123);
s.getmarks(70,80);
s.display();
}
}

Count Lines-Vowels-Words in a File.

import java.io.*;
import java.util.*;
class count
{
public static void main(String args[])throws IOException
{
int n=0,ct=0,wo=0;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter the file do u want to read");
String f=d.readLine();
FileInputStream f1=new FileInputStream(f);
DataInputStream in=new DataInputStream(f1);
String strline;
while((strline=in.readLine())!=null)
{
n=n+1;
for(int i=0;i<strline.length();i++)
{
char c=strline.charAt(i);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
{
ct++;
}
}
StringTokenizer st=new StringTokenizer(strline);
while(st.hasMoreTokens())
{
String s=st.nextToken();
wo++;
}
}
System.out.println("File Contains");
System.out.println(n + " Lines");
System.out.println(ct + " Vowels");
System.out.println(wo + " Words"
);
}
}

Armstrong - Prime - Perfect

import java.io.*;
class arm
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
int no;
int r,n1,i,n,j,flag=0;
System.out.println("Enter a number: ");
no=Integer.parseInt(in.readLine());

System.out.println("");

//armstrong

n1=no;
int s=0;
while(n1>0)
{
r=n1%10;
s=s+(r*r*r);
n1=n1/10;
}
if(s==no)
{
System.out.println(s+" is armstrong");
}

System.out.println("");
System.out.println("");

//prime

n1=no;
for(j=2;j<=n1-1;j++)
{
if(n1%j==0)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==0)
System.out.println(n1+"prime");

System.out.println("");
System.out.println("");

//perfect

n1=no;
int s1=0;
for(j=1;j<=n1-1;j++)
{
if(n1%j==0)
s1=s1+j;
}
if(s1==n1)
System.out.println(s1+"perfect");

}
};



Database Program

 import java.sql.*;
 import java.io.*;
 class database
 {
        public static void main(String args[])throws IOException
        {
        String str;
        int ch;
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                try
                {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection c=DriverManager.getConnection("jdbc:odbc:master");
                Statement s=c.createStatement();
               
do
{
System.out.println("\n1->create\n2->insert or update or modify or alter\n3->view\n4->exit\n");
ch=Integer.parseInt(br.readLine());

                switch(ch)
                {
                case 1:
                        {
                        str=br.readLine();
                        boolean a=s.execute(str);
                        if(!a)
                        System.out.println("Table created");
                        }
                        break;
                case 2:
                        {
                        str=br.readLine();
                        int r=s.executeUpdate(str);
                        }
                        break;
                case 3:
                        {
                        str=br.readLine();
                        ResultSet rs=s.executeQuery(str);
                        ResultSetMetaData rsmd = rs.getMetaData();
                        int x=rsmd.getColumnCount();
                        for(int j=1;j<=x;j++)
                        {
                        System.out.print(rsmd.getColumnName(j)+"\t\t");
                        }
                        while(rs.next())
                        {
                        System.out.println("");

                                for(int i=1;i<=x;i++)
                                {
                                System.out.print(rs.getObject(i)+"\t");
                                }

                        }
                        }
                        break;
                }
}while(ch!=4);


                }catch(Exception e)
                {
                System.out.println(e);
                }
          }
}

Encryption & Decryption

import java.io.*;
public class encrypt
{
char[] temp=new char[100];
char current,s;
int asc;
String s1;
int i=0;
void getdata(int y)throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("enter the text file name to encrypt or decrypt");
s1=in.readLine();
File file=new File(s1);
if(!file.exists())
{
System.out.println(s1+"does not exists");
return;
}
FileInputStream fis=new FileInputStream(file);
while(fis.available()>0)
{
temp[i]=(char)fis.read();
i=i+1;
}
int n=i;
FileOutputStream fos=new FileOutputStream(file,false);
for(int j=0;j<n;j++)
{
current=temp[j];
asc=(int)current;
asc=asc+y;
s=(char)asc;
fos.write(s);
}
fos.close();
}
public static void main(String args[])throws IOException
{
encrypt x=new encrypt();
char[] temp=new char[100];
int asc;
int i=0;
String s1;
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.println("1.encryption");
System.out.println("2.decryption");
System.out.println("\tenter ur choice");
int ch=Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
System.out.println("encrypting the file");
x.getdata(4);
System.out.println("the file is encrypted successfully");
break;
case 2:
System.out.println("decrypting the file");
x.getdata(-4);
System.out.println("the file is decrypted successfully");
break;
}
}
catch(IOException e)
{
System.out.println("file not found");
}
}
}

Exception handling in Java

import java.io.*;
class exc1
{
    public static void main(String arg[])throws IOException
      {
             DataInputStream d=new DataInputStream(System.in);
             int c,d1,d2,i,j,sum=0;
             double ans;
             int a[]=new int[5];
             int b[]=new int[5];
             try
             {
             System.out.print("Enter the Divedent=");
             d1=Integer.parseInt(d.readLine());
             System.out.print("Enter the divisor=");
             d2=Integer.parseInt(d.readLine());
             ans=d1/d2;
             System.out.println("The answer ="+ans);
           
             System.out.println("Enter the number in array one by one");
             for(i=0;i<5;i++)
             {
              a[i]=Integer.parseInt(d.readLine());
             }
             System.out.print("Enter which index number do you want to print=");
             c=Integer.parseInt(d.readLine());
             System.out.println(a[c]);
           
             System.out.println("Enter the Integer value one by one to Sum");
             for(j=0;j<5;j++)
             {
             b[j]=Integer.parseInt(d.readLine());
             }
             }
             catch(ArrayIndexOutOfBoundsException e )
              {
                System.out.println("ArrayIndexOutOfBoundsException");
              }
                        
              catch(ArithmeticException e1)
              {
                        System.out.print("Divided by Zero");
              }
                  
          catch(NumberFormatException e2)
          {
            System.out.println("NumberFormatException");
            for(j=0;j<5;j++)
            sum=sum+b[j];
            System.out.print("The Sum of remaining valid integer ="+sum);
          }
}
}

Wednesday, 7 September 2011

Thread

import java.io.*;

public class T1 extends Thread
{
public void run()
{
for(int i=0; i < 5; i++)
{
System.out.println("Child Thread : " + i);
try
{
Thread.sleep(50);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Child thread finished!");
};

public static void main(String[] args) throws IOException
{
Thread t = new Thread(new T1(), "My Thread");
t.start();
for(int i=0; i < 5; i++)
{
System.out.println("Main thread : " + i);
try
{
Thread.sleep(100);
}
catch(InterruptedException ie)
{
System.out.println("Child thread interrupted! " + ie);
}
}
System.out.println("Main thread finished!");
}
}

Synchronized Thread

import java.io.*;
class display
{
synchronized void show(int n)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
}
System.out.println(n+"the multiplication table");
}
}
class fivetable extends Thread
{
display d;
fivetable(display d)
{
this.d=d;
}
public void run()
{
d.show(5);
for(int i=1;i<=5;i++)
System.out.println(i+"*"+5+"="+(i*5));
}
}
class seventable extends Thread
{
display d;
seventable (display d)
{
this.d=d;
}
public void run()
{
d.show(7);
for(int i=1;i<=7;i++)
System.out.println(i+"*"+7+"="+(i*7));
}
}
class tentable extends Thread
{
display d;
tentable (display d)
{
this.d=d;
}
public void run()
{
d.show(10);
for(int i=1;i<=10;i++)
System.out.println(i+"*"+10+"="+(i*10));
}
}
class thread1
{
public static void main(String args[])
{
display d=new display();
fivetable t1=new fivetable(d);
seventable t2=new seventable(d);
tentable t3=new tentable(d);
t1.start();
t2.start();
t3.start();
}
}

Multi Thread

import java.io.*;

class A extends Thread
{
public void run()
{
for(int i=1;i<=3;i++)
{
System.out.println(i+" Execution of thread A");
}
System.out.println("Exit A");
}
};


class B extends Thread
{
public void run()
{
for(int j=1;j<=3;j++)
{
System.out.println(j +" execution of thread B");
}
System.out.println("Exit B");
}
};

class C extends Thread
{
public void run()
{
for(int k=1;k<=3;k++)
{
System.out.println(k +" execution of thread c");
}
System.out.println("Exit C");
}
};

class multithread
{
public static void main(String args[])throws IOException
{
new A().start();
new B().start();
new C().start();
}
};

Single Thread

import java.io.*;
public class single
{
public static void main(String st[]) throws IOException
{
Thread th=new Thread();
System.out.println("Numbers are printed line by line after 5 sec");
 try
{
for(int i=1;i<=10;i++)
{
 System.out.println(i);
 th.sleep(5000);
}
}
catch(InterruptedException e)
{
System.out.println("Thread Interrupted");
e.printStackTrace();
}
}
}

Tuesday, 6 September 2011

Java Programming Lab Cycle 1


Java Programming
Lab Cycle 1
1.Write a program to show how to handle the following exceptions
          1.Array Index out of bounds exception
          2.Divide by zero exception
          3.Arithmetic exception
2.Write a program to encrypt and decrypt a file
3.Write a program to implement the concept of single thread, multi thread, synchronized thread.
4.Write  a database program about the following.
          1.To read data from database with fields such as name,id,city and country.
          2.To insert a set of values into the table using Java Frame.
          3.To print and update the salary for a given employee number.
5.Write a program whether the Given number is armstrong or prime or perfect or not?
6.Write a program to count no. of words,vowels,lines in a given file.
7.Write a java program to show inheritance.
8.Write a program to show matrix multiplication.
9.Write a program to print the contents of file using filestream class.