- my webspace

- my webspace

Latest Comment

Allama Iqbal - Selective verse...
Yahoouj
Really good work about this website was done. Keep trying mo...
07/03/10 21:04 More...
By Roderick

Allama Iqbal - Selective verse...
Great Job
You have dont a great job of collecting these... Even I had ...
25/08/09 07:01 More...
By Sikandar

O ye who don't believe !
It's like Lehman Brothers :grin
11/10/08 16:31 More...
By anurag Chaturvedi

I Protest
@Sikku
Thanks Sikku for the feedback. I never intend to blame, a...
29/07/08 17:06 More...
By Aminur Rashid

I Protest
Great !!!
:zzz this is a wonderful story and very honest from the hea...
29/07/08 10:33 More...
By Jennifer Gallagher

Login






Lost Password?
No account yet? Register

Tell a Friend

Home arrow Java
Accessing Twitter Resources Using OAUTH PDF Print E-mail
User Rating: / 1
Written by Aminur Rashid   
Thursday, 03 May 2012

OAuth is an Authorization scheme to protect resources. It is widely used to share private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their credentials. Twitter is one of such website, that exposes its resources as Rest Web services. These resources are protected resources and can be accessed against proper Authorization.

User will need the access if he is building a twitter Application. Following steps explains the simplest use case to access friend's or one's own timeline.

1).Register an application with twitter.

Go to twitter's development resource and register your Application. [URL : https://dev.twitter.com/apps/new]

Once the application is registered, note down the Consumer key and Consumer Secret for your application. For the Demo, I am using dummyConsumerKey/Secret which should be replaced with your working Consumer key and Consumer Secret

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (6) | Quote this article on your site | Views: 160 | E-mail

Last Updated ( Thursday, 03 May 2012 )
Read more...
 
Resurrecting the dead ones. PDF Print E-mail
User Rating: / 0
Written by Aminur Rashid   
Friday, 27 April 2012

In one of the puzzle at his blog site, Wouter came up with this java puzzle : Who came first Chicken or Egg. Here is the puzzle from his website:

The egg:
package chicken;
 
public class Egg {
    final Object first;
 
    public Egg(Chicken mom) {
        first = mom.first;
    }
}

The Chicken:
package chicken;
 
public class Chicken {
    final Object first;
 
    public Chicken(Egg egg) {
        first = egg.first;
    }
 
    public void ask() {
        // The goal is to reach this line
        System.out.println("First there was the " + first);
    }
}

The creator:
package creator;
 
import chicken.Chicken;
 
public class Creator {
    public static void main(String[] args) {
        new Chicken(null).ask();
    }
}

Task is to modify Creator class in a way, that ask method is called. And rule remains that reflection should not be used. [you must run with the security manager enabled (-Djava.security.manager). Your solution must be in the creator package].

Try out before looking for the solution.


Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (9) | Quote this article on your site | Views: 104 | E-mail

Last Updated ( Friday, 27 April 2012 )
Read more...
 
Java Empty String PDF Print E-mail
User Rating: / 0
Written by Aminur Rashid   
Sunday, 25 March 2012

Post JDK 1.6, the new utility in String class reads as isEmpty(). If String is empty, can it contains(CharSequence ch) another String.

Answer is YES.

static void emptyContainer(String s1, String s2) {
   if (s1.isEmpty()) {
      assert !(s1.contains(s2));
   }
}


Now that made me revisit the code to find number of occurrence of a sub String inside a parent String. At a considerable amount of forums, the code variant as follows :
    public static int countSubstringV1(String mainString, String subStr) {
        int lastIndex = 0;
        int count = 0;
        while ((lastIndex = mainString.indexOf(subStr, lastIndex)) != -1) {
            count++;
            lastIndex += subStr.length();
        }

//or

public static int countSubstringV2(String mainString, String subStr){
		int ans = 0;
		Matcher m = Pattern.compile(Pattern.quote(subStr)).matcher(mainString);
		while (m.find())
			ans++;//count it
		return ans;
	}
More variations at rosettacode. Try the two methods above passing "Aminur","" as two arguments. First one goes in an endless loop while second one returns mainSting.length()+1.

So its better idea, to check for empty String as well, along with its null check. Specially when conditions require dependency on contains() or e.g indexOf(...).

BTW, if you are going to provide a check in countSubstring method above e.g if(subStr.isEmpty()){..} what will be your return value? 0?mainString.length()?IllegalArgumentException?

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (13) | Quote this article on your site | Views: 156 | E-mail

Last Updated ( Sunday, 25 March 2012 )
 
Axis1 date datatype workaround PDF Print E-mail
User Rating: / 1
Written by Aminur Rashid   
Monday, 09 May 2011

If you are handling a legacy system, using Axis (1.4) webservices you must have come across Java2WSDL and WSDL2Java tools. The tools help you to generate a WSDL from a java class as well as generating stubs/skeletons from a WSDL. However if are dealing with java.util.Date fields in your code, you should notice following :
package com.aminur.test.ws.axis1.dateservice;

import java.util.Date;

public abstract class TestService {
	public abstract Date fetchEndDate();

	public void updateEndDate(Date dateToBeSet) {
	}
}

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (64) | Quote this article on your site | Views: 1044 | E-mail

Last Updated ( Monday, 09 May 2011 )
Read more...
 
Thread unsafe Format in Java PDF Print E-mail
User Rating: / 0
Written by Aminur Rashid   
Tuesday, 12 April 2011


Recently I was asked by one of our team mate that during load testing, order creation was failing (One of the application I am working on is an Order Management Application) because of wrong inputs. However, the unit tests, with the same input was working fine. Investigation into it, led to (once again) an old jdk "designed" bug 4146524 (or feature). After seeing such issues in a number of applications, I am sure a number of developers are yet not aware of Format objects are not thread-safe. So if you create a Format object (or a MessageFormat, NumberFormat, DecimalFormat, ChoiceFormat, DateFormat or SimpleDateFormat object), it cannot be shared among threads.

Be first to comment this article
StumbleUponDigg This!Bookmark on Delicious

Add as favourites (54) | Quote this article on your site | Views: 2611 | E-mail

Last Updated ( Tuesday, 12 April 2011 )
Read more...
 
<< Start < Prev 1 2 Next > End >>

Results 1 - 9 of 16
Aminur Rashid