Concurrent HashMap vs synchronized HashMap..

In synchronized HashMap:
1) While reading, complete map is locked. Thus, if N threads are reading from it, at any given time, only one thread would be actually reading.
2) While writing, complete map is locked. Thus, if N threads are writing even to different keys, at any given time, only one write operation is performed.

In ConcurrentHashMap:
1) While reading, map is not locked. Thus, if N threads are reading from it, all of them can simultaneously read from map.
2) While writing, only the record (key) under consideration is locked. Thus, if N threads are writing values of different keys, all those operations can happen simultaneously. However, if 4 threads are writing to same key, those operations are thread-safe.

ConcurrentHashMap is recommended for large Maps or large number of read-write operations because of its good scalability.

Adding JSF Capabilities(Richfaces 4) to Eclipse Web project:

First Install JBoss Tools plugin for Eclipse Helios below are the steps:
Prerequisite: Install the most recent JBoss AS tools.
• Go to Help > Install New Software.
• Set Work with to http://download.jboss.org/jbosstools/updates/stable/helios/
• In the results, select Web and Java EE development.
• Next, etc, Finish.

Eclipse Jboss PlugIn

Eclipse JBoss Tools plugIn for Richfaces

This will get you the JBoss-provided server plugins, including the one supporting 6.0, along with several easing JSF development plugins, such as EL autocompletion.
You only need to ensure that you’re using Eclipse Helios SR1 (at least, the most recent WTP version). The initial Helios version had some vague problems with JBoss AS Tools.

Next Step:
1. Create a new “Dynamic project”
2. After creating the project, right click on the project select “configure” > “Add JSF Capabilities” as shown in the below screen shot.

Select Configure > JSF Capabilities

Click “Next” in the below screen:

Add JSF Capabilities Dialog

Add JSF Capabilities Dialog

In the below screen If there is an error then unselect “target server is already selected”.
And click Finish. This should successfully Add JSF (Richfaces 4 Capabilities to your project).

Add JSF Capabilities2 Dialog

Add JSF Capabilities2 Dialog

Server-side Sample Code to get Latitude and Longitude of a given address using Google map API

Server-side Sample Code to get Latitude and Longitude of a given address using Google map API:
Note: The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions @ http://code.google.com/apis/maps/terms.html#section_10_12.

import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URLEncoder;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class LongLatService {
	
	private static final String GEOCODE_REQUEST_URL = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&";
	private static HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
	
	public static void main(String[] args) throws Exception {
		LongLatService tDirectionService = new LongLatService();
  	    tDirectionService.getLongitudeLatitude("Rijnsburgstraat 9-11, Amsterdam, The Netherlands");
	}
	
    public void getLongitudeLatitude(String address) {
        try {
        	StringBuilder urlBuilder = new StringBuilder(GEOCODE_REQUEST_URL);
            if (StringUtils.isNotBlank(address)) {
            	urlBuilder.append("&address=").append(URLEncoder.encode(address, "UTF-8"));
            }

            final GetMethod getMethod = new GetMethod(urlBuilder.toString());
            try {
            	httpClient.executeMethod(getMethod);
                Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet());
                
                int data = reader.read();
                char[] buffer = new char[1024];
                Writer writer = new StringWriter();
                while ((data = reader.read(buffer)) != -1) {
                    	writer.write(buffer, 0, data);
               	}

                String result = writer.toString();
                System.out.println(result.toString());

                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		        DocumentBuilder db = dbf.newDocumentBuilder();
		        InputSource is = new InputSource();
		        is.setCharacterStream(new StringReader("<"+writer.toString().trim()));
		        Document doc = db.parse(is);
            
                String strLatitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lat/text()");
                System.out.println("Latitude:" + strLatitude);
                
                String strLongtitude = getXpathValue(doc,"//GeocodeResponse/result/geometry/location/lng/text()");
                System.out.println("Longitude:" + strLongtitude);
                
                
            } finally {
                getMethod.releaseConnection();
            }
        } catch (Exception e) {
             e.printStackTrace();
        }
    }

    private String getXpathValue(Document doc, String strXpath) throws XPathExpressionException {
        XPath xPath = XPathFactory.newInstance().newXPath();
        XPathExpression expr = xPath.compile(strXpath);
        String resultData = null;
        Object result4 = expr.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result4;
        for (int i = 0; i < nodes.getLength(); i++) {
        	resultData = nodes.item(i).getNodeValue();
		}
        return resultData;
    }
    
}

Server side sample program on calculating shortest distance between two addresses using Google API.

Server side sample program on calculating shortest distance between two addresses using Google API.
Note: The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions @ http://code.google.com/apis/maps/terms.html#section_10_12.

