How to Sort a Two Dimensional String Array using JAVA

February 15th, 2010 No comments

Recently I had to write a program to sort data (String) in a table and was looking for an efficient and easiest way to do sorting in java. I found two options – one was to write my own sorting program, and the other was to use the Comparator class in the Util package. I found that using Comparator or Comparable interface was very easy compared to writing my own sorting algorithm.

If you are new to using “Comparator”, I highly recommend reading this one page tutorial.

Here is a working example for sorting a two dimensional string array:

import java.util.Arrays;
import java.util.Comparator;

public class Sort {	
	public static void main(String args[]){
		//Array with address to sort
		String[][] addressArray = new String[][]{
				{"E","abc st","Sunshine", "FL"},
				{"S","abc st","Sunrise", "FL"},
				{"E","abd st","Cleveland", "OH"},
				{"N","aab st","Dallas", "TX"},
				{"W","xyz st","San Antonio", "TX"}};
		//Sort the array by city name or column 3
		Arrays.sort(addressArray, new ColumnComparator(2));
		//Print the sorted array
		for(int i=0; i<addressArray.length; i++){
			String[] row = addressArray[i];
			for(int j=0; j<row.length; j++) {
				System.out.print(row[j] + " | ");
//Class that extends Comparator
class ColumnComparator implements Comparator {
	int columnToSort;
	ColumnComparator(int columnToSort) {
		this.columnToSort = columnToSort;
	//overriding compare method
	public int compare(Object o1, Object o2) {
		String[] row1 = (String[]) o1;
		String[] row2 = (String[]) o2;
		//compare the columns to sort
		return row1[columnToSort].compareTo(row2[columnToSort]);

Results – sorted by city name

E | abd st | Cleveland | OH | 
N | aab st | Dallas | TX | 
W | xyz st | San Antonio | TX | 
S | abc st | Sunrise | FL | 
E | abc st | Sunshine | FL | 
Categories: Tech Tips Tags: , ,

How to match AdSense colors with the WordPress theme?

February 9th, 2010 1 comment

Ever wondered how to display ads from Google Adsense that will blend in with your wordpress theme and colors, rather than having the standard white and blue that will shadow everything else you have on your site. I read articles from different bloggers, which suggested that a site with AdSense in matching theme would have a better click-rate compared to ones with the standard colors. I thought of trying this, and listed below are the steps I followed.

In order to change the colors, you have to generate the adsense ad units with colors that match your site. Go to Adsense Setup > Get Ads > Adsense for Content > Ad Unit > Colors

Google will allow you to edit each of the fields in this default color palette, but the trouble is to identify matching colors by looking at your stylesheet. All the colors and styles will be defined in “syle.css”, and you will be able to access this file by going to Dashboard > Appearance > Editor or download the theme and look for the style.css.  In the example below, I am trying to match adsense colors to the sidebar of wordpress theme “iNova”.

In syle.css search for “background:” look for the block were you want your ads to appear.
sidebar { background:#F7F7F7 url(img/sidebar_shadow.gif) top repeat-x;
This is just an example. Different themes will have different way of defining background colors.

Keep the color same as background so that border will be invisible.

Look for the style definition for anchor tags
a { color:#2970A6;

For the side panel, keep it the same color as the URL (varies for theme).

Look for the color definition for anchor tags
title a { color:#FFFFFF;

Look for font definitions like – “font-family:”
body {
font-family:Verdana,”BitStream vera Sans”,Tahoma,Helvetica,Sans-serif;

Here is the final color palette that match WordPress iNove theme sidebar.

If you know of any better ways to match colors please feel free to comment.


How to increase server timeout in eclipse?

February 4th, 2010 No comments

If you are running JBOSS or other servers within eclipse, and your application takes more than 50 seconds to launch, then you might see a similar exception – “Server JBOSS was unable to start within 50 seconds. If the server requires more time try increasing the timeout in the server editor”

To fix this timeout in eclipse (Galilieo), go to Window -> Show View -> Servers -> Click on server name -> Increase start timeout.

If you are using an older eclipse build (Europa or below), then go to Window -> Preferences -> Server

Categories: Tech Tips Tags: , ,

How to transfer contacts to Samsung SPH A900 cell phone?

February 14th, 2007 3 comments

I recently brought a new SPH A900 and was looking around for a way to transfer all the contacts from my old cell phone. Lot of websites offered help in transferring contacts one at a time, but transferring 300 plus contacts, one at a time was a nightmare.

Recently I figured how to transfer contacts in bulk. Here are the steps.

  1. Transfer contacts from your old cell phone to Microsoft Office Outlook. My old Sony Ericsson had a feature to sync with Outlook, so it was easy to transfer contacts to outlook. Outlook also offers many ways to import contacts, just in case your phone doesn’t have a sync feature.
  2. Purchase KENSINGTON 33348 Bluetooth USB 2.0 Adapter and install the software that comes with it.
    (Note: All Bluetooth adapters will not allow bulk transfer. I tested the same with TRENDNET Bluetooth adapter and it did not allow bulk transfer.)
  3. Follow the instructions and pair your phone (SPH-A900) with the Bluetooth adapter plugged into your laptop or desktop.
  4. Now open Microsoft Office Outlook, go to contacts and select all the contacts you want to transfer to your phone.
  5. Go to menu File and you will see an option to “Send To Bluetooth”. Select your phone and all your contacts would be transferred as vcard. Make sure you accept the data on the phone.


Hope it helps.

Categories: Tech Tips Tags:

Email to Fax – FREE

November 16th, 2006 1 comment

TCP Fax offers a service that enables you send fax from your email, for free. To send your fax via e-mail, start your mail software and compose a new e-mail message.

An example:


This will send a fax to the number 495-968-2590 (the first ‘1‘ at in the fax number is the country code for the USA)
The coversheet will look like this:

Please deliver to:
Arlington Hewes
Room 403

Before you try, check whether your fax number is covered:


Categories: Cool Sites Tags:

Hide batch command window

November 8th, 2006 7 comments

If you are trying to run a Java Swing application by clicking on a batch file in Windows, you will see an empty command window and the swing application. There is no one magic command that will hide the command window, but here is a little script that will do the trick –

Files: MyApp.jar, AppStart.bat, run.bat

java -jar MyApp.jar

@echo off
set VBS=”%TEMP%\HideCmdWindow.vbs”
if exist %VBS% goto Runit
@echo dim obj, obj1, obj2, objArgument>%VBS%
@echo Set WshShell = WScript.CreateObject(“WScript.Shell”)>>%VBS%
@echo Set objArgument = Wscript.Arguments>>%VBS%
@echo obj = WshShell.Run(“AppStart.bat“, 0)>>%VBS%
@echo set WshShell = Nothing>>%VBS%
set param=%*
set param=”%param:”=“`%”
cscript //nologo %VBS% %param%

Start your application by clicking on run.bat and the command window should be hidden. You should implement this only if you do not wish to see the debug/error statements thrown to the command window.


Categories: Tech Tips Tags:

FREE upgrade to Windows Vista

October 26th, 2006 No comments

When you buy a qualifying Windows Vista Capable PC between October 26, 2006 and March 15, 2007, you may be eligible for an Express Upgrade to Windows Vista. Ask your retailer about the Express Upgrade to Windows Vista, being offered by participating PC manufacturers.

Receive an Express Upgrade to Windows Vista when you buy a qualifying PC running Windows XP Media Center Edition, Windows XP Tablet PC Edition, or Windows XP Professional. The five different editions of Windows Vista are designed to fit the way you intend to use your PC:

Windows Vista Business
Regardless of the size of your organization, Windows Vista Business will help you lower your PC management costs, improve your security, enhance your productivity, and help you stay better connected.

Windows Vista Enterprise
Windows Vista Enterprise is designed to meet the needs of large global organizations with highly complex IT infrastructures. Windows Vista Enterprise can help you lower your IT costs while providing additional layers of protection for your sensitive data.

Windows Vista Home Premium
Whether you choose to use your PC to write e-mail and surf the Internet, for home entertainment, or to track your household expenses, Windows Vista Home Premium delivers a more complete and satisfying computing experience.

Windows Vista Home Basic
Windows Vista Home Basic is designed to deliver improved reliability, security, and usability to home PC users who just want to do the basics with their PCs.

Windows Vista Ultimate
If you want all of the best business features, all of the best mobility features, and all of the best home entertainment features that Windows Vista has to offer, Windows Vista Ultimate is the solution for you. With Windows Vista Ultimate you don’t have to compromise.



Categories: Tech Tips Tags:

Windows XP – search NOT finding files

October 16th, 2006 3 comments

Other day I was searching for a file in my desktop using Windows Search option “A word or phrase in the file” and search results came back saying “Search is complete. There are no results to display“. But I was certain the file with the keyword that I was searching for existed in my machine, and sure enough I was able to locate the file after going through a ton files. Once I located the folder in which my file existed, I ran the search again on the folder with the same keywords, but search gave the same results as before.

After browsing around a little, I found that this is a known bug with Windows XP and Windows Server 2003 editions. Multiple resolutions are given at Microsoft site under the link Using the “A word or phrase in the file” search criterion may not work

I used method2 and here is how it looks:
To configure Windows XP to search all files no matter what the file type, obtain the latest service pack for Windows XP and then turn on the Index file types with unknown extensions option.

If you use this method, Windows XP searches all file types for the text that you specify. This can affect the performance of the search functionality. To do this:
1. Click Start, and then click Search (or point to Search, and then click For Files or Folders).
2. Click Change preferences, and then click With Indexing Service (for faster local searches).
3. Click Change Indexing Service Settings (Advanced). Note that you do not have to turn on the Index service.
4. On the toolbar, click Show/Hide Console Tree.
5. In the left pane, right-click Indexing Service on Local Machine, and then click Properties.
6. On the Generation tab, click to select the Index files with unknown extensions check box, and then click OK.
7. Close the Indexing Service console.


Fore more details visit MSDN Knowledgebase


Categories: Tech Tips Tags:

How to locate MAC Address for Wireless Adapter in Windows XP?

October 13th, 2006 4 comments

step1: Click Start then select Run

step2: In the little box type cmd and click OK

step3: Once the command window opens up,type ipconfig/all and press Enter cmd1.jpg

step4: Mac/Physical address for each adapter in your machine will be displayed on the screen. Check for the physical address under Wireless Adapter that will be the MAC Address you looking for.

Categories: Tech Tips Tags:

How to create a jar file using Ant that refers to other jar files?

September 29th, 2006 6 comments

To create a jar file named “TestWizard.jar” that uses at least 10 other jar files in a folder named “lib”. Build file should be created in such a way that build.xml doesn’t need to be modified when a new jar file is added to the lib folder.

To execute TestWizard.jar, that refers to classes residing in the lib folder. All the jars need to be set to the CLASSPATH to that it be visible from TestWizard.jar

Working Solution
Set the Class-Path attribute of MANIFEST.MF inside TestWizard.jar with all the jar files in the library.

Folder structure

lib —
– a.jar
– b.jar
– c.jar

Manifest Classpath setting for TestWizard.jar
<attribute name=”Class-Path” value=”lib/a.jar lib/b.jar lib/c.jar”/>

Code Snippet

<!– Add all the jar files in lib folder to the class path –>
<path id=”build.classpath”>
<fileset dir=”${basedir}/”>
<include name=”lib/*.jar”/>

<pathconvert property=”test.project.manifest.classpath” pathsep=” “>
<path refid=”build.classpath”/>
<globmapper from=”*.jar” to=”lib/*.jar”/>

<!– Create jar file –>
<target depends=”compile” name=”jar”>
<jar jarfile=”${basedir}/${TestWizard.jar}”>
<fileset dir=”${build}” />
<attribute name=”Main-Class” value=”com.test.panels.TestMain”/>
<attribute name=”Class-Path” value=”${test.project.manifest.classpath}”/>


Erroneous Approaches

  • If you just include the external jar files (from lib folder) into TestWizard.jar, then the classpaths won’t be set correctly. Alternative is use onejar solution (
  • Create a batch file, that will set the set the classpath individually to all the jar files in the lib folder and then execute TestWizard.jar. This might work, but I was experiencing classnotfound exceptions
Categories: Tech Tips Tags: