Thursday, June 18, 2009

Multi-threading in Java

Multi threading is really a nice feature a programming language can have. In multi threading you can make new threads in your program while it is running, which means program will be running in more than one thread simultaneously(parallel). It can be a very useful feature in some server client system. In java you can use multi threading in the following way.

1) to be able to run a class in a thread the class need to either extend Thread class or should implement Runnable.

2) The second requirement to be able to run a class into a thread is to have a method named run(), this method will contain what to run in the thread.

public ClassName extends Thread{

public ClassName implements Runnable{

3) Syntax to start the thread in some other class

ClassName name = new ClassName();
Thread t = newThread(name);

How to rename a large number of files at once in windows?

If you have a large number of files with random names ( lets say images from different sources with random names) and want to rename them all systematically for some reason.
On Microsoft windows there a simple trick to do this.

Select all the files.
Right click on any file and select rename ( or press F2 for rename)
Then give a name like img(1).jpg
And you are done. This will rename all the selected files as img(1).jpg, img(2).jpg, img(3).jpg .......

Please note that this will work for all kinds of files and extensions, not just images ( I took jpgs just for an example to illustrate)

Saturday, June 6, 2009

Amarok internet access behind proxy server

If you use amarok behind a proxy server and it cannot access internet (for example to fetch lyrics using a lyrics script, or to submit data to or any other task which requires it access the internet). The reason for this is that amarok does not read the system wide proxy settings from GNOME. To solve this problem you need to edit the following file :


and add the following entries to it :

[Proxy Settings][$i]

Save the file and Restart amarok.

Wednesday, June 3, 2009

OpenCV shared libraries error

If you installed opencv on your linux machine and are able to compile opencv programs but cannot run them and are receiving the following error :

error while loading shared libraries: cannot open shared object file: No such file or directory

This means that the program is not able to locate the shared libraries it needs to execute. To sort this out you to have set the LD_LIBRARY_PATH environment variable to the path of your opencv lib directory. This directory should be located in your opencv installation directory(if you installed opencv using the tar rather than using your linux distribution repositories). You can do this by the following command (assuming you have installed opencv in your user directory in a folder named "opencv" :

export LD_LIBRARY_PATH=/home/{username}/opencv/lib/

If you are using the eclipse IDE and getting the same error then to fix it you need to open the Run configurations dialogue box which is located in the run menu, select the environment tab and add a new variable named LD_LIBRARY_PATH with value as described above.