Monday, August 29, 2011

How to Develop Android Applications Using Eclipse IDE

Eclipse is a common Integrated Development Environment  acting as a platform to develop applications with GUI's.Eclipse IDE is also available for Java, for developing Java Applications.Since Android is an Operating System with Java Programming Interface ,applications for Android are mostly Coded in Java.In this Post i will show you how to Configure Eclipse for Developing Android Applications.

  • Enter this URL https://dl-ssl.google.com/android/eclipse/ or http://dl-ssl.google.com/android/eclipse/ into the text box corresponding to the works with label..


  • Wait for the Plugins to be listed ,Check the Boxes ,Click on Next.
  • Wait for the Installation to be completed.Done!Your IDE is ready for developing android apps. 

               

Java Program to Check whether a Expression is Valid using Stack

The Program given below can be used to check whether a given mathematical expression is valid or invalid.The Validation procedure is based on the presence of complementary opening and closing braces.This implementation makes use of stack to push and pop out opening and closing brackets to the stack, as they are encountered in the Expression String.This program pushes opening brackets to the stack and pops out closing braces,checking whether the complementary brace is present at the top of the stack.Finally if the stack is empty the Expression is valid else the Expression is Invalid.

sample Output:
Enter the string
(a+b)-c
Valid Expression

Enter the string
(a+b-c
Invalid expression
The Complete Source Code is Provided below
 import java.io.*;  
 import java.lang.*;  
 class array  
 {  
  DataInputStream get=new DataInputStream(System.in);  
  int n,i,top=0,f=0;  
  char a[];  
  String str;  
  void getdata()  
  {  
  try  
   {  
   a=new char[30];  
   System.out.println("Enter the string");  
   str=get.readLine();  
   n=str.length();  
  }  
  catch(Exception e)  
  {  
   System.out.println(e.getMessage());  
  }  
  }  
  void push(char c)  
  {  
   a[top]=c;  
   top++;  
  }  
  char pop()  
  {  
   char h;  
  if(top!=0)  
   {  
   top--;  
   h=a[top];  
   return h;  
   }  
  else  
  return 0;  
  }  
  int stempty()  
  {  
   if(top==0)  
   return 1;  
   else  
   return 0;  
  }  
  void operation()  
  {  
  char d,t;  
  for(i=0;i<n;i++)  
   {  
   d=str.charAt(i);  
   switch(d)  
     {  
     case '(':  
         {  
          push(d);  
          break;  
         }  
     case '{':  
         {  
          push(d);  
          break;  
         }  
     case '[':  
         {  
          push(d);  
          break;  
         }  
     case ')':  
         {  
          t=pop();  
          if(t!='(')  
          f=1;  
          break;  
         }  
     case '}':  
         {  
          t=pop();  
          if(t!='{')  
          f=1;  
          break;  
         }  
     case ']':  
         {  
          t=pop();  
          if(t!='[')  
          f=1;  
          break;  
         }  
     }  
     }  
  if(f==0&&top==0)  
  {  
   System.out.println("Valid Expression");  
  }  
  else  
   System.out.println("Invalid expression");  
  }  
 }  
 class validexp  
 {  
  public static void main(String arg[])  
  {  
   array obj=new array();  
   obj.getdata();  
   obj.operation();   
  }  
 }  

Sunday, August 28, 2011

Java Program to Perform Linear Search

Linear Search is a Sequential Searching algorithm, it is commonly used to find an element in an array.It works by checking whether each element in the array is equal to the element to be found.This done by Incrementing the Index of the array.If the element is found a flag variable is set to indicate the presence of the element and the index of the array ,where the element is found is reported.The Complete Source Code to implement Linear Search in java is provided below.
 import java.io.*;  
 import java.lang.*;  
 class Linear  
 {  
 DataInputStream get;  
 int a[];  
 int key,n,i;  
 void getdata()  
 {  
  try  
  {  
   get=new DataInputStream(System.in);  
   System.out.println("Enter the size");  
   n=Integer.parseInt(get.readLine());  
   a=new int[n];  
   System.out.println("Enter the elements");  
   for(i=0;i<n;i++)  
   a[i]=Integer.parseInt(get.readLine());  
   System.out.println("Enter the key element");  
   key=Integer.parseInt(get.readLine());  
  }  
  catch(Exception e)  
  {  
   System.out.println(e.getMessage());  
  }  
 }  
 void search()  
 {  
 int flag=0,j,i;  
 int pos[]=new int[10];  
 for(i=0,j=0;i<n;i++)  
  {  
  if(key==a[i])  
  {  
   flag=1;  
   pos[j]=i+1;  
   j++;  
  }  
  }  
 if (flag==1)  
 {  
  System.out.println("Element is found in position:");  
  for(i=0;i<j;i++)  
  System.out.print(pos[i]+" ");  
 }  
 else  
  System.out.println("Element not present in this array");  
 }  
 }  
 class Linearsearch  
 {  
 public static void main(String arg[])  
 {  
  Linear obj=new Linear();  
  obj.getdata();  
  obj.search();  
 }  
 }  

Wednesday, August 24, 2011

Java Program to Perform Infix to PostFix Conversion

The Program given below Converts an Infix Expression to Post Fix Expression.For eg: ((l+i)*n-(o-p)^(q+p)) would be Converted to li+n*op-qp+^- .The Complete Source Code is Provided Below
 import java.lang.*;   
 import java.io.*;
  class array   
  {   
  DataInputStream get=new DataInputStream(System.in);   
  int n,i,top;   
  char s[],a[];   
  String str;   
  void getdata()   
  {   
  try   
   {   
   System.out.println("Enter the expression:");   
   str=get.readLine();   
   n=str.length();   
   s=new char[40];   
   a=new char[40];   
  }   
  catch(Exception e)   
  {   
   System.out.println(e.getMessage());   
  }   
  top=0;   
  }   
  void push(char c)    
  {   
   s[top]=c;   
   top++;   
  }   
  char pop()   
  {   
   char h;   
  if(top!=0)   
   {   
   top--;   
   h=s[top];   
   return h;   
   }   
  else   
   return 0;   
  }   
  void operation()   
  {   
  int j=0;   
  char d=0;   
  char t;   
  for(i=0;i<n;i++)   
   {   
   t=str.charAt(i);   
   switch(t)   
    {   
    case'^':   
      {   
      push(t);   
      break;   
      }   
    case '(':   
      {   
      push(t);   
      break;   
      }   
    case '{':   
      {   
      push(t);   
      break;   
      }   
    case '[':   
      {   
      push(t);   
      break;   
      }   
    case ')':   
      {   
      while((d=pop())!='(')   
      {   
       a[j++]=d;   
      }   
      break;   
      }   
    case '}':   
      {   
      while((d=pop())!='{')   
      {   
       a[j++]=d;   
      }   
      break;   
      }   
    case ']':   
      {   
      while((d=pop())!='[')   
      {   
       a[j++]=d;   
      }   
      break;   
      }   
    case '+':   
      {   
      if(s[top]=='/'||s[top]=='*'||s[top]=='^')   
      {   
      a[j++]=pop();   
      }   
      push(t);   
      break;   
      }   
    case '-':   
      {   
      if(s[top]=='+'||s[top]=='/'||s[top]=='*'||s[top]=='^')   
      {   
       a[j++]=pop();   
      }   
      push(t);   
      break;   
      }   
    case '*':   
      {   
      if(s[top]=='^')   
      {   
       a[j++]=pop();   
      }   
      push(t);   
      break;   
      }   
    case '/':   
      {   
      if(s[top]=='^'||s[top]=='*')   
      {       
       a[j++]=pop();   
      }   
      push(t);   
      break;   
      }   
    default:   
      a[j++]=t;   
    }   
   }   
   while(top!=0)   
   {   
   if(s[top]!='(')   
   {   
    a[j++]=pop();   
    }   
   }   
    System.out.println("The postfix expression is:");   
    for(i=0;i<j;i++)   
    System.out.print(a[i]);   
  }   
  }   
  class postcon   
  {   
  public static void main(String arg[])   
  {   
  array obj=new array();   
  obj.getdata();   
  obj.operation();   
  }   
  } 

Sunday, August 21, 2011

Protecting Jar files from Decompilation by Code Obsfuscation using SmokeScreen

Today every program has a threat from decompilation and reverse Engineering.This threat is not limited to Executable(.exe) files ,Jar files (.jar) can be unpacked and reverse engineered easily than an Executable(.exe) file.The Java program source code can be easily be reconstructed from the class files.

This does not mean that .jar files are Insecure.Several methods can be used to Protect or Pack a Jar file.Code Obfuscation is means of protecting a Java File by Complicating or Obfuscation of the Source Code.Many code Obfuscation tools are available and Smoke Screen is one of it.

Smoke Screen has a clean user Interface and Codes can be obfuscated with the click of button.You can get Smoke Screen from its official website http://www.leesw.com/smokescreen/ 

Now i will tell you how to protect a .jar file by using smokescreen

1)Open Smoke Screen and Select the Jar file you want to Protect by Clicking the Browse Button Next to the Source Tab.