import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class DrivingDistanceAndDurationService {

	public static void main(String[] args) {
		DrivingDistanceAndDurationService directionService = new DrivingDistanceAndDurationService();
		String addressFrom = "3316+REYNOLDS+DR+Huntsville+AL+35810";
		String addressTo = "2811+CORA+HILL+AVE+Huntsville+AL+35810";
		directionService.calculateRoute(addressFrom, addressTo);
	}

	public void calculateRoute(String addressFrom, String addressTo) {
		String outputResult = "";
		String urlString = "http://maps.googleapis.com/maps/api/directions/xml?sensor=true&origin="
				+ addressFrom + "&destination=" + addressTo;
		System.out.println(urlString);
		
		try {
			URL urlGoogleDirService = new URL(urlString);

			HttpURLConnection urlGoogleDirCon = (HttpURLConnection) urlGoogleDirService.openConnection();

			urlGoogleDirCon.setAllowUserInteraction(false);
			urlGoogleDirCon.setDoInput(true);
			urlGoogleDirCon.setDoOutput(false);
			urlGoogleDirCon.setUseCaches(true);
			urlGoogleDirCon.setRequestMethod("GET");
			urlGoogleDirCon.connect();

			try {
				OutputStream output = new OutputStream() {
					private StringBuilder string = new StringBuilder();

					@Override
					public void write(int b) throws IOException {
						this.string.append((char) b);
					}

					@Override
					public String toString() {
						return this.string.toString();
					}
				};

				byte buf[] = new byte[1024];
				int len;

				while ((len = urlGoogleDirCon.getInputStream().read(buf)) > 0) {
					output.write(buf, 0, len);
				}
				output.close();
				urlGoogleDirCon.getInputStream().close();
				outputResult = output.toString();

				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				DocumentBuilder db = dbf.newDocumentBuilder();
				InputSource is = new InputSource();
				is.setCharacterStream(new StringReader(outputResult));

				Document doc = db.parse(is);

				XPath xPath = XPathFactory.newInstance().newXPath();
				XPathExpression expr = xPath.compile("//DirectionsResponse/route/leg/duration/text/text()");

				Object durationNodeList = expr.evaluate(doc, XPathConstants.NODESET);
				NodeList durationNodes = (NodeList) durationNodeList;
                                int durationLength = durationNodes.getLength();
				for (int i = 0; i < durationLength; i++) {
					System.out.println("Duration:" + durationNodes.item(i).getNodeValue());
				}

				XPath xPath1 = XPathFactory.newInstance().newXPath();
				XPathExpression expr1 = xPath1.compile("//DirectionsResponse/route/leg/distance/text/text()");

				Object distanceNodeList = expr1.evaluate(doc, XPathConstants.NODESET);
				NodeList distanceNodes = (NodeList) distanceNodeList;
                                int distanceLenght = distanceNodes.getLength();
				for (int i = 0; i < distanceLenght; i++) {
					System.out.println("Distance:" + distanceNodes.item(i).getNodeValue());
				}

				System.out.println("Done successfully");
			} catch (IOException e) {
				e.printStackTrace();
			}

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

Steps to Evaluate Open Source Software

Steps to Evaluate Open Source Software is primarily based on four steps:
1. Identify the potential candidates/tools.
Identifying the potential open source tools can be done by:
■ Market Research
■ Technical documents/blogs, popular sites like sourceForge etc
■ Some are picked based on Product’s popularity (example: Apache’s open source tools)
■ Team discusssions or by word of mouth
■ Subject matter experts
■ Through publicly posted evaluations
■ OpenLogic’s list of OSS/FS programs; they include the license info as well.
■ OSALT – Open source as ALTernative
■ Google search
■ Or by posting questions in Technical Fourms.

2. Look at the reviews/comments on that particular tool:
Read exiting blogs, reviews and evaluations about the alternatives. Best way to get the reviews is by search engine (e.g. google). This will help to get some important information about the product and also some additional alternatives which were not considered/identified earlier.

Though its just to get additional information its not some thing which you need to puerly go by the comments as some of the websites/magazines sometimes provide biased information becaused of advertising.

Market share: An indirect reivew which is enjoyed by the product. Market share is extremely hard to measure for most products, because anyone can just download and install them without registering with anyone, this is specially case with open source software.

Another piece of information is through Linux distributions. These distributions keep the number of components low to reduce the number of CD-ROMs in their distribution, and evaluate products first to see which ones to include. Thus, if the product is included, it’s likely to be one of the best OSS/FS products available, because its inclusion reflects an evaluation by someone else. Specially in case of browsers.

3. Compare the basic attributes/criteria to your needs:
■ Functionality
■ Cost
■ Market Share
■ Documentation
■ Support
■ Maintenance/Longevity
■ Reliability
■ Performance
■ Scaleability
■ Useability
■ Security
■ Flexibility/Customizability
■ Interoperability
■ Legal/license issues
■ Other/Current open Issues

4. Perform an in-depth analysis of the top candidates
The important attributes to consider are the same as in the previous step; one need to simply spend more effort by actually trying things out instead of quickly reading the references and available documentation.

This step would be similar to Open Source Software (OSS) and commercial products (COTS).

Doing some Proof of Concept on the required features and non-funcational features like Performance, Scalaibiltiy and Software security with mocked data and by setting environment as close as to actual environment. Both environment and sample production data would be really prove the concept indirectly the actual software which is under scanner.

Little about J2EE Software Selection:
Choosing a J2EE solution then breaks itself into one of two main categories (there are of
course many variations in between these two extreemes):
1. Standalone J2EE systems – interoperability is not necessary (perhaps a Web application that “interoperates” through sharing a common database backend or via XML) or where isolation of the solution is important.
• Developer Productivity
• Distributed Application Management
• J2EE Compliance
• Load Balancing and Fail Over
• Organisational Stability
• Performance of Applications
• Vendor Stability
2. Infrastructure J2EE systems- where J2EE is a decision for the organisation and interoperability at a level greater than simply database or XML level is important. Typically Remote Procedure Calls (RPC) (and sometimes Message Oriented
Middleware (MOM)) mechanisms are important across applications.
• Developer Productivity
• Distributed Application Management
• EJB Prohibitions
• Interoperability
• J2EE Compliance
• Load Balancing and Fail Over
• Modular Design
• Organisational Stability
• Performance of Applications
• Support for Common Distributed Problems
• Vendor Stability