Welcome to my blog, hope you enjoy reading
RSS

Monday, 8 July 2013

Java beep sound example

Java beep sound example

There are different ways to generate a beep sound in java. The general basic way to generate is to use java.awt.Toolkit class which has a default method to generate the beep sound. The other implementation is also shown below on how to generate beep sound in java.
Share

Friday, 28 June 2013

Eclipse to Merge Branch into Trunk

Eclipse to Merge Branch into Trunk

If the changes of branch project is merge to trunk then do the following steps in eclipse
  1. Find the revision number of the last merge 
    1. how to find the log of branch?
  2. Check out a copy of the trunk as, say, openmrs-trunk:
Share

Thursday, 27 June 2013

Using If Condition In Select Query in mysql

Using If Condition In Select Query in mysql

For Example

select If(Amt>0,'Yes','no')
from 
product

the above is not working

Solution:

Select Case
When Amt > 0 Then 'Yes'
Else 'No'
End AliasYourColumnHere
From Product
Share

Tuesday, 25 June 2013

HowTo: Run .jar files in Ubuntu

HowTo: Run .jar files in Ubuntu

  • To run a JAR file from the command line in ubuntu using the following command:
                 java -jar filename.jar
  • Otherwise it is also possible to enable double clicking to run jar files too by the following simple steps:
                 Find the .jar file in the File Browser (a.k.a Nautilus)
                 Right click the .jar file > Properties
                Click on the “Open With” tab along the top
                Change the bullet to be Sun Java 6 Runtime
                Click Close and you’re done.

Share

create the executable jar file using java

create the executable jar file using java

To create the executable jar file using java do following steps
  1. create the swing based UI in java and generate the .class file 
  2. after creating the mainfast file your choice (.txt ) and you will give the java class name like           Main-Class: TestApp  
  3. the above step2 ,you have write the Main-Class: after given one space and press two times enter button in keyboard
  4. C:/>jar cmf test.txt myjarfilename.jar *
  5. you have generate the executable jar file
    1. for ubuntu os you can give the permistions
    2. chmod +x myjarfilename.jar.

Creating an Executable Jar Files in Eclipse

  1. Highlight the appropriate file/project
  2. File -> Export
  3.  Choose "Runnable JAR file" -> Next
  4. Make sure the right project is selected under the "Launch Configuration" dropdown and select "Package required libraries into generated JAR file" under the "Library Handling" section and make sure it's going to the correct export destination. 
  5. click Finish

Now you should have the jar file in the destination you told it to export to. Double click it and it should run. 
**HOWEVER** If this is a command line program it will not run. To run a command line program, after doing the above steps, open the command prompt, cd to the correct directory, and execute it by typing
  java -jar name_of_file.jar 

Share

Compiling and Running Java Programs in Terminal on Ubuntu

Compiling and Running Java Programs in Terminal on Ubuntu

 You can install the open Java JDK by opening a terminal and running:

Code:
  • sudo apt-get install openjdk-6-jdk
this will also setup the classpath for you. Now you can simple compile and run you java source with the normal javac / java commands. Lets assume your file is called Myprog.java (with the class called Myprog) and is in your home folder... you can compile with:

Code:
  •  javac Myprog.java
Then run it with:

Code:
  •  java Myprog
Share

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