2)Give the Name and Path of the Protected /Obfuscated Jar file By Clicking the Browse Button next to the Destination tab.

3)Click on Start.Wait for the Process to Finish.Done! The Protected jar file can be obtained from the Destination location you specified.

Friday, August 19, 2011

Java Program to Impliment Circular Queue

The Java Source Code given below can be used to Implement a Circular Queue.
 import java.io.*;  
 import java.lang.*;  
 class clrqueue  
 {  
  DataInputStream get=new DataInputStream(System.in);  
  int a[];  
  int i,front=0,rear=0,n,item,count=0;  
  void getdata()  
  {  
  try  
   {  
   System.out.println("Enter the limit");  
   n=Integer.parseInt(get.readLine());  
   a=new int[n];  
   }   
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
   }  
  }  
  void enqueue()  
  {  
   try  
   {  
   if(count<n)  
    {  
    System.out.println("Enter the element to be added:");  
    item=Integer.parseInt(get.readLine());  
    a[rear]=item;  
     rear++;  
    count++;  
    }  
   else  
    System.out.println("QUEUE IS FULL");  
   }  
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
   }  
  }  
  void dequeue()  
  {  
   if(count!=0)  
    {  
    System.out.println("The item deleted is:"+a[front]);  
    front++;  
    count--;  
    }  
   else  
    System.out.println("QUEUE IS EMPTY");  
  if(rear==n)  
   rear=0;  
  }  
  void display()  
  {  
   int m=0;  
   if(count==0)  
   System.out.println("QUEUE IS EMPTY");  
   else  
   {  
   for(i=front;m<count;i++,m++)  
   System.out.println(" "+a[i%n]);  
   }  
  }  
 }  
 class myclrqueue  
 {  
  public static void main(String arg[])  
  {  
  DataInputStream get=new DataInputStream(System.in);  
  int ch;  
  clrqueue obj=new clrqueue();  
  obj.getdata();  
  try  
  {  
   do  
   {  
   System.out.println(" 1.Enqueue  2.Dequeue  3.Display  4.Exit");  
   System.out.println("Enter the choice");  
   ch=Integer.parseInt(get.readLine());  
   switch (ch)  
   {  
   case 1:  
       obj.enqueue();  
      break;  
   case 2:  
      obj.dequeue();  
      break;  
   case 3:  
      obj.display();  
      break;  
   }  
   }  
   while(ch!=4);  
  }  
  catch(Exception e)  
  {  
  System.out.println(e.getMessage());  
  }  
  }  
 }  

