26 Sept 2012

Converting a number into its equivalent value in words in Java

/* Converting a number into its equivalent value in words in Java,  How to convert a number into words using Java */

class constNumtoLetter
  {
      String[] unitdo={""," One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine", " Ten", "       Eleven", " Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen",  " Seventeen"," Eighteen","Nineteen"};
      String[] tens={"","Ten"," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety"};
      String[] digit={""," Hundred"," Thousand"," Lakh"," Crore"};
      int r;
      //Count the number of digits in the input number
      int numberCount(int num)
      {
          int cnt=0;
          while (num>0)
          {
            r=num%10;
            cnt++;
            num=num/10;
          }
            return cnt;
      }
      //Method for Conversion of two digit
      String twonum(int numq)
      {
           int numr,nq;
           String ltr="";
           nq=numq/10;
           numr=numq%10;
           if(numq>19)
             {
           ltr=ltr+tens[nq]+unitdo[numr];
             }
           else
             {
           ltr=ltr+unitdo[numq];
             }
           return ltr;
      }
      //Method for Conversion of three digit
      String threenum(int numq)
      {
             int numr,nq;
             String ltr="";
             nq=numq/100;
             numr=numq%100;
             if(numr==0)
              {
              ltr=ltr+unitdo[nq]+digit[1];
               }
             else
              {
              ltr=ltr+unitdo[nq]+digit[1]+" and"+twonum(numr);
              }
             return ltr;
      }
}

 class originalNumToLetter

   {
      public static void main(String[] args) throws Exception
      {
          //Defining variables q is quotient, r is remainder
          int len,q=0,r=0;
          String ltr=" ";
          String Str="Rupees:";
          constNumtoLetter n=new constNumtoLetter();
          int num=Integer.parseInt(args[0]);
          if(num<=0) 
 System.out.println("Zero or Negative number not valid for conversion");
          while(num>0)
          {
             len=n.numberCount(num);
             //Take the length of the number and do letter conversion
             switch(len)
             {
                  case 8:
                          q=num/10000000;
                          r=num%10000000;
                          ltr=n.twonum(q);
                          Str=Str+ltr+n.digit[4];
                          num=r;
                          break;

                  case 7:

                  case 6:
                          q=num/100000;
                          r=num%100000;
                          ltr=n.twonum(q);
                          Str=Str+ltr+n.digit[3];
                          num=r;
                          break;

                  case 5:

                  case 4:
                           q=num/1000;
                           r=num%1000;
                           ltr=n.twonum(q);
                           Str=Str+ltr+n.digit[2];
                           num=r;
                           break;

                  case 3:

                            if(len== 3)
                            r=num;
                            ltr=n.threenum(r);
                            Str=Str+ltr;
                            num=0;
                            break;

                  case 2:

                        ltr=n.twonum(num);
                           Str=Str+ltr;
                           num=0;
                           break;

                  case 1:

                           Str=Str+n.unitdo[num];
                           num=0;
                           break;
                  default:
                          num=0;
                          System.out.println("Exceeding Crore....No conversion");
                          System.exit(1);
              }
                          if (num==0)
                          System.out.println(Str+" Only");
            }
         }
      }


 Output:

 D:\Crawlerf1>java originalNumToLetter 10560090
  Rupees: One Crore Five Lakh Sixty Thousand Ninety Only

25 Sept 2012

Calling multiple methods in java

/* Calling multiple methods in java */ 

for (int i=0;i<N;i++) 
      {
      try {
        obj.getClass().getMethod("method"+i).invoke(obj);
           } 
     catch (Exception e) 
        {
         // give up
         break;
      }
    }


ex:
obj.method1()
obj.method2()
obj.method3()
obj.method4()
obj.method5()

jdbc odbc connection for ms access in java

/* jdbc odbc connection for ms access in java code, jdbc-odbc connection in java with ms-access*/ 
import static java.lang.System.*;
import java.sql.*;

public class DBDemo
{
    public static void main(String[] args)
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String sourceURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=UserDB.mdb;";
            Connection userDB = DriverManager.getConnection(sourceURL, "admin", "");
            Statement myStatement = userDB.createStatement();
            String writeString = "INSERT INTO Users(Firstname,Surname,Id)                     
            VALUES('Fred','Bloggs','bf01')";
            myStatement.executeUpdate(writeString);

