Technical Tips, Tricks and Articles

Comparing Wrapper objects values in range –128 to 127

leave a comment »

While debugging through a bug that I encountered in one of my ongoing project. I came to know a strange behavior of Java. Consider the following code segment

1 Integer a = 10;
2 Integer b = 10;
3 
4 if (a == b){
5 	System.out.println("Two values are equal");
6 	}

If you look closely at line no 4, then you would realize that the code is actually comparing “Java objects”. Since “a” and “b” are not wrapper classes not primitive types.  But even then the condition is being true. Ok, some how this makes sense (at least till now unless you read this code segment)

1 Integer a = 150;
2 Integer b = 150;
3 
4 if (a == b){
5 	System.out.println("Two values are equal");
6 	}

Astonishingly, for the above code, the if statement would not execute true. Why?

Well, ever since Java has introduced “auto-boxing” feature, you’ll face this issue. Why is it so? Actually, compiler try to optimize things as much it can. For this, Java has a pool of values from –128 to 127. Whenever, there is some auto-boxing between these values, the reference object for the wrapper class will get the same memory location. In both cases, we are comparing “object references” but in first case, since the value was in the range for both objects hence, Java assigned the same reference location to both objects, making the condition “true” on comparing memory location for two objects.

Now, the question is why between –128 to 127?. Well, the smallest range of values for smallest wrapper class is between –128 to 127 i.e. Byte.

Written by ..alee

July 5, 2009 at 1:06 pm

Posted in code, interview, java, programming

Tagged with , ,

How to retrieve MSN Messenger display pictures

leave a comment »

One of my friend asked me that he needs to copy the display picture he had in his MSN Messenger display. He has tried searching but could not located it. Here is some detail about MSN way of storing display pictures.

Please browse to the following path

%userprofile%\Local Settings\Application Data\Microsoft\Messenger

Here you will see folders against each email id that signed in to the msn messenger on that particular machine. Follow the steps to retrieve the display picture.

  • Browse to the desired email id whose DP you want to retrieve
  • Open ObjectStore and then open UserTile folder.
  • You’ll see some files in it with some weird  names ending with either DT2 extension or ID2. (notice the file size of both files. the DT2 will be slightly larger than ID2).

The DT2 is actually that thumbnail of your display picture. You have to open it using any photo viewer software:

  • Right click on the file
  • Select open
  • A pop up will come up asking you to search for the desired program from internet or choose
  • Select on choose and then use any photo editing software
    • For basic users select “windows pictures and fax viewer”
  • Now you can save this picture at your favorite location.

Written by ..alee

July 1, 2009 at 11:07 am

Posted in msn

Tagged with , ,

Syntax highlighting on blogs

leave a comment »

Syntax highlighting is always been a desired things on blogs, specially for those who post their code so often on blogs. Not only it adds to the look of the blog but also, it makes the code more readable.  From quite a few days, i was trying to search for something by which i can paste my codes in formatted highlighted form on the blog, but whatever plug-in i found was not integrateable into wordpress free service.

The earlier solutions that came to my mind was taking a snapshot of the code window and post here. But it includes few extra steps for me (taking a snapshopt, croping it and the uploading it) and for reader, they just can’t COPY-PASTE the code if they want to.

highlightSo if you are one of those who are looking for some syntax highlighting thing for your blog, here is some great tool, named Highlight. The tools come with some default styles, including eclipse, emacs and other well know editors. You can configure the style if you wish so and the you can export it in your desired format i.e (html – with inline CSS, RTF, XHTML, LaTeX, SVG, XML etc).  See the below snippet that I formatted/highlighted using the it. it’s pretty clean and easy to incorporate :)