Binary Search Program Source Code in Java

The Java Program given below can be used to find an Element in array using Binary Search Technique.
The Main steps Involved here are
1)A Pivot Element is Found
2)The array is sorted in such a way that elements greater than the pivot lies to the right and elements lesser lies to the left of the pivot.
3)Linear search is applied by taking the appropriate limits.,depending upon whether the element to be searched is greater or lesser than the pivot. 
 class array  
 {  
  DataInputStream get;  
  int a[];  
  int i,j,n,key;  
  void getdata()  
  {  
  try  
  {  
   get=new DataInputStream(System.in);  
   System.out.println("Enter the limit");  
   n=Integer.parseInt(get.readLine());  
   a=new int[n];  
   System.out.println("Enter the elements");  
   for(i=0;i<n;i++)  
   a[i]=Integer.parseInt(get.readLine());  
  }  
  catch(Exception e)  
  {  
   System.out.println(e.getMessage());  
  }  
  }  
 void sorting()  
 {  
 int t,j;  
 for(j=0;j<n;j++)  
 {  
  for(i=0;i<n-1;i++)  
  {  
  if(a[i]>a[i+1])  
   {  
   t=a[i];  
   a[i]=a[i+1];  
   a[i+1]=t;  
   }  
  }  
  }  
  System.out.println("Elements in ascending order is:");  
  for(i=0;i<n;i++)  
  System.out.print(a[i]+" ");  
  System.out.println();  
  try  
  {  
  System.out.println("Enter the key element");  
  key=Integer.parseInt(get.readLine());  
  }  
  catch(Exception e)  
  {  
   System.out.println(e.getMessage());  
  }  
  }  
  void search()  
  {  
  int m,flag=0,l,u,p=0;  
  l=0;  
  u=n-1;  
  while(l<=u)  
  {  
   m=(l+u)/2;  
   if(a[m]==key)  
   {  
   flag=1;  
   p=m+1;  
   break;  
   }  
   else if(a[m]<key)  
   l=m+1;  
   else  
   u=m-1;  
  }  
  if(flag==0)  
   System.out.println("The number is not found");  
  else  
   System.out.println("The number is found in:"+p);  
  }  
 }   
 class binarysearch  
 {  
 public static void main(String arg[])  
 {  
  array obj=new array();  
  obj.getdata();  
  obj.sorting();  
  obj.search();  
  }  
 }  


