Monday 19 January 2015

Write JAVA Program to print string length using extended thread.

File Name = exteded_thread .java


import java.util.Scanner;
class demo1 extends Thread
{
   Thread t;
   String threadName,s;
   demo1(String name)
   {
       Scanner in = new Scanner(System.in);
       threadName = name;
       System.out.println("Creating Thread......");
       try
        {  
            Thread.sleep(1000);
        }
        catch(InterruptedException e)
        {
            System.out.println("Erroe is --> "+e);
        }
   }
   public void run()
   {
      System.out.println("Running Thread......");
      try
      {     Thread.sleep(1000);
            System.out.println("length Of String Is -->"+s.length());
            Thread.sleep(1000);
      }
      catch(InterruptedException e)
        {
            System.out.println("Erroe is --> "+e);
        }
     System.out.println("Thread Is exiting.");
   }
   public void start ()
   {
      if (t == null)
      {
         t = new Thread (this, threadName);
         t.start ();
      }
   }
}
public class exteded_thread
{  
    public static void main(String args[])
     {
      String s="Wellcome";
      demo1 T1 = new demo1(s);
      T1.start();
     }
}

Write JAVA Program to print 1 to 10 using thread and synchronization.

Write JAVA Program to print 1 to 10 using thread without synchronization.


Write JAVA thread Program to find length of String.

File Name=RunnableDemo

import java.util.Scanner;
class RunnableDemo1 implements Runnable
{
   private Thread t;
   private String threadName;
   String s;
   RunnableDemo1(String name)
   {
   Scanner in = new Scanner(System.in);
   threadName = name;
   System.out.println("Enter String ");
   s = in.nextLine();
   }

  public void run()
{
        try {
                Thread.sleep(5000);
                System.out.println("length Of Thread " +  s.length());
            }
            catch (InterruptedException ex)
            {
               System.out.println("Exception "+ex');
            }
   }

   public void start ()
   {
         t = new Thread (this, threadName);
         t.start ();
   }
}

public class RunnableDemo
{
   public static void main(String args[])
  {
      RunnableDemo1 R1 = new RunnableDemo1("Thread-1");
      R1.start();
   }
}

    

JAVA Program to implement Simple Thread program

File name = RunnableDemo.java 


class RunnableDemo1 implements Runnable
{
   private Thread t;
   private String threadName;
   RunnableDemo1(String name)
   {
   threadName = name;
   System.out.println("Thread Is Start"+  threadName );
   }
  public void run()
  {
        try {
                Thread.sleep(5000);
                System.out.println("Thread Is Running " +  threadName );
                Thread.sleep(5000);
                System.out.println("length Of Thread " +  threadName.length());
            }
            catch (InterruptedException ex)
            {
                System.out.println("Exception is  "+ex);
            }
        System.out.println("Thread Is Exit " +  threadName );
   }
   public void start ()
   {
         t = new Thread (this, threadName);
         t.start ();
System.out.println("Thread Is Create "+  threadName );
   }
}

public class RunnableDemo
{
   public static void main(String args[])
 {
      RunnableDemo1 R1 = new RunnableDemo1("Thread-1");
      R1.start();
   }  
}


Tuesday 14 October 2014

C Program to crate lexical analyzer which will do space removal.

#include
#include
#include
#include

int key = 0;
char expr[100];
char cont[][20]={"CONTROLS","for","do","while","NULL",};
char cond[][20]={"CONDITION","if","then","NULL"};
char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};
char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};

void checking(char[],char[][20]);

void main()
{
int i,j,l,k,m,n;
char sbexpr[50],txt[3];
clrscr();
cout<<"Enter the expression:";
gets(expr);
for(i=0;expr[i]!=NULL;i++)
{
key=0;
for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)
sbexpr[k]=expr[j];
sbexpr[k]=NULL;

if(key==0) checking(sbexpr,cond);

if(key==0) checking(sbexpr,cont);

if(key==0) checking(sbexpr,branch);

if(key==0)
{
for(m=0;sbexpr[m]!=NULL;m++)
{
key=0;
txt[0]= sbexpr[m];
txt[1] = NULL;

if(key==0) checking(txt,oprt);
if((key==0) || ((sbexpr[m]>=97 && sbexpr[m]<=122) || (sbexpr[m]>=65 && sbexpr[m]<=90)))
{
cout<<"\n"<"<<"Identifier\n";
key = 1;
}
}
}
if(key == 0)
{
cout<<"\n"<"<<"Address\n";
key = 1;
}
}

getch();
}


void checking (char expr[],char check[][20])
{
for(int i=1;strcmp(check[i],"NULL")!=0;i++)
{
if(strcmp(expr,check[i])==0)
{
cout<"<key = 1;
}
}
}

C Program to implement Recursive Deceptive Parsing

#include
#include
#include
void main()
{
int i,j,k;
char a[20],b[20],c[20],m,n[10],o[10];
clrscr();
printf("Enter a recursive string:");
gets(a);
if(a[0]==a[3]) {
m=a[0];
printf("%c\n",m);
}
else {
printf("Entered string is not recursive");
}
j=0;
for(i=4;a[i]!=NULL;i++) {
if(a[i]!='/') {
b[j++]=a[i];
printf("%c",b[j]);
}
else {
goto a1;
}
}
a1:
b[j]='\0';
j=0;
for(i=i+1;a[i]!=NULL;i++) {
c[j]=a[i];
j++;
}
c[j]='\0';
n[0]=m;
n[1]='-';
n[2]='>';
j=3;
for(i=0;c[i]!=NULL;i++) {
n[j]=c[i];
j++;
}
n[j++]=m;
n[j++]='`';
n[j++]='\0';
printf("\n\nOutput string1 is:");
puts(n);
o[0]=m;
o[1]='-';
o[2]='>';
j=3;
for(i=0;b[i]!=NULL;i++)
{
o[j]=b[i];
j++;
}
puts(b);
o[j++]=m;
o[j++]='`';
o[j++]='/';
o[j++]='$';
o[j++]='\0';
printf("\n\nOutput string is:");
puts(o);
getch();
}