1 package com.e2e.test;
2 
3 import javax.microedition.lcdui.Alert;
4 import javax.microedition.lcdui.Command;
5 import javax.microedition.lcdui.CommandListener;
6 import javax.microedition.lcdui.Display;
7 import javax.microedition.lcdui.Displayable;
8 import javax.microedition.lcdui.Form;
9 import javax.microedition.lcdui.StringItem;
10 import javax.microedition.lcdui.TextBox;
11 import javax.microedition.midlet.MIDlet;
12 import javax.microedition.midlet.MIDletStateChangeException;
13 
14 public class Test extends MIDlet implements CommandListener, Runnable{
15 
16     private Display mDisplay;
17     private Command mExitCommand, mFindCommand, mCancelCommand;
18 
19     private TextBox mSubmitBox;
20     private Form mProgressForm;
21     private StringItem mProgressString;
22 
23     public Test() {
24         mExitCommand = new Command("Exit", Command.EXIT, 0);
25         mFindCommand = new Command ("Find", Command.SCREEN, 0);
26         mCancelCommand = new Command ("Cancel", Command.CANCEL, 0);
27 
28         mSubmitBox = new TextBox("Test", "", 32, 0);
29         mSubmitBox.addCommand(mExitCommand);
30         mSubmitBox.addCommand(mFindCommand);
31         mSubmitBox.setCommandListener(this);
32 
33         mProgressForm = new Form ("Lookup Progress");
34         mProgressString = new StringItem(null, null);
35         mProgressForm.append(mProgressString);
36     }
37 
38     protected void destroyApp(boolean arg0) throws
39                               MIDletStateChangeException {
40         // TODO Auto-generated method stub
41 
42     }
43 
44     protected void pauseApp() {
45         // TODO Auto-generated method stub
46 
47     }
48 
49     protected void startApp() throws MIDletStateChangeException {
50         mDisplay = Display.getDisplay(this);
51         mDisplay.setCurrent(mSubmitBox);
52     }
53 
54     public void commandAction(Command c, Displayable d) {
55         if (c == mExitCommand){
56             try {
57                 destroyApp(false);
58             } catch (MIDletStateChangeException e) {
59                 System.out.println("exception @ destroyApp(false);");
60             }
61             notifyDestroyed();
62         }
63         else if (c == mFindCommand){
64             mDisplay.setCurrent(mProgressForm);
65             Thread t = new Thread(this);
66             t.start();
67         }
68     }
69 
70     public void run() {
71         String word = mSubmitBox.getString();
72         String definition;
73         try{
74             definition = lookup(word);
75         }
76         catch (Exception ie){
77             Alert report = new Alert("Sorry", "Something went wrong", null,
78                            null);
79             report.setTimeout(Alert.FOREVER);
80             mDisplay.setCurrent(report, mSubmitBox);
81             return;
82         }
83         Alert report = new Alert ("Definition", definition, null, null);
84         report.setTimeout(Alert.FOREVER);
85         mDisplay.setCurrent(report, mSubmitBox);
86 
87     }
88 
89     private String lookup(String word) {
90         if (word.equalsIgnoreCase("1")){
91             throw new RuntimeException("exception thrown");
92         }
93         return "hardcoded definition";
94     }
95 
96 }

Written by ..alee

March 13, 2009 at 9:15 am

Posted in Miscellaneous

Tagged with , , , ,

Postbox – an awesome mail client

with 2 comments

When it comes to email, I am stick to GMail. There is nothing else that i like more than GMail.

But sometime, you just need a desktop application when you are in professional environment. Microsoft Outlook is a big choice, however, i was using Mozilla Thunderbird from quite a while. Which is light weight, have option to subscribe to the newsgroups, global address book. But still there were lot of things missing which i found in postbox.

The software has really nice features, besides having all those features of thunderbird, it has integration with GMail (POP3, IMAP). You can have very easy TODO management, Threaded emails (even for GMail).

One of the really impressing feature of this software is that it manages your attachments, images at one place.

toolbar-image

Clicking on the image button will open a new tab name images. It will index the images of your configured mail account once and then your images will be accessible at one place. Same goes to attachments.

Anyone, who is using Mozilla ThunderBird should try this one. You’ll definitely love it.

Written by ..alee

February 12, 2009 at 4:24 pm

Posted in Application, Review

Error starting eclipse

leave a comment »

You might face an error while starting eclipse on a freshly installed system, or on the system which has undergone a fresh upgrade. The error message will be like

—————————
Eclipse
—————————
JVM terminated. Exit code=-1
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:MaxPermSize=256M
-Djava.class.path=D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
-os win32
-ws win32
-arch x86
-showsplash D:\eclipse-jee-ganymede-win32\eclipse\\plugins\org.eclipse.platform_3.3.100.v200806172000\splash.bmp
-launcher D:\eclipse-jee-ganymede-win32\eclipse\eclipse.exe
-name Eclipse
–launcher.library D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.100.v20080509-1800\eclipse_1114.dll
-startup D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
-framework plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vm C:\Program Files\Java\jre1.6.0\bin\client\jvm.dll
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:MaxPermSize=256M
-Djava.class.path=D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
—————————
OK
—————————

Actually, eclipse is trying to get the version of java that is installed on system. you might have installed that latest one but there are possibilities that any upgradation of later softwares has replaced the java.exe files in system32 folder with older version. All you need to do is to run eclipse with clean parameters. Create a batch file in the directory where eclipse.exe is and write this line in it eclipse -clean -vmargs -Xmx256m

Written by ..alee

January 30, 2009 at 4:11 pm

Posted in java

your own personal code repository

leave a comment »

are you crazy about coding? are you the one who use to write code for others or sometime your written utilities are so good that you actually want to share them and want to release the later versions of it?

If you are one of that guy then this site is really gona rock your coding experience. The site is github social coding .

Here you can make your profile and can create your own repository. For free users, there are limits (100 mb space, no ssl etc). But even then it’s really great to get things started.

Get going coders

Written by ..alee

January 23, 2009 at 4:15 pm

Posted in code website

Manage your TODO with GMail

leave a comment »