Java Program to Add two Numbers using Linked List

The Program below inserts two numbers to a Linked list and Adds them to produce the output.
 import java.io.*;  
 import java.lang.*;  
 class node  
 {  
   int data;  
   node next;  
   node prev;  
   node(int d)  
   {  
     data=d;  
     next=null;  
     prev=null;  
   }  
 }  
 class list  
 {  
   node first=null;  
   node curr=null;  
   void insert(int d)  
   {  
     node n1=new node(d);  
     curr=first;  
     if(curr==null)  
       first=n1;  
     else  
     {  
       while(curr.next!=null)  
         curr=curr.next;  
       curr.next=n1;  
     }  
   }  
   void display()  
   {  
     curr=first;  
     if(curr==null)  
       System.out.println("no list");  
     else  
     {  
       while(curr!=null)  
       {  
         System.out.print(curr.data);  
         curr=curr.next;  
       }  
     }  
   }  
 }  
 public class Sum {  
   public static void main(String[] args) {  
    DataInputStream get=new DataInputStream(System.in);  
    list l1=new list();  
    list l2=new list();  
    list l3=new list();  
    node curr1,curr2,curr3;  
    int n1,n2,n3;  
    int p,q,d,e;  
    try  
    {  
      System.out.println("Enter 1st no:");  
      n1=Integer.parseInt(get.readLine());  
      System.out.println("Enter 2nd no:");  
      n2=Integer.parseInt(get.readLine());  
      p=0;  
      while(n1>0)  
      {  
        d=n1%10;  
        p++;  
        l1.insert(d);  
        n1=n1/10;  
      }  
      n3=n2;  
      q=0;  
      while(n3>0)  
      {  
        d=n3%10;  
        q++;  
        l2.insert(d);  
        n3=n3/10;  
      }  
      while(p>q)  
      {  
        l2.insert(0);  
        p--;  
      }  
      while(q>p)  
      {  
        l1.insert(0);  
        q--;  
      }  
      e=0;  
      curr1=l1.first;  
      curr2=l2.first;  
      while(curr1!=null&&curr2!=null)  
      {  
        e=e+curr1.data+curr2.data;  
        if(e>=10)  
        {  
         d=e%10;  
         l3.insert(d);  
         e=e/10;  
        }  
        else  
        {  
          l3.insert(e);  
          e=0;  
        }  
      curr1=curr1.next;  
      curr2=curr2.next;  
      }  
      node temp=null;  
      int s=0;  
      int i,j;  
      curr3=l3.first;  
      while(curr3!=null)  
      {  
        temp=curr3;  
        s++;  
        curr3=curr3.next;  
      }  
      curr3=l3.first;  
      s=s/2;  
      for(j=0;j<s;j++)  
      {  
        i=curr3.data;  
        curr3.data=temp.data;  
        temp.data=i;  
        curr3=curr3.next;  
        temp=temp.prev;  
      }  
      System.out.println("Sum=");  
      l3.display();  
    }  
    catch(Exception k)  
    {  
      System.out.println(k.getMessage());  
    }  
   }  
 }  

