Thursday, October 8, 2009

Easy way to keep your Blog and Twitter up-to-date.

I was thinking how can I keep my blog and my twitter up-to-date, if I add any new post in my blog and I have to come back to twitter to do the same.
This is a redundant work which I have to do. Today when I was searching in the net found a cool web application which will update your twitter accounts if any update is made in your blogs.
The way it works is it takes your RSS feeds of your blog and understands the updates based on that it updates your twitter account.

twitterfeed

Then I added follow me on twitter in blog ;)
Try if you like it :)

Wednesday, October 7, 2009

How can we track from where user started to access your Web Application?

Most of the time we want to know from where the user started to trigger our URL, most of the time it will via of google.com. It terms of marketing a product its very important to know how the URL was triggered...I was think the only way is to add the reference as a request parameter, but there is also another option is available in HTTP header fields.

Referer Header Field:

This field in the header object will give you the web page URL from which you application was triggered.
Below code in java will give you the reference URL.


String refUrl = request.getHeader("referer");

Tuesday, October 6, 2009

Is there any difference between java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException ?

When we started learning java most of time we may come across java.lang.ClassNotFoundException when we try to run some simple programs. Later we found that this error was throwing due to the class was not in the jvm class-path.

java.lang.NoClassDefFoundError will be thrown when the class was loaded and it cannot be initialized properly. As JVM can find the classes in the class-path and it cannot create a Class object of the class which is loaded.

Below are few scenarios where the class initializing may throw exception.

·        When a exception was thrown inside the static block of the class.

o   The reason is the static block is executed when the Class object is getting loaded, if any error occurs it can't be initialized.

·        Any Exception was thrown when initialing a static variable of the class.

o   The reason remains same as static block. It also getting executed during Class load.

 

Then the morel of the story is when the class was not properly initialized then we will get java.lang.NoClassDefFoundError, mainly due the static blocks and static variables.

Simple Example which will throw java.lang.NoClassDefFoundError..

package passionsoft.bloggerspot.com;

 

public class AnotherClass {

          static String test = "new";

          static AnotherClass staticObject = new AnotherClass();

 

          public AnotherClass() {

                   String a = null;

                   a.length();

          }

}

package passionsoft.bloggerspot.com;

 

public class SimpleTest {

          public static void main(String[] args) {

                   AnotherClass a= null;

                   try {

                             a = AnotherClass.staticObject;

                   } catch (Error e) {

                             e.printStackTrace();

                   }

                   System.out.println(AnotherClass.test);

          }

}

When SimpleTest calles the "AnotherClass.staticObject" the class get loaded and the static variable staticObject calles the constructor where the initialization failes… below is the error trace

java.lang.ExceptionInInitializerError

          at passionsoft.bloggerspot.com.SimpleTest.main(SimpleTest.java:11)

Caused by: java.lang.NullPointerException

          at passionsoft.bloggerspot.com.AnotherClass.<init>(AnotherClass.java:12)

          at passionsoft.bloggerspot.com.AnotherClass.<clinit>(AnotherClass.java:7)

          ... 1 more

Exception in thread "main" java.lang.NoClassDefFoundError

          at passionsoft.bloggerspot.com.SimpleTest.main(SimpleTest.java:19)

 

As per my understanding I can think only two scenarios when the java.lang.NoClassDefFoundError was thrown if you guys know some more scenarios please update the comments.:)

 

Monday, October 5, 2009

Great Add-ons for Mobile Testing

When you want to change your User-Agent name of your Browser (its nothing but your browser name which sent to the server on every request) you can use the "User Agent Switcher" Add-ons of Fire fox to change your user-agent....

What is the Special about Changing User-Agent?

The "User-Agent" is the only way (as of I know) the server come to know from which browser the user was triggered this request, based on that server may change its display logic...

If you try google.com from your mobile, you will see a different version as compared to your google.com from your web browser (IE or Mozilla), that difference. If you are a mobile developer want to know how the data are displayed for a Specific model you can give the user agent string of that Mobile then trigger the request.

For Example when you change your user-agent as "BlackBerry8800/4.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/100" and hit from you Fire-fox browser, the content will be displayed as it was seen in Blackberry 8800 Mobile…

These Very good Add-ons if you need to test with different mobile devices (as I do right now)…J.. Please feel free to add your comments ….