Browse Month: April 2012

Servlet Lifecycle

Hi friends,  in this post we will take an overview of servlet lifecycle.

First of all lets just know what is  servlet?

Servlet is a java program which runs on server side. Servlet interacts with the client via request-response. It is nothing but HTML code embedded into java code.

When any servlet get called container first checks that whether the object of requested servlet is already exists, if not then container instantiates the object and then servlet lifecycle starts with call to init method.

init() – This method gets called only once in lifecycle of the servlet. We can override this method to write the code which we want to execute only once. Object of ServletConfig is passed to this method, which contains the configuration/initialization values stated in web.xml

service() – This method gets called by the container whenever any request comes from the client for that servlet. In this method ServletRequest and ServletResponse objects are passed as arguments to this method. ServletRequest object contains the request from the client.

destroy() – It is called by the server when any servlet is no longer necessary or want to keep the servlet out of service. Container calls this method before removing the object of the servlet.

Thats how servlet lifecycle works.

Happy Coding……..!

How to make an AI Enemy Car in which it follows the track during the Race ?

The AI for enemy car can be done by using waypoints method..

the following code is used

var waypoint : Transform[];

var speed : float =20;

private var currentWaypoint : int;

var loop : boolean = true;

function Awake()


function Update ()

{ if(currentWaypoint < waypoint.Length)

{ var target : Vector3 = waypoint[currentWaypoint].position;

var moveDirection : Vector3 = target-transform.position;

var velocity = rigidbody.velocity;


{ currentWaypoint++;}

else { velocity = moveDirection.normalized * speed;  //velocity = Vector3.forward * speed; }  }

else { if(loop)  {  currentWaypoint=0; }

else   { velocity =; }

} rigidbody.velocity = velocity;



How to move the image on touch in android

image.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
layoutParams1 = (RelativeLayout.LayoutParams) image.getLayoutParams();

case MotionEvent.ACTION_DOWN:

case MotionEvent.ACTION_UP:
x_cord = (int) event.getRawX();
if (x_cord la.getWidth()) {
x_cord= la.getWidth();
if (x_cord <windowwidth-la.getWidth()) {
x_cord =windowwidth-la.getWidth();
layoutParams1.leftMargin = x_cord -(image.getWidth()+0);
image.setPadding(5, 5, 5, 5);

return true;

How to pick music file from music library in iPhone application

Like UIImagePickerView to pick image from image gallery we can also pick up any music file from the music gallery of the device and can use it in our application with the help of MPMediaPickerController.

For that you need to add AVFoundation framework in your application. also to play the picked file we need to add MediaPlayer framework. and to use them just import them in respective view controller. Also in .h file you have to add MPMediaPickerControllerDelegate.

In button click action  write the following

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

picker.delegate = self;

picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController: picker animated: YES];

This will present a controller from where we will be able to access the device’s music library. Also to get the picked file override the delegate method

– (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {

// Dismiss the media item picker.

[self dismissModalViewControllerAnimated: YES];

MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];

NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

[self dismissModalViewControllerAnimated: YES];

// Play the item using MPMusicPlayer

MPMusicPlayerController* appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];

[appMusicPlayer setQueueWithItemCollection:mediaItemCollection];

[appMusicPlayer play];

AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];

AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];

[player play];


Done. Now you can play any music file from device music library into your application.

Happy Coding…..!


Custom Fonts in Blackberry Application

Download the .ttf (True Type Font)file and include it in src folder.

Include this code into the constructor.

EditField edField1 = new EditField (“”, “TestEditField”, 30, EditField.READONLY| EditField.FIELD_VCENTER){
protected void layout(int width, int height)
super.layout(customWidth, customHeight);
setExtent(customWidth, customHeight);

Font fo3 = loadCustomFonts(“digital-7.ttf”, “ThirdFont”, 0, 40);


Include this function.

public Font loadCustomFonts (String path, String fontname,int fontStyle, int fontSize){
InputStream stream = this.getClass().getResourceAsStream(path);
if (FontManager.getInstance().load(stream, fontname,                 FontManager.APPLICATION_FONT) == FontManager.SUCCESS){
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
else {
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
return null;

By Using this we can add custom font into our Application.

thank you.

How to get parameters passed to a URL in salesforce apex

If we pass parameter while creating a page in salesforce apex like this

public PageReference setParameter()


public papageReference ref = new PageReference(‘/apex/print?email=’ + textEmail1);    ref.setRedirect(true);

return ref;


where email is the parameter. Then using the following function we can get the value of the parameter passed

public getParameter()


email = ApexPages.currentPage().getParameters().get(’email’);


Function For returning Multiple values in iphone

Function For returning Multiple values in iphone
– (void)viewDidLoad
[super viewDidLoad];

//Return In Dictionary
NSDictionary *FullName = [Self FullnameDict:@”AAAA,BBBB”];

NSString *FName = [Name objectForKey:@”firstame”];
NSString *LName = [Name objectForKey:@”lastname”];

//Return In Array
NSArray *FullName1 = [Self FullnameArray:@”AAAA,BBBB,CCCC”];

NSString *FName1 = [FullName1 objectAtIndex:0];
NSString *MName1 = [FullName1 objectAtIndex:1];
NSString *LName1 = [FullName1 objectAtIndex:2];

– (NSDictionary *)FullnameDict :(NSString *)responseData;
NSString *FullName = [NSString stringWithFormat:@”%@”,responseData];
NSArray *NameArray = [FullName componentsSeparatedByString:@”,”];

NSString *FName = [NSString stringWithFormat:@”%@”,[NameArray objectAtIndex:0]];
NSString *LName = [NSString stringWithFormat:@”%@”,[NameArray objectAtIndex:1]];

return [NSDictionary dictionaryWithObjectsAndKeys:FName, @”FName”,LName, @”LName”, nil];

– (NSArray *)FullnameArray :(NSString *)responseData;
NSString *FullName = [NSString stringWithFormat:@”%@”,responseData];
NSArray *NameArray = [FullName componentsSeparatedByString:@”,”];

return NameArray;

Conversion of NSString to NSDate and NSDate to NSString


Here is the way to convert NSDate to NSString in objective C

Conversion of NSDate to NSString :

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateFormat:@”yyyy-dd-MMM”];

NSString *dateString = [dateFormat stringFromDate:today];

NSLog(@”date: %@”, dateString);

[dateFormat release];

Note that today should be your NSDate object which you want to convert to NSString.

Conversion from NSString to NSDate :

NSString *dateString = @”01-02-2010″;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@”dd-MM-yyyy”];

NSDate *dateFromString = [[NSDate alloc] init];

dateFromString = [dateFormatter dateFromString:dateString];

[dateFormatter release];

You can set the date format which you want.

So simple…..!!!!!!! Enjoy coding…….!!!!!





Extracting data from Apple iTunes

I tried a lot to find RSS feeds for latest apps getting posted on Apple iTunes store under all categories but couldnt find anywhere, not sure why Apple does not provide such feed.

So I decided to write one of my own and below is how I accomplished the task using curl in php. Through httpfiddler I first out request headers sent by iTunes software and used the same.



function gunzip($zipped) {
$offset = 0;
if (substr($zipped,0,2) == "x1fx8b")
$offset = 2;
if (substr($zipped,$offset,1) == "x08")  {
# file_put_contents("tmp.gz", substr($zipped, $offset - 2));
return gzinflate(substr($zipped, $offset + 8));
return "Unknown Format";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Apple-Tz: 29600',
'X-Apple-Store-Front: 253477,27',
'Accept-Encoding: gzip',
'Accept-Language: en-us, en;q=0.50',

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo gunzip($output);