Java Program to display prime numbers from a group of numbers added to a LinkedList

The Program given below adds the given numbers to a linked list,checks if each of them is prime and displays prime numbers.
 import java.io.*;  
 class node  
 {  
   int data;  
   node next;  
   node(int d)  
   {  
     data=d;  
     next=null;  
   }  
   int display()  
   {  
     return(data);  
   }  
 }  
 class list  
 {  
   node first=null;  
   void insert(int d)  
   {  
     node n1=new node(d);  
     node curr;  
     curr=first;  
     if(curr==null)  
       first=n1;  
     else  
     {  
       n1.next=first;  
       first=n1;  
     }  
   }  
   void display()  
   {  
     node curr;  
     curr=first;  
     while(curr!=null)  
     {  
       int e=curr.display();  
       System.out.print(" "+e);  
       curr=curr.next;  
     }  
   }  
  }  
 public class JavaApplication2   
 {  
   public static void main(String[] args)   
   {  
     DataInputStream get=new DataInputStream(System.in);  
     int c,i,a,n,f;  
     node curr1;  
     list l1=new list();  
     list l2=new list();  
     try  
     {  
      System.out.println("Enter the limit");  
      n=Integer.parseInt(get.readLine());  
      System.out.println("Enter the nos:");  
      for(i=0;i<n;i++)  
      {   
        c=Integer.parseInt(get.readLine());  
        l1.insert(c);  
      }  
      curr1=l1.first;  
      while(curr1!=null)  
      {  
        a=curr1.data;        
        f=0;  
        for(i=2;i<(a/2);i++)  
        {  
          if(a%i==0)  
          {  
            f=1;  
            break;  
          }    
        }  
       if(f==0)  
        l2.insert(a);  
       curr1=curr1.next;  
      }  
      System.out.println("Prime nos are:");  
      l2.display();  
     }  
     catch(Exception e)  
     {  
       System.out.println(e.getMessage());  
     }  
   }  
 }  

Java Program Source Code to Add Two Polynomials

The Following Java Program can be used to add two polynomials of any degree.
 package poly;  
 /**  
  *  
  * @author www.c-madeeasy.blogspot.com  
  */import java.io.*;  
 class node  
 {  
   int coef;  
   int pow;  
   node next;  
   node(int c,int p)  
   {  
     coef=c;  
     pow=p;  
     next=null;  
   }  
   void display()  
   {  
     System.out.println("coef="+coef+" pow="+pow);  
   }  
 }  
 class list  
 {  
   node first=null;  
   void insert(int c,int p)  
   {  
     node n1=new node(c,p);  
     node curr;  
     curr=first;  
     if(curr==null)  
       first=n1;  
     else  
     {  
       n1.next=first;  
       first=n1;  
     }  
   }  
   void display()  
   {  
     node curr;  
     curr=first;  
     while(curr!=null)  
     {  
       curr.display();  
       curr=curr.next;  
     }  
   }  
  }  
 public class Poly {  
   /**  
    * @param args the command line arguments  
    */  
   public static void main(String[] args) {DataInputStream get=new DataInputStream(System.in);  
     int c,i,a,n;  
     node curr1,curr2;  
     list l1=new list();  
     list l2=new list();  
     list l3=new list();  
     try  
     {  
      System.out.println("Enter the polynomial degree:");  
      n=Integer.parseInt(get.readLine());  
      System.out.println("first polynomial:");  
      for(i=0;i<=n;i++)  
      {  
        System.out.println("Enter coeff. of term of power "+i);  
        c=Integer.parseInt(get.readLine());  
        l1.insert(c,i);  
      }  
      System.out.println("second polynomial:");  
      for(i=0;i<=n;i++)  
      {  
        System.out.println("Enter coeff. of term of power "+i);  
        c=Integer.parseInt(get.readLine());  
        l2.insert(c,i);  
      }  
      curr1=l1.first;  
      curr2=l2.first;  
      while((curr1!=null)&&(curr2!=null))  
      {  
        a=curr1.coef+curr2.coef;        
        int p=curr1.pow;  
        l3.insert(a,p);  
        curr1=curr1.next;  
        curr2=curr2.next;  
      }  
      System.out.println("Polynomial after addition");  
      l3.display();  
     }  
     catch(Exception e)  
     {  
       System.out.println(e.getMessage());  
     }  
     // TODO code application logic here  
   }  
 }  