I wonder, what was the life before GMail. Gmail was already awesome and day by day it’s getting really great. Today, I am going to write simple tips which will help you to turn your GMail into your TODO Task Manager. Actually, there are 2 ways that i find great and I am going to explain you both.

  1. This tip is going to use 2 GMail Lab (quicklinks and superstars) and ofcourse the google’s legendary search capability. First of all, enable both of these labs by going to your lab settings and selecting Enable against each of the lab. Now, make a decision about any of your favorite superstar for your todo list. I selected red-bang (don’t forget to read their names by hovering your mouse on each superstar in your mail settings > general tab).
    red-bang

    red-bang

    Now, we need to create a quickview so that it may sort out TODO for us. Type this string in GMail search box is:unread AND has:red-bang and add it to quickview and name it TODO. Now all you have to do is to mark all your TODO items with this red-bang star by click on star icon against emails and whenever you want to view your TODO, just click on the TODO linkview from your quickview.

  2. In second method, we are going to use GMail freedom of email aliases. May be you people know that in GMail youremail@gmail.com is same as youremail+anytag@gmail.com. So what we are going to do is to create a filter on TO field i.e; apply label TODO to all those emails whose TO field is youremail+todo@gmail.com. Now, whenever an email has been sent to youremail+todo@gmail.com it’ll be automatically added to your TODO label list.

The benefit of method 2 over method 1 is that you can ask your friends to email at youremail+todo@gmail.com whenever there is something pending on you and GMail will manage it as your TODO list in your inbox.

Written by ..alee

September 17, 2008 at 12:16 pm

Posted in GMail

Tagged with ,

Knol – Google Contender for WikiPedia

leave a comment »

It seems as if Google is following the same path which Microsoft did in Past. History is repeating itself but this time it’s not desktop, software or os market, this time it’s WEB and the company is Google.

Google is either buying each and everything which is making its presence on internet. Few weeks earlier, Google even bid for Digg, though the bid was not successful but Google has tried. It would not be a surprise if Google will launch its own gDigg Beta (Following Google Convetions) in near future. Anyway, Those are things that are yet to happen but now let me share with you the thing that is happening.

It’s
http://knol.google.com/k/knol

Google’s contender for WikiPedia. Since Google has always added nice things in it’s ventures and the convention is being followed over here as well. Up till now i have found 2 decent things in Knol.

  • You can set the permissions who should be able to edit/write the things for particular thing.
  • Every individual is allow to write his own writing for already written article and each article will be rate on the basis of author’s authenticity, history and votes by other users. For example, you might find only one page on WikiPedia on Pakistan but in Knolyou may find multiple page son Pakistan contributed by different authors and you can see which author is more authentic or whatsoever.

It is still in BETA (seems like google naming standard) let’s see when it will be officially launched.

Written by ..alee

August 15, 2008 at 1:53 pm

Posted in Miscellaneous

Tagged with , , ,

GMail Labs – Tips & Review

with 4 comments

Mail is setting the standards of new web mail. The light look, simple design and fast retreival has made other mail boxes to re-design their architecure, look and feel. Now, GMail has added new functionality to it; GMail Labs. The little widgets has added to the functionality of GMail making it even better but right now I am going to write “things that are missing” in these labs.

Quick Links

One of the coolest widget giving the opportunity to add “custom views”. It’s use is simple. Open the view of your choice. Like make a search as label:<your lable> + “any string available for search”. This will result in a mailbox view filtered on specific criteria you mentioned and now you can add the quick link for this specific view. Everytime onward, whenever you click on this quick link you’ll have this view; i.e search reasult based on the query your wrote.

Unread Andriod Quick Link

From the above example, I am creating a quick view based on the following search string label:android is:unread This will result in mailbox view and list all the mails which has label “andriod” and are “unread”.

Thing Missing:

For the users who are having lots of Labels. Its cumbersome to scroll down to the bottom of the page to click on some quick link. It’d be great if GMail Team adds some drag-drop functionality for the panels at the left side.

Written by ..alee

June 19, 2008 at 12:06 pm

Posted in GMail

Tagged with , , , , ,

A new breed to OS – WebSoft

leave a comment »

May be you have read the following article of mine in which i have given an idea about what could be the possible future of Operating Systems and Web. At that time the web was not that much mature compared to today and now that concept has moved one step forward with number of online softwares other that OS so that you don’t need to install things on your system. Here are few

A nice collection of online Office suite – Word processor, SpreadSheet, Calendar, Notebook.

One of the best contender to Google’s online office product and i believe some are really better than what google have developed. Besides those, it is providing online project management and other such features as well.

One of the awesome online web application. If i’d have to rename it i’ll rename it as “Online Photoshop” – yes and i hope you got it what does this application do.

A nice online free tool to build websites without any cumbersome coding. A replacement of early versions of FrontPage and DreamWeaver.

I’ll updating this post regularly with new applications – and don’t forget to share with me :) .

Written by ..alee

June 11, 2008 at 11:40 am