Posts Tagged ‘Programming Practice’
Todays read: Mastering CSS Coding
Mastering CSS Coding: Getting Started
An amazingly simple and useful article from Smashing Magazine.
CSS has become the standard for building websites in today’s industry. Whether you are a hardcore developer or designer, you should be familiar with it. CSS is the bridge between programming and design, and any Web professional must have some general knowledge of it. If you are getting your feet wet with CSS, this is the perfect time to fire up your favorite text editor and follow along in this tutorial as we cover the most common and practical uses of CSS.
Read it here: http://www.smashingmagazine.com/2009/10/05/mastering-css-coding-getting-started/
Follow them in twitter
How-to: Write web services using Axis2
This is a very basic post on writing a web service provider and consumer using Axis2. You can find such posts anywhere in the web. Here I’ve tried to make it as simple as I can.
Set up: What all we need to do?
1. Axis2 runtime.
I tried with WAR distribution from http://ws.apache.org/axis2/download/1_5/download.cgi
2. A web/app server. I am using Tomcat.
Using the Axis2 runtime & setting it up
Extract the Axis2 WAR distribution and keep it in the deploy directory of the server. In case of Tomcat keep it in webapps. This is how my directory structure look like.
The WEB-INF is the most important directory. Tell you why. Unlike our normal WEB-INF in archives, this directory hold some special sub-directories. Here goes which contains what.
classes – compiled Java classes. We can find some Axis specific classes here.
conf – axis.xml (Axis configuration file)
lib – All necessary Axis2 libraries (JARs)
modules – Don’t ask me. Even I’m not sure. Did I mention that I’m also a beginner? ![]()
services – All web service archives & services.list
Coding: What we need to write?
1. The service provider. A Java class.
2. service.xml. The web services descriptor.
3. build.xml. To build and deploy the web services archive.
4. The service consumer. Another Java class to consume the services offered
And we are good to go now. Let’s make our hands dirty with some Java code. This is very simple and kudos to Axis2.
The service provider: SampleService.java
package subin.rnd.ws;
public class SampleService
{
public WsOutput doSomething(WsInput anInput)
{
System.out.println("doSomething()");
WsOutput anOutput = new WsOutput();
anOutput.setResponseString("I did some thing to " + anInput.getName());
return (anOutput);
}
}
WsInput is a sample input class to demonstrate that we can have more complex IO is possible. Similarly WsOutput is the output class. Instead of using WsInput / WsOutput for IO, we can use normal data types like integer, float, string etc too.
WsInput.java
package subin.rnd.ws;
import java.io.Serializable;
public class WsInput implements Serializable
{
private String name;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return (this.name);
}
}
WsOutput.java
package subin.rnd.ws;
import java.io.Serializable;
public class WsOutput implements Serializable
{
private String responseString;
public void setResponseString(String response)
{
this.responseString = response;
}
public String getResponseString()
{
return (this.responseString);
}
}
We have the Java part of the web-service ready. But that’s not enough. We need to deploy the web-service as an AAR – Axis Archive – file. An AAR is just another zip file (like a JAR) with a funky extension
. The AAR should contain the class files along with the services.xml – web service descriptor.
Web service descriptor: services.xml
<service name="SampleWs" scope="application"> <description>Subin's sample webs service</description> <messagereceivers> <messagereceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messagereceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messagereceivers> <operation name="doSomething" /> <parameter name="ServiceClass">subin.rnd.ws.SampleService</parameter> </service>
The services.xml is the place where we define the details of the services being offered.
Build file: build.xml
<project name="my.webservice.test" default="build.aar">
<property name="deploy.dir" value=".../webapps/axis2.war/WEB-INF/services" />
<property name="file.name" value="subinws.aar" />
<target name="build.aar">
<javac srcdir="src" destdir="bin" />
<echo>Copying services.xml to bin</echo>
<copy file="META-INF/services.xml"
tofile="bin/META-INF/services.xml" overwrite="true"/>
<jar basedir="bin" destfile="${file.name}" />
<echo>Deleting services.xml from bin</echo>
<delete dir="bin/META-INF" />
<copy file="${file.name}" tofile="${deploy.dir}/${file.name}" />
</target>
</project>
So I hope we have an AAR ready, which is copied to the services directory. But we’ve not done yet. Now we have to make an entry in services/services.list file. Just insert the name of the ARR file at the end of it – in this case “subinws.aar”.
Please wait for part 2.
How-to: Create my first iPhone application
These days everyone wants to create iPhone applications. But “user retention” is the biggest challenge most the application developers or companies facing. As per some analysis report which I went through sometime back, the amount of returning users/customers is very less. Problems may be the way we (developers) develop those products, not-so-good application usability or even the confused user.
I think this Smashing magazine article – How to Create Your First iPhone Application – can help us to a great extend.
What if you had a nickle for every time you heard: "I have the perfect idea for a great application!"? It’s the buzz on the street. The iPhone has created unprecedented excitement and innovation from people both inside and outside the software development community. Still for those outside the development world, the process is a bit of a mystery.
This how-to guide is supposed to walk you through the steps to make your idea for an iPhone app a reality. This post presents various ideas, techniques, tips, and resources that may come in handy if you are planning on creating your first iPhone application.
Read the article: http://www.smashingmagazine.com/2009/08/11/how-to-create-your-first-iphone-application/
Today’s read: 10 Ways To Make Your Site Accessible Using Web Standards

