Monday, 22 August 2011

NEXT LAB PROGRAMS:(1.ADT 2.DNA)


DNA:
import java.util.*;
import java.io.*;
public class DNADescending
{
public static void main(String args[])throws IOException
{
final String dnaFileName="Dnasequence.txt";
final String outputFile="Dnaout.txt";
DNADescending dnaTest=new DNADescending();
try
{
File f=new File(outputFile);
BufferedOutputStream OutputStream=new BufferedOutputStream(new FileOutputStream(f));
PrintWriter pw=new PrintWriter(OutputStream);
dnaTest.readFileAsString(dnaFileName,pw);
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void readFileAsString(String filePath,PrintWriter pw)throws java.io.IOException
{
BufferedReader reader=new BufferedReader(new InputStreamReader
(this.getClass().getClassLoader().getResourceAsStream(filePath)));
String strLine;
int count,i,j,temp;
boolean flag;
String[][] line=new String[15][6];
while((strLine=reader.readLine())!=null)
{
String[] word=strLine.split(" ");
count=0;
flag=false;
for(i=0;i<word.length;i++)
{
if(word[i].contains("TATA"))
{
count++;
flag=true;
}
}
if(flag)
{
for(int k=0;k<6;k++)
{
if(line[count][k]==null)
{
line[count][k]=strLine;
System.out.println(line[count][k]);
break;
}
}
}
}
for(i=4;i>0;i--)
for(j=5;j>=0;j--)
{
if(line[i][j]!=null)
writeIntoFile(line[i][j],pw);
}
}
private void writeIntoFile(String str,PrintWriter pw)
{
try
{
pw.println(str);
System.out.println("THE DNA PATTERN HAS BEEN WRITTEN");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
LINKED LIST:

import java.util.*;

interface Stack {

      void push(int num);
      void pop();
      void display();
}

class Arraystack implements Stack {

      int[] as;
      int top;
      int size;

      public Arraystack(int n)
      {
         as = new int[n];
         top=-1;
         size=n;
      }
     
      public void push(int num)
      {
         if(top<size-1)
         {
            top++;
            as[top]=num;
            System.out.println("Element PUSHED successfully...");
         }
         else
            System.out.println("Stack Overflow!!");
      }

      public void pop()
      {
         if(top==-1)
            System.out.println("Stack Underflow!!...");
         else
         {
            top--;
            System.out.println("Element POPPED successfully...");
         }
      }

      public void display()
      {
         if(top==-1)
            System.out.println("...Stack Empty...");
         else
         {
            System.out.println("The contents of stack is...");
            int i=top;
            while(i>-1)
            {
               System.out.println(as[i]);
               i--;
            }
         }
      }
}

class Liststack implements Stack {

      LinkedList ls;

      public Liststack()
      {
         ls = new LinkedList();
      }
     
      public void push(int num)
      {
         ls.addFirst(new Integer(num));
         System.out.println("Element PUSHED successfully...");
      }

      public void pop()
      {
         if(ls.isEmpty()==true)
            System.out.println("Stack Underflow!!...");
         else
         {
            ls.remove();
            System.out.println("Element POPPED successfully...");
         }
      }

      public void display()
      {
         if(ls.isEmpty()==true)
            System.out.println("...Stack Empty...");
         else
            System.out.println("The contents of stack is...\n"+ls);
      }
}

class StackTrial {

      public static void main(String args[])
      {
         int s,opt,ch=1;
         Scanner inp = new Scanner(System.in);

         System.out.println("Enter the size of the stack...");
         Arraystack aob = new Arraystack(inp.nextInt());

         Liststack lob = new Liststack();

         System.out.println("...ARRAY IMPLEMENTATION OF STACK...");
         do
         {
            System.out.println("\n1.Push.\n2.Pop.\n3.Display.\n4.Exit");
            opt=inp.nextInt();
            if(opt<1 || opt>3)
               break;

            switch(opt)
            {
               case 1:
                  System.out.println("Enter the element to be inserted...");                
                  aob.push(inp.nextInt());
                  break;

               case 2:
                  aob.pop();
                  break;

               case 3:
                  aob.display();
                  break;
            }
         }while(ch==1);
        
         System.out.println("...LINKED LIST IMPLEMENTATION OF STACK...");
         do
         {
            System.out.println("\n1.Push.\n2.Pop.\n3.Display.\n4.Exit");
            opt=inp.nextInt();
            if(opt<1 || opt>3)
               break;

            switch(opt)
            {
               case 1:
                  System.out.println("Enter the element to be inserted...");                
                  lob.push(inp.nextInt());
                  break;

               case 2:
                  lob.pop();
                  break;

               case 3:
                  lob.display();
                  break;
            }
         }while(ch==1);
      }
}

Friday, 19 August 2011

NEXT LAB PROGRAMS (20.08.2011 and 23.08.2011)


4. Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list. Provide necessary exception handling in both the implementations.

ALGORITHM
STEP 1: Create an interface which consists of three methods namely PUSH, POP and
    DISPLAY
STEP 2: Create a class which implements the above interface to implement the concept
              of stack through Array
STEP 3: Define all the methods of the interface to push any element, to pop the top
               element and to display the elements present in the stack.
STEP 4: Create another class which implements the same interface to implement the concept of stack through linked list.
STEP 5: Repeat STEP 4 for the above said class also.
STEP 6: In the main cl
ass, get the choice from the user to choose whether array
                implementation or linked list implementation of the stack.
STEP 7: Call the methods appropriately according to the choices made by the user in the
                previous step.
STEP 8: Repeat step 6 and step 7 until the user stops his/her execution

Thursday, 4 August 2011

09.08.2011 and 11.07.2011 LAB PROGRAMS

UNIVERSITY SYLLABUS:EX NO:4
1. Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle,
Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate
dynamic polymorphism.

step 1:Define the class point.
step 2:Define the method show().
step 3:Teminate the class.
step 4:Define the class shape which extends from point.
step 5:Define the class show() make a call for the super class show().
step 6:Terminate the class.
step 7:Define the class rectangle that extend from the class shape.
step 8:Declar the datamembers l&b in integer.
step 9:Define the method getdata() to get the l and b values.
step 10:Define the show() to display the area.
step 11:Terminate the class.
step 12:Define the class square that extend from the class shape.
step 13:Declar the datamembers a in integer.
step 14:Define the method gdata() to get the a values.
step 15:Define the sarea() to display the area.
step 16:Terminate the class.
step 17:Define the class circle and triangle that extend from the class shape and display the result.
step 18:Define the shapetest and define the main() method in it.
step 19:create objects for the classes rectangle,square,circle and triangle and access their methods.
step 20:display the result.
step 21:Terminate the main and class.
OTHER PROGRAMS:

1.Write a java program to create HTML file from your actual source file.
2.Develop a java program to calculate factorial number calculation (USE YOUR OWN   PACKAGE).
3. Develop a java program to the given number is Armstrong or not. (USE YOUR OWN   PACKAGE).
3.Develop a java program to create your own package(pack1,pack2) and use package  access modifiers table and prove the all 5 different operation.(Define many methods in package and access that methods using ACCESS MODIFIERS TABLE).Assume your own data.

IMPORTANT NOTE: 
1.Complete the pending programs.
2.Get Sign from me.
3.Prepare for viva questions .
4.Study  well For UNIT TEST-I
5.I will give prize for first mark in unit test.

Wednesday, 3 August 2011

JAVA PACKAGE EXAMPLES


HOME EXCERCISE:
1.Write a java program to create HTML file from your actual source file.
2.Develop a java program to calculate factorial number calculation (USE YOUR OWN      
   PACKAGE).
3.Develop a java program to create your own package and use access modifiers chart(to access all access specifiers fields).Assume your own data

JAVA PROGRAMMING LAB UNIVERSITY SYLLABUS

JAVA PROGRAMMING LAB
1. Develop a Java package with simple Stack and Queue classes. Use JavaDoc
comments for documentation.
2. Design a class for Complex numbers in Java. In addition to methods for basic
operations on complex numbers, provide a method to return the number of active
objects created.
3. Design a Date class similar to the one provided in the java.util package.
4. Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle,
Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate
dynamic polymorphism.
5. Design a Java interface for ADT Stack. Develop two different classes that implement
this interface, one using array and the other using linked-list. Provide necessary
exception handling in both the implementations.
6. Write a Java program to read a file that contains DNA sequences of arbitrary length
one per line (note that each DNA sequence is just a String). Your program should
sort the sequences in descending order with respect to the number of 'TATA'
subsequences present. Finally write the sequences in sorted order into another file.
7. Develop a simple paint-like program that can draw basic graphical primitives in
different dimensions and colors. Use appropriate menu and buttons.
8. Develop a scientific calculator using even-driven programming paradigm of Java.
9. Develop a template for linked-list class along with its methods in Java.
10. Design a thread-safe implementation of Queue class. Write a multi-threaded
producer-consumer application that uses this Queue class.
11. Write a multi-threaded Java program to print all numbers below 100,000 that are
both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a
thread that generates prime numbers below 100,000 and writes them into a pipe.
Design another thread that generates fibonacci numbers and writes them to another
pipe. The main thread should read both the pipes to identify numbers common to
both.
12. Develop a multi-threaded GUI application of your choice.
TOTAL= 45 PERIODS

S. No. Description of Equipment Quantity Required
1.
Hardware:
Pentium IV with 2 GB RAM,
160 GB HARD Disk,
Monitor 1024 x 768 colour
60 Hz.
30 Nodes
2.
Software:
Windows /Linux operating system
JDK 1.6(or above)
30 user license

Tuesday, 2 August 2011

TWO MARK QUESTIONS(3.08.2011 TEST)


Questions:
1.Define string comparision methods
2. How many objects are in the memory after the exection of following code segment? 
   
String str1 = \"ABC\";
    String str2 = \"XYZ\";
    String str1 = str1 + str2; 
3.Define StringBuilder and StringBuffer.
4. What is the importance of == and equals() method with respect to String object?
5. Explain the concept of abstract classes and methods.
6. Define Class and Object.
7. What is a super class and how can you call a super class?
8. Types of comments.
9. Define Abstract method.
10. What is Message Passing.
11.Define package.Explain static imports and class imports.
12.Three ways to implement the polymorphism.
13.What are the three characteristics of object.
14.Define final keywords.(all types).Give  any two example classes of predefined final class.
15.Syntax of inheriting interface.