Saturday, August 13, 2011

Depth First Search Program in Java

DFS:Depth First Search is a Method to Traverse a Tree and find the Required Element in a Tree.This Algorithm is referred to as Depth First Search because is Spans the Tree in Various Levels or Depths to Find an Element.

DFS uses a Stack to Insert the Elements of a Tree as it is spanned. Several Variables are used to Indicate whether a Node is Visited ,Unvisited or in Processing State.The Complete Java Source Code to Implement DFS is provided below
 import java.io.*;   
  import java.lang.*;   
  /** Compose  
  * @author www.c-madeeasyblogspot.com   
  */   
  class stack   
  {   
   int a[]=new int[20],top=0;   
   void push(int p)   
   {   
    a[top]=p;   
    top++;   
   }   
   int pop()   
   {   
    int h;   
    top--;   
    h=a[top];   
    return h;   
   }   
  }   
  public class DFS {   
   /**   
   * @param args the command line arguments   
   */   
   public static void main(String[] args) {   
    stack mystack=new stack();   
    int n=0;   
    String[] label=new String[10];   
    int x;   
    int status[]=new int[10];   
    int am[][]=new int[50][50];   
    int a[]=new int[10];   
    DataInputStream get=new DataInputStream(System.in);   
   try   
   {   
   System.out.println("Enter the no of vertices");   
   n=Integer.parseInt(get.readLine());   
   System.out.println("Enter labels");   
   for(int i=0;i<n;i++)   
   {   
    label[i]=get.readLine();   
   }   
    System.out.println("Enter AM");   
    for(int i=0;i<n;i++){   
     for(int j=0;j<n;j++)   
     {   
     am[i][j]=Integer.parseInt(get.readLine());    
     status[i]=1;   
     }   
    }   
     mystack.push(0);   
     status[0]=2;   
     x=mystack.pop();   
     a[0]=x;   
     status[0]=3;   
    for(int i=1;i<n;i++)   
    {   
    for(int j=0;j<n;j++)    
    {   
    if(am[x][j]==1&&status[j]==1)    
    {   
     mystack.push(j);   
     status[j]=2;   
    }   
    }   
    x=mystack.pop();   
    a[i]=x;   
    status[x]=3;   
    }   
    System.out.println("DFS is");   
    for(int i=0;i<n;i++)   
    {   
     int m=a[i];   
     System.out.print(" "+label[m]);   
    }    
   }   
  catch(Exception e)   
   {   
   System.out.println(e.getMessage());   
   }   
   }   
  }   

WJJHAEUVSUQD

Stack using Array in Java+Complete Source Code

Stack is a Linear Data Structure.Stack can be Implemented easily by using an array in Java or C.Every Stack has two Main Operations/Methods

a)Push()-Used to Insert an Element to the Stack

b)Pop()- Used to Remove an Element from the Stack