            ResultSet results = myStatement.executeQuery("SELECT Firstname, Surname, Id FROM Users 
            ORDER BY Id");

            while (results.next())
            {
                out.print(results.getString(1) + " ");
                out.print(results.getString(2) + " ");
                out.println(results.getString(3));
            }
            results.close();
        }
        //The following exceptions MUST be caught
        catch(ClassNotFoundException cnfe)
        {
            out.println(cnfe);
        }
        catch(SQLException sqle)
        {
            out.println(sqle);
        }
    }
}

append new line on top of the jtextarea in java swing

/* how to insert or append new line on top of the jtextarea in java swing */
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;

public class TestTextArea {

    private void initUI() {
        JFrame frame = new JFrame("textarea example");
        final JTextArea textarea = new JTextArea(24, 80);
        JButton addText = new JButton("Add new line");
        addText.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try { 
                    textarea.getDocument().insertString(0,"New line entered      on"+new Date()+"\n",null);
                     } 

                catch (BadLocationException e1) 
                    {
                    e1.printStackTrace();
                   }
            }
        });
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new JScrollPane(textarea));
        frame.add(addText, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new TestTextArea().initUI();
            }
        });
    }

}

24 Sept 2012

advantages and disadvantages of threads in java

/* advantages and disadvantages of threads in java, advantages and disadvantages of using threads in java */

Advantages:


Some advantages include:

     1. Reduces development time.
     2. Reduces maintenance costs.
     3. Improves the performance of complex applications.
     4. Useful for improving the responsiveness of the user interfaces.
     5. Used in server applications for improving high throughput and resource utilization.
     6. Parallelize tasks.
    7. If a thread cannot use all the computing resources of the CPU (because instructions depend on each other's result), running another thread can avoid leaving these idle.
    8. If several threads work on the same set of data, they can actually share their cache, leading to better cache usage or synchronization on its values.

Disadvantages:


Some disadvantages include:


    1. Multiple threads can interfere with each other when sharing hardware resources such as caches or translation lookaside buffers (TLBs).

      2. Execution times of a single thread are not improved but can be degraded, even when only one thread is executing. This is due to slower frequencies and/or additional pipeline stages that are necessary to accommodate thread-switching hardware.
    3. Hardware support for multithreading is more visible to software, thus requiring more changes to both application programs and operating systems than multiprocessing.

Use of thread in java:


For example, You have a Java program to compute the sum of two numbers:


public class sumoftwonumbers

{
   public static void main(String[] args) 
     {
     int a=Integer.parseInt(args[0]);
     int b=Integer.parseInt(args[1]);
     System.out.print("Sum of "+a+" "+b+" is: ");
     int c=a+b;
     System.out.println(c);
     }
}

When you run this program, it executes a sequence of instructions, that list of instructions looks like this:


1. convert args[0] to an integer and store that integer in a location called 'a'.

2. convert args[1] to an integer and store that integer in a location called 'b'.
3. print some text.
4. calculating the sum of two numbers called 'a' and 'b', and store it in a location called 'c'.
5. print out the value stored in 'c'.

This program is executed as a series of instructions, the execution path of these instructions is called as a thread.


In your program, that thread is called as main thread, and it begins executing statements with the first statement of the main() method of your class.


If there are two separate tasks in your java program, so you could choose to write them as two separate threads.


What is multiprocessing and multithreading?

Multiprocessing: If two or more programs are executing concurrently is called as multiprocessing.
Multithreading: If two or more tasks are executing concurrently is called as multithreading.

For ieee projects visit our site here

or Visit our blog

FatCow Plan for $3.15/mo. only

thread priority example in java

/* thread priority example in java */ 

class TestA extends Thread {
    public void run() {
        System.out.println("TestA Thread started");
        for (int i = 1; i <= 4; i++) {
            System.out.println("\t From thread TestA :i=" + i);
        }
        System.out.println("exit from TestA");
    }
}

class TestB extends Thread {
    public void run() {
        System.out.println("TestB Thread started");
        for (int j = 1; j <= 4; j++) {
            System.out.println("\t From thread TestB :j=" + j);
        }
        System.out.println("exit from TestB");
    }
}

class TestC extends Thread {
    public void run() {
        System.out.println("testC Thread started");
        for (int k = 1; k <= 4; k++) {
            System.out.println("\t From thread TestC :K=" + k);
        }
        System.out.println("exit from TestC");
    }
}

public class TestThread {
    public static void main(String args[]) {

        TestA A = new TestA();
        TestB B = new TestB();
        TestC C = new TestC();

        C.setPriority(Thread.MAX_PRIORITY);
        B.setPriority(Thread.NORM_PRIORITY+1);
        A.setPriority(Thread.MIN_PRIORITY);

        System.out.println(" Begin thread A");
        A.start();

        System.out.println(" Begin thread B");
        B.start();

        System.out.println(" Begin thread C");
        C.start();

        System.out.println(" End of main thread");
    }
}

 
Output:
Begin thread A
Begin thread B
TestA Thread started
Begin thread C
From thread TestA :i=1
testC Thread started
From thread TestC :K=1
End of main thread
From thread TestC :K=2
From thread TestC :K=3
From thread TestC :K=4
exit from TestC
From thread TestA :i=2
From thread TestA :i=3
TestB Thread started
From thread TestB :j=1
From thread TestB :j=2
From thread TestB :j=3
From thread TestB :j=4
exit from TestB
From thread TestA :i=4
exit from TestA

Multithreaded program in java

/* multithreaded program in java example, multithreading program in java using runnable, multithreading program example in java */

class NewThread implements Runnable {
   Thread t;
   NewThread() {
      // Create a new, second thread
      t = new Thread(this, "Demo Thread");
      System.out.println("Child thread: " + t);
      t.start(); // Start the thread
   }
  
   // This is the entry point for the second thread.
   public void run() {
      try {
         for(int i = 5; i > 0; i--) {
            System.out.println("Child Thread: " + i);
            // Let the thread sleep for a while.
            Thread.sleep(500);
         }
     } catch (InterruptedException e) {
         System.out.println("Child interrupted.");
     }
     System.out.println("Exiting child thread.");
   }
}

class ThreadDemo {
   public static void main(String args[]) {
      new NewThread(); // create a new thread
      try {
         for(int i = 5; i > 0; i--) {
           System.out.println("Main Thread: " + i);
           Thread.sleep(1000);
         }
      } catch (InterruptedException e) {
         System.out.println("Main thread interrupted.");
      }
      System.out.println("Main thread exiting.");
   }
}

Output:
Child thread: Thread[Demo Thread,5,main]
Main Thread: 5
Child Thread: 5
Child Thread: 4
Main Thread: 4
Child Thread: 3
Child Thread: 2
Main Thread: 3
Child Thread: 1
Exiting child thread.
Main Thread: 2
Main Thread: 1
Main thread exiting.

synchronized block in java example

/* synchronized block in java example */ 

This is the general form of the synchronized statement:
synchronized(object) {
   // statements to be synchronized
}

Here, object is a reference to the object being synchronized. A synchronized block ensures that a call to a method that is a member of object occurs only after the current thread has successfully entered object's monitor.

Here is an example, using a synchronized block within the run( ) method:

// File Name : Callme.java
// This program uses a synchronized block.
class Callme {
   void call(String msg) {
      System.out.print("[" + msg);
      try {
         Thread.sleep(1000);
      } catch (InterruptedException e) {
         System.out.println("Interrupted");
      }
      System.out.println("]");
   }
}

// File Name : Caller.java
class Caller implements Runnable {
   String msg;
   Callme target;
   Thread t;
   public Caller(Callme targ, String s) {
      target = targ;
      msg = s;
      t = new Thread(this);
      t.start();
   }
  
   // synchronize calls to call()
   public void run() {
      synchronized(target) { // synchronized block
         target.call(msg);
      }
   }
}
// File Name : Synch.java
class Synch {
   public static void main(String args[]) {
      Callme target = new Callme();
      Caller ob1 = new Caller(target, "Hello");
      Caller ob2 = new Caller(target, "Synchronized");
      Caller ob3 = new Caller(target, "World");
  
      // wait for threads to end
      try {
         ob1.t.join();
         ob2.t.join();
         ob3.t.join();
      } catch(InterruptedException e) {
         System.out.println("Interrupted");
      }
   }
}

This would produce following result:

[Hello]
[World]
[Synchronized]

Converting Document into Text file in java

/* Converting Document into Text file in java code, Convert .doc file to .txt file, how to convert Document into Text file in java code*/

import java.io.*;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class ReadDocFile 
{
public static void main(
java.lang.String[] args) 
{ java.io.File file = null;

try 
{
// Read the Doc/DOCx file
file = new 
java.io.File("D:\\New.docx"); 
java.io.FileInputStream fis = new java.io.FileInputStream(file.getAbsolutePath()); 
XWPFDocument doc = new XWPFDocument(fis);
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
String text = ex.getText();

//write the text in txt file
java.io.File fil = new java.io.File("D:\\New.txt"); 
java.io.Writer output = new java.io.BufferedWriter(new java.io.FileWriter(fil)); 
output.write(text);
output.close();
catch (java.lang.Exception exep) 
{
}
}
}


Also upload the xmlbeans-2.3.0,dom4j-1.6.1 and stax-api-1.0.1.

Download the Apache POI jar also.

Generating New Population for Genetic Algorithm in java

/* Generating New Population for Genetic Algorithm in java code */ 

import java.util.Collections;
import java.util.Vector;

public class Simulation 
  {
    private static int NUM_CHROMOSOMES = 10;
    private static int MAX_POWER = 10;
    private static int MAX_NUMBER = (int) Math.pow(2, MAX_POWER) - 1;
    private static int FITNESS_THRESHOLD = 5;
    private static float MUTATE = (float) .05;
   
    private Vector population;
    private boolean done = true;
    int numRuns = 0;
    int randomValue=0;
   
   
    public Simulation()
   {
        generateRandomPopulation();
    }
   
    private void generateRandomPopulation()
    {
        System.out.println("***Randomly Generating population with: " + NUM_CHROMOSOMES + " Chromosome(s)***");
       
        population = new Vector();
       
        for(int i = 0; i < NUM_CHROMOSOMES; ++i)
       {
            randomValue = (int) (Math.random()*MAX_NUMBER);
            population.add(new Chromosome(randomValue, MAX_POWER));
        }
        System.out.println("First Population: " + population +"\n");
    }
    public int getRandomvalue()
    {
        return randomValue;
    }

    public static int getMaxpower()
    {
        return MAX_POWER;
    }
   
    public void start()
      {
        Collections.sort(population);
        Chromosome fitess = (Chromosome) population.lastElement();
       
        done = fitess.fitness() >= MAX_POWER? true:false;
       
        if(done)
        {
            System.out.println("DONE, solution found: " + fitess);   
        }
        else
        {
            numRuns++;
            System.out.println("FITESS: " + fitess + " fitness: " + fitess.fitness());
            generateNewPopulation();
            start();
        }
    }
   
    private void generateNewPopulation()
    {
       
        System.out.println("***Generating New Population");
        Vector temp = new Vector();
       
        for(int i = 0; i < population.size()/2; ++i)
      {
            Chromosome p1 = selectParent();
            Chromosome p2 = selectParent();
            temp.add(cross1(p1, p2));
            temp.add(cross2(p1, p2));
        }
       
        population.clear();
        population.addAll(temp);
        System.out.println("New Population: " + population + "\n");
    }
   
    private Chromosome selectParent()
      {
        int delta = population.size();
        delta = NUM_CHROMOSOMES - NUM_CHROMOSOMES/2;
       
        int num = (int) (Math.random()*10 + 1);
        int index;
       
        if(num >= 4)
       {
            index = (int) (Math.random()*delta + NUM_CHROMOSOMES/2);
        }
        else
       {
            index = (int) (Math.random()*delta);   
        }
       
        return (Chromosome) population.get(index);
    }
   
    private Chromosome cross1(Chromosome parent1, Chromosome parent2)
      {
        String bitS1 = parent1.getBitString();
        String bitS2 = parent2.getBitString();
        int length = bitS1.length();
       
        String newBitString = bitS1.substring(0, length/2) + bitS2.substring(length/2, length);
        Chromosome offspring = new Chromosome();
        offspring.setBitString(newBitString);
       
        if(shouldMutate())
       {
            mutate(offspring);
        }
       
        return offspring;
    }
   
    private Chromosome cross2(Chromosome parent1, Chromosome parent2)
    {
        String bitS1 = parent1.getBitString();
        String bitS2 = parent2.getBitString();
        int length = bitS1.length();
       
        String newBitString = bitS2.substring(0, length/2) + bitS1.substring(length/2, length);
        Chromosome offspring = new Chromosome();
        offspring.setBitString(newBitString);
       
        if(shouldMutate())
       {
            mutate(offspring);
        }
       
        return offspring;
    }
   
    private boolean shouldMutate()
   {
        double num = Math.random();
        int number = (int) (num*100);
        num = (double) number/100;
        return (num <= MUTATE);
    }
   
    private void mutate(Chromosome offspring)
   {
        String s = offspring.getBitString();
        int num = s.length();
        int index = (int) (Math.random()*num);
        String newBit = flip(s.substring(index, index+1));
        String newBitString = s.substring(0, index) + newBit + s.substring(index+1, s.length());
        offspring.setBitString(newBitString);
    }
   
    private String flip(String s)
   {
        return s.equals("0")? "1":"0";
    }

    public static void main(String[] args) 
   {
        double average = 0;
        int sum = 0;
            Simulation s = new Simulation();
            s.start();
            sum = sum + s.numRuns;
            System.out.println("Number of runs: " + s.numRuns);
    }
}

How to find Chromosome for Genetic Algorithm in java

/* How to find Chromosome for Genetic Algorithm in java */

import java.lang.Comparable;

public class Chromosome implements Comparable
   {
    protected String bitString;
   
    public Chromosome()
   {
    }
   
    public Chromosome(int value, int length)
   {
        bitString = convertIntToBitString(value, length);
    }
   
    public void setBitString(String s)
   {
        bitString = s;
    }
   
    public String getBitString()
   {
        return bitString;
    }
   
    public int compareTo(Object o) 
  {
        Chromosome c = (Chromosome) o;
        int num = countOnes(this.bitString)-countOnes(c.getBitString());
        return num;
    }
   
    public int fitness()
   {
        return countOnes(bitString);
    }
   
    public boolean equals(Object o)
    {
        if(o instanceof Chromosome)
        {
            Chromosome c = (Chromosome) o;
            return c.getBitString().equals(bitString);
        }
        return false;
    }
   
    public int hashCode()
   {
        return bitString.hashCode();
    }
   
    public String toString()
   {
        return "Chromosome: " + bitString;
    }
   
    public static int countOnes(String bits)
     {
        int sum = 0;
        for(int i = 0; i < bits.length(); ++ i)
            {
            String test = bits.substring(i, i+1);
            if(test.equals("1")){
                sum = sum + 1;
            }
        }
        return sum;
    }
   
    public static String convertIntToBitString(int val, int length)
    {
        int reval = val;
       
        StringBuffer bitString = new StringBuffer(length);
        for(int i = length-1; i >=0; --i )
         {
            if( reval - (Math.pow(2, i)) >= 0 )
           {
                bitString.append("1");
                reval = (int) (reval - Math.pow(2, i));
            }
            else{
                bitString.append("0");
            }
        }
        return bitString.toString();
    }
   
    public static void main(String[] args)
    {
        Simulation sim=new Simulation();
        Chromosome c=new Chromosome(sim.getRandomvalue(),Simulation.getMaxpower());
        System.out.println(c.fitness());
    }
}

Difference between two dates in java


/* difference between two dates in java example, calculating the difference between two dates in java */

int diffInDays=(newerDate.getTime()-olderDate.getTime())/(1000*60*60*24);

how to force to delete a Directory in java

/* how to force to delete a Directory in java, delete a folder in java code,force to delete all files from a folder in java code */

java.io.File fin = new java.io.File("F:/folder name/");
    java.io.File[] finlist = fin.listFiles();       
    for (int n = 0; n < finlist.length; n++) 
      {
        if (finlist[n].isFile()) 
         {
        System.gc();
        java.lang.Thread.sleep(2000);
        finlist[n].delete();
        }
    } 

or

org.apache.commons.io.FileUtils.deleteDirectory(java.io.File directoryname) throws IOException

or

java.io.File fin = new java.io.File("F:/folder name/");
for (java.io.File file : fin.listFiles()) 
{
    org.apache.commons.io.FileDeleteStrategy.FORCE.delete(file); //throws IOException
}


For ieee projects visit our site here

Moving Files from one Folder to other folder in java

/* how to move a file from one folder to another in java, Moving Files from one Folder to other folder in java, copy files from one folder to another folder in java*/

import java.io.File;

public class Test 
   {
    public static void main(String[] args) 
    {
        
java.io.File file = new java.io.File("C:\\Test1");

        java.io.File dir = new java.io.File("C:\\Test2");
        java.io.File[] listFiles = file.listFiles();
        for (int i = 0; i < listFiles.length; i++) 
         {
            boolean success = listFiles[i].renameTo(new       

            java.io.File(dir,listFiles[i].getName()));
            if (success) 
           {
                System.out.print("Moved");
            }
              else{
                System.out.print("not Moved");
                    }
        }

    }
}

or

Use org.apache.commons.io.FileUtils class

moveDirectory(
java.io.File srcDir, java.io.File destDir) we can move whole directory

More KeyEvents in java swings

/* key events in java with examples, More Key Events in java swings */

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Keyserver 

{
static 
java.net.ServerSocket server;

static java.net.Socket soc;
static java.io.ObjectInputStream in;
static int key;
static 
java.awt.Robot bot;

static boolean shift = false;

public static void main(String[] args) throws 
java.awt.AWTException

{
    bot = new java.awt.Robot();
    while(true)
    {
       try 

       {
            server = new 
java.net.ServerSocket(1111, 10);

            soc = server.accept();
            System.out.println("Accepted port");
            in = new 
java.io.ObjectInputStream(soc.getInputStream());

        } 
        catch (java.io.IOException e) 
        {
            e.printStackTrace();
        }
        while(soc.isConnected())

        {
            try 

            {
                key = in.readInt();
                System.out.println(key);
                switch(key)

                {
                case(7):
                    bot.keyPress(KeyEvent.VK_0);
                    bot.keyRelease(KeyEvent.VK_0);
                    break;
                case(8):
                    bot.keyPress(KeyEvent.VK_1);
                    bot.keyRelease(KeyEvent.VK_1);
                    break;
                case(9):
                    bot.keyPress(KeyEvent.VK_2);
                    bot.keyRelease(KeyEvent.VK_2);
                    break;
                case(10):
                    bot.keyPress(KeyEvent.VK_3);
                    bot.keyRelease(KeyEvent.VK_3);
                    break;
                                    ....
                case(53):
                    bot.keyPress(KeyEvent.VK_Y);
                    bot.keyRelease(KeyEvent.VK_Y);
                    break;
                case(54):
                    bot.keyPress(KeyEvent.VK_Z);
                    bot.keyRelease(KeyEvent.VK_Z);
                    break;
                case(4):
                    bot.keyPress(KeyEvent.VK_BACK_SPACE);
                    bot.keyRelease(KeyEvent.VK_BACK_SPACE);
                    break;
                case(62):
                    bot.keyPress(KeyEvent.VK_SPACE);
                    bot.keyRelease(KeyEvent.VK_SPACE);
                    break;
                case(59):
                    if(!shift)

                    {
                        bot.keyPress(KeyEvent.VK_SHIFT);
                    }else

                    {
                        bot.keyRelease(KeyEvent.VK_SHIFT);
                    }
                    shift = !shift;
                    break;
                case(60):
                    if(!shift)

                    {
                        bot.keyPress(KeyEvent.VK_SHIFT);
                    }else

                    {
                        bot.keyRelease(KeyEvent.VK_SHIFT);
                    }
                    shift = !shift;
                    break;

                case(90):
                    bot.keyPress(KeyEvent.VK_1);
                    bot.keyRelease(KeyEvent.VK_1);
                    break;
                case(91):
                    bot.keyPress(KeyEvent.VK_2);
                    bot.keyRelease(KeyEvent.VK_2);
                    break;
                case(92):
                    bot.keyPress(KeyEvent.VK_0);
                    bot.keyRelease(KeyEvent.VK_0);
                    break;
                case(93):
                    bot.keyPress(KeyEvent.VK_3);
                    bot.keyRelease(KeyEvent.VK_3);
                    break;
                case(104):
                    bot.keyPress(KeyEvent.VK_ENTER);
                    bot.keyRelease(KeyEvent.VK_ENTER);
                    break;
                case(105):
                    bot.keyPress(KeyEvent.VK_BACK_SPACE);
                    bot.keyRelease(KeyEvent.VK_BACK_SPACE);
                    break;
                case(106):
                    bot.keyPress(KeyEvent.VK_MINUS);
                    bot.keyRelease(KeyEvent.VK_MINUS);
                    break;
                case(107):
                    bot.keyPress(KeyEvent.VK_EQUALS);
                    bot.keyRelease(KeyEvent.VK_EQUALS);
                    break;
                case(108):
                    bot.keyPress(KeyEvent.VK_TAB);
                    bot.keyRelease(KeyEvent.VK_TAB);
                    break;
                case(109):
                    bot.keyPress(KeyEvent.VK_ESCAPE);
                    bot.keyRelease(KeyEvent.VK_ESCAPE);
                    break;
            }

            } 

            catch (java.io.IOException e) 
              {
                try {
                    e.toString();
                    in.close();
                    soc.close();
                    server.close();
                    break;
                } 

                catch (java.io.IOException e1) 
                {
                    e1.toString();
                }  
            }
        }
        System.out.println("PORT CLOSED");
    }
}
}