Welcome to my blog, hope you enjoy reading
RSS

Tuesday, 25 June 2013

Folder Lock without any S/W in Windows

Folder Lock without any S/W in Windows

Open Notepad and copy the be low code and save as lock e r.bat. At first tim e start it will cre ate folde r with Lock e r autom atically for u. Don't forge t to
change your password in the code its shown the place whe re to type your password.
afte r cre ation of Lock e r folde r again click on the lock e r.bat.it will ask .pre ss Y the n Lock e r folde r will be disappe are d.again to ge t it click on lock e r.bat.
and give ur password u will ge t the folde r again.
Share

Monday, 24 June 2013

Control your keyboard with Java

Control your keyboard with Java

You may control your keyboard using this simple program.Please dont run this program directly, its just for reference

import java.awt.Robot; 
import java.awt.event.InputEvent; 
import java.awt.event.KeyEvent; 

/* 
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */ 
/** 
 * 
 * @author Anurag 
 */ 
public class ControlKeyboard { 

    public static void main(String args[]) { 
        new ControlKeyboard().control_keyboard(); 
    } 

    public void control_keyboard() { 
        try { 
            Robot robot = new Robot(); 

            //Perform ALT+TAB which will switch your window 
            robot.keyPress(KeyEvent.VK_ALT); 
            robot.keyPress(KeyEvent.VK_TAB); 

            Thread.sleep(100); 

            robot.keyRelease(KeyEvent.VK_ALT); 
            robot.keyRelease(KeyEvent.VK_TAB); 

            //Press Key A 
            robot.keyPress(KeyEvent.VK_A); 
            Thread.sleep(100); 
            robot.keyRelease(KeyEvent.VK_A); 
            //Similarly to press key Z use  
            robot.keyPress(KeyEvent.VK_Z); 
            Thread.sleep(100); 
            robot.keyRelease(KeyEvent.VK_Z); 

            //Press ALT key 
            robot.keyPress(KeyEvent.VK_ALT); 
            Thread.sleep(100); 
            robot.keyRelease(KeyEvent.VK_ALT); 

            //Press Control Key 
            robot.keyPress(KeyEvent.VK_CONTROL); 
            Thread.sleep(100); 
            robot.keyRelease(KeyEvent.VK_CONTROL); 




        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 

Explaination :

First we make an object of Robot class.

If we want to press a keyboard key then we use the keyPress and keyRelease method.

Always make sure there is a delay of some small seconds before key press and key release events

Suppose if we want to click A then we use KeyEvent.VK_A, for B we use VK_B ...., for Z VK_Z.

To perform Control key use VK_CONTROL, ALT key we use VK_ALT and likewise there are other combinations.

To perform multiple key event we perform the key press for both keys and after that give a small delay. After that we perform the release operation.

For eg: In above example we perform keypress for both VK_ALT and VK_TAB together. Then we give small delay and then perform the keyrelease for VK_ALT and VK_TAB together
Share

Thursday, 20 June 2013

How To Validate Date With Regular Expression

How To Validate Date With Regular Expression

Date Format (dd/mm/yyyy hh:mm:ss) Regular Expression Pattern


(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d) ([01][0-9]|2[0-3]):([012345][0-9]):([012345][0-9])


Share

Wednesday, 19 June 2013

How To Get Installed Printer name using Java

How To Get Installed Printer name using Java

Get Installed printers in Java

  •     You can get installed printers by using both javax.print.PrintService and javax.print.PrintServiceLookup 
  •     PrintServiceLookup.lookupDefaultPrintService().getName(); will gives default printer name;

package com.javanotes2all.java.printers;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public class ShowPrinters {

String defaultPrinter;
    public void SearchPrinter() {
        PrintService[] ser = PrintServiceLookup.lookupPrintServices(null, null);
 
        System.out.println("**************** All Printers ******************");
        for (int i = 0; i < ser.length; ++i) {
            String p_name = ser[i].getName();
            System.out.println(p_name);
        }
        System.out.println("***********************************************\n");
        defaultPrinter  =   PrintServiceLookup.lookupDefaultPrintService().getName();
        System.out.println("Default Printer  : "+defaultPrinter );
    }
 
    public static void main(String[] args) {
        new ShowPrinters().SearchPrinter();
    }
}


Share

Tuesday, 18 June 2013

how to insert auto-increment varchar value in mysql

mysql insert a concat with convert (varchar to int)+1

problem:

In the mysql DB, there is a VARCHAR field with values something like this
AB123
AB124
AB999
AB1234

I strip off the "AB, convert to integer and add one.
I really want the max value if the resulting integer, and this works so far.
It returns the number 1235.

SELECT MAX( CONVERT( REPLACE( myfield, 'AB', '' ) , UNSIGNED ) ) +1 FROM mytable

Now, what I really want to do is to INSERT back into mytable the result with the "AB" at the start of the result.
For the above, I want to insert myfield= 'AB1235' into mytable.

Solution:

Sub-selects can only go in one place -- immediately after the list of fields. So, this would need to be written something like (untested):
  • INSERT INTO mytable (myfield) SELECT concat('AB',MAX( CONVERT( REPLACE( myfield, 'AB', '' ) , UNSIGNED ) ) +1) FROM mytable
the sub-select can only go immediately after the list of fields. In particular, it can't appear within another expression. In other words, you can only have "INSERT INTO ... VALUES ..." or "INSERT INTO ... SELECT ...", but not some combination of the two. However, you can select a constant:
  • INSERT INTO mytable (myfield1,myfield2) SELECT concat('AB',MAX( CONVERT( REPLACE(myfield1, 'AB', '' ),UNSIGNED))+1), 'sdfgr45t78ahlu' FROM mytable;
Share

Sunday, 16 June 2013

How to get MAX value of numeric values in varchar column in mysql

How to get MAX value of numeric values in varchar column in mysql

Lets say that I have a table which contains a column for invoice number, the data type is VARCHAR with mixed string/int values like:

invoice_number
**************
    HKL1
    HKL2
    HKL3
    .....
    HKL12
    HKL13
    HKL14
    HKL15

I tried to select max of it, but it returns with "HKL9", not the highest value "HKL15".

SELECT MAX( invoice_number )
FROM `invoice_header`

solution:

SELECT MAX(CAST(SUBSTRING(invoice_number, 4, length(invoice_number)-3) AS UNSIGNED)) FROM table
Share

Tuesday, 11 June 2013

How To Add Password Protection To PDF Using IText In Java

How To Add Password Protection To PDF Using IText In Java

iText is very powerful library. It is used extensively to create PDF files in Java applications. Although not free, iText is the de-fecto Java library for working with PDF files. It has been extensively used in different Java related products for generating and manipulating PDF files.
Let us see how iText can be used to set password protection (encryption) to a PDF file. Also how to read an encrypted PDF file in Java.
Share

How to create random string with random characters?

How to create random string with random characters?



package com.javanotes2all.java.randomgenerator;

import java.util.Date;
import java.util.Random;

public class RandomGenerator 
{
private static Random random = new Random((new Date()).getTime());
public static String generateRandomString(int length) 
  {
      char[] values = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'};

      String out = "";

      for (int i=0;i<length;i++) {
          int idx=random.nextInt(values.length);
        out += values[idx];
      }

      return out;
    }
    public static void main(String[] args) 
     {
      RandomGenerator generator=new RandomGenerator();
      System.out.println(generator.generateRandomString(10));
      System.out.println(generator.generateRandomString(10));
      System.out.println(generator.generateRandomString(10));
      System.out.println(generator.generateRandomString(10));
      System.out.println(generator.generateRandomString(10));
    }
}

OUTPUT:
qmpebje5dw
zxvpoeq59l
6y57vehsyk
j0g89kd4pa

3uz82j5gkp
Share

Monday, 10 June 2013

Convert ArrayList To Arrays In Java

Convert ArrayList To Arrays In Java

Convert ArrayList to Arrays
A lot of time I have to convert ArrayList to Arrays in my Java program. Although this is a simple task, many people don’t know how to do this and end up in iterating the java.util.ArrayList to convert it into arrays. I saw such code in one of my friends work and I thought to share this so that people don’t end up writing easy thing in complicated way.
ArrayList class has a method called toArray() that we are using in our example to convert it into Arrays.
Following is simple code snippet that converts an array list of countries into string array.
Share

Wednesday, 5 June 2013

Changing the Font Size in Eclipse

Changing the Font Size in Eclipse

Within Eclipse click Window > Preferences. This will open up the Preferences dialog with gives you about a million configuration settings to tweak.

At the top of the list on the left you will see General. Click to open this. Next click Appearances. Finally, select Colors and Fonts from under Appearances.

This is where it gets confusing. Eclipse shows a tree of what appear to be languages or plugins or something. Underneath each one are many options for specific types of text. There are many choices in this dialog with no clearly obvious one.

Well, the one you’re looking for is “Text Font” under the “Basic” node. Select this and click the “Change…” button that appears. From here, it’s just a matter of selecting the new font size and applying it.

Oh, and when you’re ready to go back to the old font size just click the Reset button to go back to your old settings.
Share