Stack follows a LIFO (Last in First Out)approach.In this method the element inserted last is removed first.The Topmost Element of the Stack is referred to as the top of the stack.When an element is inserted it is inserted at a position above the top.Pop method is used to remove an element from the Stack and always the element at the top is removed from the Stack.
Stack may Throw two exceptions 1.Stack Overflow 2.Stack Empty these can be handled by checking if(top=array length) and if(top=0) respectively.The Complete Source Program to Implement a Stack using array is Provided Below.


 package stack;  
 import java.io.*;  
 import java.lang.*;  
 import java.util.logging.Level;  
 import java.util.logging.Logger;  
 /**  
  *  
  * @author www.c-madeeasy.blogspot.com  
  */  
  class mystack {  
  DataInputStream get=new DataInputStream(System.in);  
  int a[];  
  int i,top=0,n,item,out;  
  void getdata()  
  {  
  try  
   {  
   System.out.println("Enter the limit");  
   n=Integer.parseInt(get.readLine());  
   a=new int[n];  
   }   
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
   }  
  }  
  void push(int item)  
  {  
    if(top==n)  
    {  
      System.out.println("STACK IS FULL");  
    }  
    else  
    {  
    a[top]=item;  
    top++;  
    }  
  }  
  void pop()  
  {  
    if(top==0)   
    {  
     System.out.println("STACK EMPTY");   
    }  
    else  
    {  
      top--;  
      out=a[top];  
    }  
    System.out.println(out);  
  }  
  void display()  
  {  
    if(top==0){  
      System.out.println("STACK EMPTY");    
    }  
    else  
   {  
   for(i=top-1;i>=0;i--)  
    System.out.println(+a[i]);  
   }  
  }  
   }  
 class Stack  
 {  
   public static void main(String[]args)  
   {  
      DataInputStream get=new DataInputStream(System.in);  
  int ch = 0,t = 0;  
  mystack obj=new mystack();  
  obj.getdata();  
  System.out.println("1.PUSH 2.POP 3.DISPLAY");  
     try {  
       ch=Integer.parseInt(get.readLine());  
     } catch (IOException ex) {  
       Logger.getLogger(Stack.class.getName()).log(Level.SEVERE, null, ex);  
     }  
     while(ch!=4)  
     {  
       System.out.println("1.PUSH 2.POP 3.DISPLAY");  
  switch(ch)  
  {  
    case 1:  
      try{  
      t=Integer.parseInt(get.readLine());  
      }  
      catch(IOException e)  
      {  
      }  
      System.out.println("value");  
       try {  
       t=Integer.parseInt(get.readLine());  
       obj.push(t);  
     } catch (IOException ex) {  
       Logger.getLogger(Stack.class.getName()).log(Level.SEVERE, null, ex);  
     }  
      break;  
    case 2:  
      obj.pop();  
      break;  
          case 3:obj.display();  
            break;  
  }  
 }  
   }  
 }  

Queue using array in Java + Complete Program Source Code to Implement a Queue

Queue is an a Linear Data Structure which follows a FIFO(First in First Out) approach.There are two operations for a Queue
a)Enqueue -Insert an Element to the Queue
b)DeQueue -Remove an Element from the Queue

The Element Inserted First is Removed first from the Queue.A Queue has two main Postions
a)Rear- The Position/Element at the End of the Queue
b)Front-The Front most Element/Position of the Queue
In a Queue elements are Enqueued to the Rear and DeQueued from the Front.
The Program given below shows the Implementation a Queue un Java using an Array.

 import java.io.*;  
 import java.lang.*;  
 class clrqueue  
 {  
  DataInputStream get=new DataInputStream(System.in);  
  int a[];  
  int i,front=0,rear=0,n,item,count=0;  
  void getdata()  
  {  
  try  
   {  
   System.out.println("Enter the limit");  
   n=Integer.parseInt(get.readLine());  
   a=new int[n];  
   }   
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
   }  
  }  
  void enqueue()  
  {  
   try  
   {  
   if(count<n)  
    {  
    System.out.println("Enter the element to be added:");  
    item=Integer.parseInt(get.readLine());  
    a[rear]=item;  
     rear++;  
    count++;  
    }  
   else  
    System.out.println("QUEUE IS FULL");  
   }  
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
   }  
  }  
  void dequeue()  
  {  
   if(count!=0)  
    {  
    System.out.println("The item deleted is:"+a[front]);  
    front++;  
    count--;  
    }  
   else  
    System.out.println("QUEUE IS EMPTY");  
  if(rear==n)  
   rear=0;  
  }  
  void display()  
  {  
   int m=0;  
   if(count==0)  
   System.out.println("QUEUE IS EMPTY");  
   else  
   {  
   for(i=front;m<count;i++,m++)  
   System.out.println(" "+a[i]);  
   }  
  }  
 }  
 class Myqueue  
 {  
  public static void main(String arg[])  
  {  
  DataInputStream get=new DataInputStream(System.in);  
  int ch;  
  clrqueue obj=new clrqueue();  
  obj.getdata();  
  try  
  {  
   do  
   {  
   System.out.println(" 1.Enqueue  2.Dequeue  3.Display  4.Exit");  
   System.out.println("Enter the choice");  
   ch=Integer.parseInt(get.readLine());  
   switch (ch)  
   {  
   case 1:  
       obj.enqueue();  
      break;  
   case 2:  
      obj.dequeue();  
      break;  
   case 3:  
      obj.display();  
      break;  
   }  
   }  
   while(ch!=4);  
  }  
  catch(Exception e)  
  {  
  System.out.println(e.getMessage());  
  }  
  }  
 }  

Friday, August 5, 2011

TASM Program Source Code to Check Whether a Number is Prime