A Smashing Magazine article on making a website accessible using web standards. Nice read.
Let’s take a look at 10 ways to improve the accessibility of your XHTML website by making it standards-compliant. We’ll go the extra mile and include criteria that fall beyond the standards set by the W3C but which you should follow to make your website more accessible. Each section lists the criteria you need to meet, explains why you need to meet them and gives examples of what you should and shouldn’t do.
Read the article here: http://www.smashingmagazine.com/2009/06/18/10-ways-to-make-your-site-accessible-using-web-standards/
TreeMap vs HashMap
Both TreeMap & HashMap are two different implementation of the Map interface. Even though this post is titled “TreeMap vs HashMap” I would like to say how they are connected and how much similar they are.
Both TreeMap & HashMap are not synchronized. To make it synchronized we have to explicitly call Collections.synchronizedMap( mapName ) . Both supports “fail-fast” iterators. Both of them doesn’t support duplicate keys.
HashMap
HashMap allows null as both keys and values. HashMap is useful when we need to access the map without cosidering how they are added to the map (means, unordered lookup of values using their keys). HashMap is synchronized while it is being looked up. HashMap doesn’t allow duplicated entries.
The performance of HashMap is based on two optional parameter which we can specify during the creation of the HashMap. Initial capacity & load factor. Initial capacity is the bucket size assigned to a HashMap during it’s creation. Load factor decides when the HashMap needs to be expanded. If the load factor is 0.75, the size will be increased when the current size of the map crosses 75% of its capacity.
TreeMap
The basic difference between HashMap & TreeMap is that, in a TreeMap the elements are stored in a tree. TreeMap allows us to retrieve the elements in some sorted order defined by the user. So we can say that TreeMap is slower than HashMap. This is the only implementation based on SortedMap interface.
TreeMap allows us to specify an optional Comparator object during its creation. The keys should be compatible with the comparator specified. This comparator decides the order by which the keys need to be sorted.
public interface Comparator
{
public int compare (Object object1, Object object2);
public boolean equals (Object object);
}
If we are not specifying the comparator, TreeMap will try to sort the keys in the natural order. Means will consider them as instances of Comparable interface.
public interface Comparable
{
public int compareTo (Object objectToCompare);
}
Classes like Integer, String, Double etc implements Comparable interface. So if we are to use an object of a custom class as the key, ensure that it’ s class implements the Comparable interface.
public class MyCustomKey implements Comparable
{
private int value;
public MyCustomKey(int value)
{
this.value = value;
}
public int compareTo (MyCustomKey key)
{
int comparison = 0;
// Note:
// Return -1 if this.value < key.value
// Return 0 if this.value = key.value
// Return 1 if this.value > key.value
return (comparison);
}
}
A common mistake that everyone does is not to override the hashcode(). If we are failing to do so, map.get(new MyCustomKey(<value>)); may not give you what you were expecting. So it is always adviced to override the hashCode() if objects of that class is being used as a key.
public class MyCustomKey implements Comparable
{
private int value;
public MyCustomKey(int value)
{}
public int compareTo (MyCustomKey key)
{}
public int hashCode()
{
// Note:
// If two objects are equal then their corresponding hashCode ()
// should return the same value too.
return (this.value * 199);
}
}


