Debugging - Story of String Pools
String pools our friends can at times become out worst enemies. The nightmare story goes like this.
Ramu is a C programmer and he was one fine day asked to write a java program which was never his interest or expertise. Ramu read all the docs he could get on java programming and gave his best to write that java code. It got build and after regression testing, it was approved to be integrated with the mainstream application.
After adding this piece of logic/code to the application, it got tested in one particular application server. Everything went well and the code got released successfully. But the evil bug inside was waiting for it’s chance.
Ramu left the job and somu replaced him. One day suddenly the bug exploded. Somu our hero of the story is pretty good in debugging and tried to trace. He managed to find where the code fails and it was a condition check. This was of course not a logical mistake and much worse no system exception was thrown to stop the program execution.
The problem was that ramu tried to compare two string references rather than the value. But since it’s a String type, the string pool made it chaotic that both the references referred to the same object in spite of immutability. String pool nullifies the mutability issue till the data/value remains unchanged. Because of this String pool, this problem never rose.
The condition was:
ordered = “coffee”
orderServed= “coffee”
Ramu’s Code:
if ( ordered == orderServed)
In this case since both the strings are same, the reference matching worked(string pools to the rescue). But what happens when string pools are disabled. There are two instances (immutable of course).
The right code (non C-style comparison) would be to compare the actual values and not the addresses.
Somu’s code correction:
if ( ordered.equalsIgnoreCase(orderServed) ) // or equals()
Finally it was a happy ending. Even though this was a blunder, the program logically did well as it was intended.
1 comment August 8, 2008
A simple class in Javascript
//Lets try to make a Dog class
function Dog(name,age,family,address)
{
this.name=name;
this.age=age;
this.family=family;
this.address=address;
}
// Lets have a method
function details()
{
alert(this.name+’ age ‘+this.age+’ is of type ‘+(this.family)+’ + ‘lives at ‘ + address);
}
// Associate the methos to the class Dog prototype
Dog.prototype.details=details;
// Make a reference
dog1=new House(’johnny’,4,’beagle’,'no.1, walkers street’);
// Make the method call
dog1.view();
Add comment July 18, 2008
google watch
Few of my personal Favorites.
1. Who thought that gmail will get a big welcome and user space in the world wide web email service usage. The simple user interface and elegance in look and feel is definitely to be appreciated. In those days, we had to get invite from a friend to get a new gmail account which was in it’s beta stages. It’s never like yahoo where you can get a free account just like that. But still this approach was widely welcome and people felt the seriousness of using an email account.
2. The ajax technology was brilliantly consumed with the idea of maps. I could see even now many services making use of google maps. Gpedometer is one cool application everyone must try.
3. Orkut made a huge impact on social networking business. Now every Ram, Rahim and albert uses this networking service. Another big impact. How people use the service is another issue. But it’s one stop place for all friends meet and share.
4. Brought in a great deal of integration with a single signon mechanism. I like it when i could open that .rtf file in google docs even in my machine with no office suite installed. I also use zoho at times. But prefer google docs.
5. Google docs is my favorite application and it’s got much more potential and future. I would even afford dollars of subscription if it can maintain my documents online (time when i become operating system free). Google gears is another interesting story to make impact in the world of off line working. It’s really worth giving it a try. It’s in beta stages i guess.
6. Not to forget, the revolution it made in the web search. And it’s pretty well supported by Firefox web browser too with a ready made default search box. I guess they fund the project more than any other company. But of course we can always choose to use a different search engine at our own will. Still google tops there too.
7. My latest interest is the GWT. I am quite positive about it. But still it’s very early to say how it impact the client side industry. There are hell a lot of competitors trying to bring in that layer of browser independence. I have always been reluctant to using such layers of programming tools and comfortable writing raw javascript code on my own. But who knows, i may have to work on such a technology some day.
8. Blogger is one thing which i am not much impressed since i could not find new features like i find in wordpress. But still i use it because i get a theme which suits my blogs.
Add comment July 9, 2008
Good bye Gates doesnt mean ….. but
Bye Bye gates doesn’t mean end to proprietary software but his walls remain very solid and closed !! An article on BBC by Richard M Stallman Founder, Free Software Foundation.
Since i grew using GNU/Linux system(from my college days when i first started using computers), i did not have much attachment to the Microsoft windowing system neither Mr.Gates.
But there are lot of other restrictions that the company brought in for the user accessing the PC installed Microsoft Windows. If you are in USA then it’s pretty serious and you can never get away unless you switch to. The evils of patents and proprietary document are there still a battle to be fought. So it’s pretty unfair to just put the blame on Gates alone.
The empire of proprietary software is there to live long and so does the open architectures and tools supporting open standards. Can we call it as “coexist in totally isolated world”.
It’s really funny to see the company making their own way of doing things centered around the banner. Openxml is one such thing. But thankfully it’s not accepted as a standard because of it’s complex documentation detailing the standards and other peculiarities. ODT has a good community backup. But this war is there to continue for a long time though. And there are many similar bed time stories like this.
One day i wish to use operating system just as a minimal platform to run applications. And this would be very much possible when the world of web gains more potential and improvements. Then i would definitely say bye bye to Mr.Gates. I guess players like google can bring in such environments for users to concentrate only on their business and not worry about the operating system much. GoS is one such attempt.
In future you could have your documents online and forget about bulky hard disks. The world of web browsers have lot to offer to the user. It’s good that now people are very comfortable trading the documents in web.
Eek, i tend to move away from the topic i write. But honestly there is nothing to talk about Mr.Gates bye bye scene because we have a bigger wall to manage.
I am really interested to read about him and the charity works he does tough.
1 comment July 8, 2008
Future in pocket
It’s very obvious that the world i going to see and use lot of mobile apps very soon. What we see now as a web is about to experience a major drift. All web protocols are going to be clubbed together and made to work on mix. I am sure HTTP is there to live long. The mobile application will have to be more web centric and be very specific for it’s purpose.
I am really impressed by SMS 2.0 which i use in my N72 for sending and receiving color messages and it has got a beautiful interface for reading news side by side. XHTML is another ground breaking solution to the structuring of displays in web browsers in mobile. I could see many articles being published on mobile market in recent years. One interesting thing is that there i no one right way to make applications because no one knows exactly what to do with it till date except few internet applications.
What does flex, flash, xhtml are to offer the user interface richness ?
Almost all software vendors are eying the market inclusing Microsost and SUN. Big players support and fund lot of startups too. Is this a right market for free software to make money for the service ? That looks like a very bright chance !! Already lot of free software solutions creeping up!!
2 comments July 4, 2008