The Program given below can be used to check whether a 2 digit number is prime or not.

  print macro msg  
  mov ah,09h  
  mov dx,offset msg  
  int 21h  
 endm  
 readnum macro num  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  mov bh,0ah  
  mul bh  
  mov num,al  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  add num,al  
 endm  
 data segment  
  cr equ 0dh  
  lf equ 0ah  
  msg1 db 'Enter the no:','$'  
  num1 db ?  
  msg2 db cr,lf,'prime no','$'  
  msg3 db cr,lf,'not a prime no','$'  
 data ends  
 code segment  
  assume cs:code,ds:data  
  start:mov ax,data  
     mov ds,ax  
     print msg1  
     readnum num1  
     mov al,num1  
     cmp al,02h  
     je go3  
     mov ah,00h  
     mov bl,02h  
     mov bh,00h  
     mov cl,al  
   go2:  
     mov ah,00h  
     div bl  
     cmp ah,00h  
     je go  
     inc bx  
     mov al,num1  
     cmp bl,cl  
     jne go2  
  go3: print msg2  
     jmp exit  
  go:print msg3  
  exit:mov ah,4ch  
     mov al,00h  
     int 21h  
  code ends  
  end start  

TASM Program to find the Sum of N numbers

 
The Program given below receives N numbers from console,computes the sum of those numbers and prints the result.
 print macro msg  
   mov ah,09h  
   mov dx,offset msg  
   int 21h  
 endm  
 readnum macro num  
   mov ah,01h  
   int 21h  
   sub al,'0'  
   mov bh,0ah  
   mul bh  
   mov num,al  
   mov ah,01h  
   int 21h  
   sub al,'0'  
   add num,al  
 endm  
 data segment  
   cr equ 0dh  
   lf equ 0ah  
   msg1 db 'Enter the limit:','$'  
   msg3 db cr,lf,'Enter the no:','$'  
   msg2 db cr,lf,'sum=','$'  
   lmt db ?  
   temp db ?  
   arr db 15 dup(0)  
   rslt db 2 dup(0)  
 data ends  
 code segment  
   assume cs:code,ds:data  
  start:mov ax,data  
      mov ds,ax  
      print msg1  
      readnum lmt  
      mov ch,00h  
      mov cl,lmt  
      mov si,00h  
   l1:print msg3  
      readnum temp  
      mov al,temp  
      mov arr[si],al  
      inc si  
      loop l1  
      mov ch,00h  
      mov cl,lmt  
      mov bx,00h  
      mov si,00h  
      mov ax,0000h  
   l2: mov bh,00h  
      mov bl,arr[si]  
      add ax,bx  
      mov rslt,al  
      inc si  
      loop l2  
      mov si,offset rslt   
      call hexa2asc  
      print msg2  
      print rslt  
      mov ah,4ch  
      mov al,00h  
      int 21h  
  hexa2asc proc near  
     push ax  
     push bx  
     push cx  
     push dx  
     push si  
     mov cx,00h  
     mov bx,0ah  
 rpt1:  mov dx,00h  
     div bx  
     add dl,'0'  
     push dx  
     inc cx  
     cmp ax,0ah  
     jge rpt1  
     add al,'0'  
     mov [si],al  
 rpt2:  
     pop ax  
     inc si  
     mov [si],al  
     loop rpt2  
     inc si  
     mov al,'$'  
     mov [si],al  
     pop si  
     pop dx  
     pop cx  
     pop bx  
     pop ax  
     ret  
  hexa2asc endp  
  code ends  
 end start  

TASM:Turbo Assembler Tutorial


Assembler is a System Software which translates the Source Program,which is a set of assembly language statements into Machine Code.Turbo Assembler,commonly known as TASM is a widely used assembler.The assembly Program in  given to the Assembler as Input.The Assembler processes the input and converts the code to Object Code(Machine Code) and Produces an Assembly Listing of the generated Code.

For More Understanding of the Assembler Check out these sample Assembly Programs


http://c-madeeasy.blogspot.com/2011/09/tasm-program-source-code-to-find.html
http://c-madeeasy.blogspot.com/2011/09/tasm-assembly-program-to-find-largest.html
http://c-madeeasy.blogspot.com/2011/08/tasm-program-to-find-sum-of-n-numbers.html

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...