Sunday, December 21, 2008

The day we started to cook...

After lots of discussion and thoughts we finally decided to start cooking at home (bangalore). What is supposed to be the cleanest place in the house is where we dump everything. Dirty clothes' bag, dust bin, everyday news papers, water bottles, shuttle rackets, bunch of tooth brushes, tooth pastes and what not.. Since we have decided to cook and I am the one who wanted to do it the most, it was my responsibility to clean the kitchen. Ah.. friday evening, But I had to clean, since we have booked for a new gas connection, which can arrive any time.  

While I was doing the kitchen, I heard the calling bell. I was so immersed in cleaning that I didn't bother about it. After a few seconds another ring came through. I dropped the brumstick and then cleaned my hands with the near by newspaper and then eagerly opened the door. A guy was standing with the gas cylinder. I asked him to keep the cylinder in the kitched where we kept our dirty clothes bag before. He, then assembled the new Pigeon gas stove which was kept unused in the closet for more than a year. We were pretty excited about our first cooking experiment. 

He fired the gas stove and the stove flamed with bright blue light. My nose smelled odor of gas and I turned around to find the exhaust fan switch (yeah.. I had to find it, since we never have to turn it before!)  and turned it on, after few minutes it was better. I paid him 2550 rupees for the new gas connection and sighed him good bye. 

We have already decided what to cook today. I shut down the gas burner and them marched to a new by shop for buying cooking stuffs. We got a new packet of atta for chapathi and once we reached home we realized, we did not have chapathi roller for preparing chapathi's :) We felt stupid, but we immediately changed our plan to Dosa. So I  ran and got a packet of batter for Dosa. 

The first one was a big flop, it didn't come out properly.  I tried the second and to our suprise it was pretty good. We were encouraged by this good dosa and started the next one.. Finally we used all the batter and had a happy meal.  We then discussed about tomorrow's lunch plan. Its a week end, so we have some time to kill and hence we planned for a big menu :)

And today's lunch was also good! Not good really, but better than what we thought!! After the good meal comes the tough part of cleaning it, but we have to sacrifice something to get something..

Friday, December 12, 2008

Do you know Benny Lava???

I stumpledupon a blog about Benny Lava.. Benny Lava is the name given to an Indian actor by a bunch of western fans(really fans??!).. So just read the blog little more and came to know that Benny Lava aka Prabhu deva..

Buffalax, a youtube user, added english subtitles to a Tamil song.. subtitles based on what he heard and it's not a translation.. And it became a hit in youtube with more than 9,835,326 views.. sounds funny ah..! Take a break from your days work.. watch it here..


Tuesday, December 09, 2008

Nobody escapes from this economy crisis!!

Its all well few months back.. everybody is happy in Cisco with good pay hikes.. but that happiness didn't last long.. (Nooo they didn't rollback the hike by the way!!) Cisco is always projected as company which can handle economy down turn with ease.. Even in 2001 Cisco managed very well and Cisco sees these economy down turn as an opportunity to come out well, where as our competitors with many in-house problems are having tough time battling them and not to say about economy slow-down..

But this time even Cisco is not spared.. Spree of cost cutting measure were taken out across all cisco location and one of them is to force the employee to take leave this christmas and new year.. Company will be shut down for around 10 days and Cisco saves considerable amount of money..

In one way it is good to take leave, but people are worried where this will lead us to...
Everybody is hoping that Cisco will come back well.. With the foresight of our senior leadership, (standard slogan in every cisco meeting!!) we will fight back well.. Hopefully!!

Thursday, November 27, 2008

silly string problem!

Today is no different in office. We are nearing the release and test team is chucking out bugs tirelessly. Every day we have more bugs to fix :( As usual i started to work on with a high severity bug. I found the cause without any problem.

But then came a surprise to me. We have a function which takes an array and returns the index of any object you are looking for. So we have an array with few entries and search for an string which is there in the array. But the returned -1 (not found).

I am surprised and puzzled. One things i did was to replace the == with equals method and it worked well. But what I am not clear is why == didn't work. Since string is immutable any string object which has same data will be interned to the same reference in the string pool.

Then I searched on google and found that if any one of the string is read from file, then it is not interned.

consider the following code:
public class Test {

/**
* @param args
*/
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("c:\\test.txt"));

String str = reader.readLine();
str = str.trim();
String str2 = "A";
System.out.println(str==str2);

reader.close();
}

public final static int indexOf(T[] array, T t) {
for(int i = 0;i
if(array[i]==(t)) {
return i;
}
}
return -1;
}

}

content of the file is just "A", what do you expect the program to print? true? you are wrong.. answer is false. This is where we have to use the intern function in the string class.

Hope somebody will find it useful!!

Monday, November 17, 2008

Wonders with Wii Remote

After iPhone's multi-touch screen and Microsoft's surface, touch-interaction with computer has taken a new avatar. Every other day new video about these technology popup on youtube.

Take a look at the second light multi-touch screen

And today i stumpled upon a TED video about using Wii to create interactive screen. I am particularly excited about the idea of using infra-red to find you visual line of sight. EA is planning to use it in its game.. excited ah!! Take a look!!

Monday, November 03, 2008

The "SHIT" effect

Last Saturday I wrote my TOEFL. To me English was a night-mare in school days (still to some extent). Some how i managed to improve my stance at English little bit, but far from being perfect still.. I crossed GRE successfully, where luck played an important role and people said TOEFL is just a piece of cake (in fact it is), but i am obsessed with the speaking exercise. But i was confident to do it (after 2 years of being YASE, I have taken few presentation in front of 5 to 10 people).

Finally the day came. Reading and listening was a breeze. And then came the toughest part (at least for me), speaking. Trying to calm myself and after adjusting my head phone couple of time, the screen read.

"Describe the city you live in"

So i explained about Bangalore and it did go pretty well.. Ok, I am going to cross this, I said to myself. Then came the actual test. I read the question and mentally prepared my answer. Figuring out the first few sentences I am going to speak (sometimes I still have to form the sentence in Tamil and translate it!). I have 15 seconds to prepare and 45 seconds to speak about the question. After 15 seconds, I started with my answer. I started with few trembling words and gained stability in few seconds. Ah.. I am speaking alright i said to myself.

And then came the most embarrassing moment to me.. Before I could conclud my speaking, I ran out of time,. Two seconds before the clock ceases, it will show you a pop-up saying "Stop Speaking". I too got this pop-up at the end. I don't know what I did, still I couldn't believe it. Out of reflex, unknowingly without my knowledge I said "SHIT" into the microphone and it got recorded!!! What it did I just say? Oh my god, I am screwed. I got tensed. Not knowing what to do. I looked around to see if somebody is there near by, so that I can explain what happened. Nobody is there. I felt too bad, at the same time I wanted to roll-down and laugh for what I did!! then came the next speaking exercise, which I some how managed.. And the remaining exercise didn't go that well !! Any how we can't change the past, atleast I hope they wont ban me from future test :) At least if i would have said "The Magic Four Letter Word", they would have thought I am an American!!! LOL!!!

I know this is not fun, but unfortunately people enjoyed it.. So I am putting it in my blog :) After all life is about FUN!!

Cheer and Keep laughing,
BY "THE ONE WHO SAID 'SHIT' IN TOEFL"

Wednesday, October 22, 2008

Chandrayaan off to space -- what it is to India??

Finally Chandrayaan took off to moon, the place humans landed some 50 years ago and we are sending a box (ofcourse with some equipments inside) with our national flag now.. But it's never too late.. and it is a great achievement. Only few countries in this world were able to do that. But this is just my feeling. It is not always about us and it is about how people around the world looks at India.

After reading ezhil's blog, I started to see what international audience think about india. When i say international i have two countries in my mind, USA and China. So i started to read few news channel sites in USA and CCTV english of china.

Comments in ABC news are interesting. People having mixed feeling towards india.
CCTV doesn't even mention about this event, instead there is a news about a bomb blast in India!!

We have sent a satellite to moon after 50 years humans landed there. So what is good about it? Does ISRO work the same way like any other government organization works? But sending a satellite to moon shows what a nation is capable of. So I personally feel happy about this. But sending this satellite, are we going to salvage millions of poor Indian citizens? the answer is straight no.. are we going to find something new about moon.. again the answer is straight no.. but it does serves a purpose. By sending satellite to space, we prove our capability in rocket science and space business is a lucrative business. Countries earn tons for carrying other countries' satellite, which cannot afford it's own launch vehicle.

Chandrayaan is good sign of India's progress and i am happy about it..

Friday, October 17, 2008

Google Chrome Vs Yoga

NO, its not a post about how good Google chrome is?? But how one can use the recent events to advertise.. What a crazy idea to related yoga with Google chrome..

The most geeky way to advertise, isn't it??


Friday, October 10, 2008

The rainbow day!!!



Today climate in bangalore is amazing.. After long days of sun and no rain (yes even in bangalore!) clouds have opened up today, unfortunately today some cricket match is going on in bangalore and who bothers! Friday, we usually get free fruits from cisco. So as usual we went to the cafeteria to get some fruits. Some cricket match was going on, so i have to sit there with my friends watching cricket :( for few minutes.. And it started to breeze outside and few minutes later it started to drizzle. So i have to pull my friends to go out to get some fresh air. so we all went out and we are standing on the 8th floor of our building. The same floor we go everyday looked more beautiful. The wind became so strong, that it dashed couple of chairs. A plate with noodles was blown away :)


And we saw a beautiful rainbow on the sky. It is looked so amazing. We spent some time there till it started to rain and now I am back on my seat writing this blog :) and planning for this week end.. (loads of movie to see and this is what i am doing for my toefl! LOL!!)

Wednesday, October 01, 2008

Google @ 2001

For google's 10th anniversary, engineers at google have given us a time machine, which let us search the web as it was in 2001.. They have just put back the oldest web index they have. Whatever you try to search, google will search the web as it was in 2001 :)

So searching iPod, iPhone will give you strange results :)

Try it out here

Have Fun!!

PS: All the site may not open, since those pages listed by google may not exist now..

Wednesday, September 03, 2008

Google Chrome - Next Generation browser

Now the browser war is getting tougher with the introduction of Google Chrome, a brand new browser released by google without much hype. But why did google created another browser? Google is clearly heading in a way where it wants every god damn thing to be online and with it's own browser Google can surely redefine web application.

Following are the interesting or innovative ideas by google:

1. Tabbed user interface. Ok.. Firefox had it for eons and IE7 has that now, so is opera.. What's new in google chrome tabs. But google tabs are different. In all other browsers all tabs share same process space, that means they run inside the same process, where as in google chrome each tab is a separate process.. When I first read that, i was thinking "That doesn't really sound like a good idea", after all separate process for each tab is resource crunching. But google gave a really nice explanation and advantages of having separate tabs as separate process. With separate tabs as separate process you can regain any memory lost (due to memory leaks or what ever) by just closing the tab, OS will kill the entire process, reclaiming the memory. Ok.. sounds good! But what about sharing resource etc., god knows how google does that.. 
Now-a-days we are running more critical application in browser like online shopping, booking tickets etc., Should n't browser be stable? With separate tabs as separate process, whatever happens only that tab will be affected, remaining tab will remain!! Sounds Interesting!!

Now some experiment: Run chrome and launch few tabs. If you see task manager, you can see separate chrome processes. End Taks any one of them and navigate through the tabs. In any one of the tab you will see a "Sad Smiley" and the process you killed is associated with that tab.

2. VM for Javascript. Chrome runs a VM for javascript called V8.  Faster, efficient and safe.

3. Empty Tab : Google chrome maintains the list of sites that the user visit frequently. So when you open a new tab instead of just opening the home page or some stupid page, chrome will show you the list of frequently visited pages. Cool! Nice idea!!

4. Need not say about UI, Google is an expert in HCI. But I was shocked since I was not able to find any menu bar???! 

5. Similar to fire bug, chrome has an inbuilt javascript debugger. Nice!

6. Incognito Window - What ever you do in this window will not be saved anywhere(yes, even cookies)! So use incognito window if you are going into a porn site!! lol!! Guess IE8 has a feature similar to this.

Certainly looks good! Google has invested lot of time and brain into developing chrome. So certainly it is going to be good product from google.

Look here for more information.

Few statistics - comparison between chrome and IE6
-----------------------------------------------------

Tabs : 2
Process Mem Threads
IE         38512 24
chrome's         63344 32



Tabs : 10
Process Mem Threads
IE         52844 57
chrome's         161068 39

But google chrome for sure eats up more memory and resource! with the above statistics it is very clear!!

These are some obvious things one can see using chrome for few minute. More interesting stuffs later. 

Has anybody used IE8? I totally lost interest on IE - I use it only for some application i use at work! 

Other browsers watch out for Chrome!!!

More on chrome to follow!!

Monday, August 04, 2008

K7 Computing - A company with a difference

I some how happened read about this not so heard company "K7 Computing" right here in Chennai. I was very much impressed with the way they offered their openings! Definitely different and cool!

See : http://www.k7computing.com/careers.asp

Thursday, July 31, 2008

Thread Local

Thread local is the concept of storing data which is specific to the thread. For example member variables are specific to instance, thread local variables are specific to Thread.

The IBM's page outlines exactly how it works..

This is definitely good way to do thread related transactions where in each thread denotes on transaction or session. Caling the get method on the thread local will return value based on the thread from which the method is called.

An example:

public class ThreadLocalTest {

static class CountdownThread extends Thread {
public static final ThreadLocal local = new ThreadLocal();
private int start;

public CountdownThread(int s) {
start= s;
}

public void run() {
init();
while(true) {
System.out.println(local.get());
int i = local.get();
local.set(--i);
if(i==0) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

public void init() {
local.set(start);
}
}

public static void main(String[] args) {
CountdownThread t1 = new CountdownThread(10);
CountdownThread t2 = new CountdownThread(5);
t1.start();
t2.start();

}
}


Output:

10
5
4
9
3
8
2
7
1
6
5
4
3
2
1

I wonder how come I didn't hear about this for long time!!!

Happy coding!!

Wednesday, July 23, 2008

Open source licenses...

Open source has been the buzz word for sometime.. Whether you like it or not, we have to use open source products in our business today and so do we in our company. If we don't have a proper understanding of different open source licenses, you may put your company/product into trouble. So all software developers have to take this training and this training was very useful and informative. So here is what I learnt from it...
  • Open source and free/shareware are completely different. They are NOT same.
  • Open source coined by FSF (free software foundation), refers to sharing of source code.
Various open source licenses:

GPL: GPL stands for General Public License and it is most popular license in open source community. If you use a software which is GPL licenses in your code, you just have to share your code as well as whatever improved you do to the GPL license code. There are various versions of GPL, GPL 3.0 being the latest and most stricter of all.. If you use GPL code in your job, we really have to be careful!

MPL: Mozilla public license. It is less stricter than GPL, but more stricter than BSD. If is also called "Patent peace" license. This license strongly discourages patent infringement fights between parties

EPL : Eclipse public license. Less stricter than MPL and very business friendly open source license. If you proprietary codes just uses the API/libraries provided by EPL license, you don't have to disclose you proprietary source code! Good to do business, isn't it!!

CPL: Common public license. Created by IBM and also used by Microsoft. This license permits you to enhance a CPL licensed code and release the binaries for stricter license. Another big difference is that, contributors cannot be anonymous. they must identify themselves.

CDDL: Very similar to CPL

MIT License: Permissive license. You can do whatever you want with the source code, as long as you distribute the MIT license with your code.

BSD: Very similar to MIT license

Another important things is also related to how you use the 3rd party libraries. For example, if you use 3rd party libraries through sockets, pipes it is different from directly calling the API proprietary code, and this was a suprise to me!!

Treat the above as just an information. Please verify and read each individuals license if you need exact information.

Monday, June 23, 2008

Silly mistakes!

Though Java relieves you from memory management, it doesn't mean that you don't have any memory leaks. Certain things which we use typically in our day to day coding which causes memory over usages and inefficient codes.

Tip1:
for example String s = "hi" or String s = new String("hi"); which of these 2 is good. I am voting for the first one, not just because if offers me to type less, but also more efficient. But why?

When you use new String() you unnecessary create explicit copy of the string (This makes sense only if you know what string pools are and why string is immutable?)

Tip2:
Looping though are basic constructs of any programming languages, we need to be little care full about using them. for example, java provides iterator for iterating collection.
Ex: we have linked list, it can be iterated through iterator or using get(i) function. But if you remember how linked list are implements you will realize why using get(i) is extremely inefficient.

Paying little attention while coding makes you code better.. I am still trying to learn it myself..!

Thursday, June 19, 2008

XNA Game Studio - wow!!

When it comes to development, nobody can beat the solution and tools Microsoft provides. Recently I came to know about XNA Creator studio, which acts as a plugin in C# IDE for creating games for xbox or window. The podcast on it looks really impressive. For sure this offers a great deal for creating games.

Video : http://creators.xna.com/en-US/create_detail

For hobby game developers like me this is really wonderful.. Kudos to Microsoft!!

Let's Game!

Friday, June 06, 2008

Java. Is it dying...?

This is the first time I am reading that JavaOne is not good (2008).. So I just read along many other blogs and there are many blogs related to the end of java.. I asked to myself "Is java going to die?" and heard back a sound response.. No way! atleast anytime sooner.. I read a blog in which the author says that Java is not going to die anytime sooners and he gave some number on job requirement based on Dice.com and impressively Java is way to high than anything else. Almost twice the next language C++, Ruby and Phyton not even 10%..

As many are blaming about how bad Generic are in Java, but still I feel java is a better language to code on.. Another blog says "Your top biz guys doesn't mind what language you use.. they wants the things to be done easier, faster and better.. and many new languages like Ruby (not really new!) were much simpler and less verbose.. But still Java is very widely used and millions of people know it (though not properly!) Java is going to be there and Sun is doing great job in enhancing Java each version and adding new features to it...

So I feel Java is going to be there for some time and there is enough time to learn any new language that might get be popular!!!

So chill out..!!

Some blogs to read..

google killing java,
Another one

Tuesday, May 27, 2008

Forgot my id...!

Today happened something that is really funny.. as usual I woke up very late and I have to rush to office. As a saying says "haste makes waste", I forgot to carry my office ID card. But it's ok not a big deal I can just get a temporary id card for the day...

So I went straight to the receptionist and our conversation goes as follows:

Me: excuse me... ah.. (starting problem) I forgot my id card..
Receptionist: Cisco ID ?? (with tone of a question)
Me: Yes
Receptionist: Cisco IIDD?? (with a tone of question, but with little more stress!)
Me: yeah.. yeah..
giving out a big exhale ...
Receptionist: CISCO IIDD?? (now with irritation)
Me: yes
I thought she is asking whether I forgot my cisco id.. !! :)
Receptionist: ah.. (wishing to slap me!!) WHAT IS YOUR CISCO ID NUMBER?
Me: (With a really stupid smile) oh cisco id number.. 2 ah.. 3 ah. x x x x x x

and she gave me a temporary id card and I got it with a insane smile.. :)

and my day goes on well!!!

Wednesday, May 21, 2008

Netbeans 6.1

Netbeans 6.1 is really cool and it has really improved a lot. Certainly main add-on which comes prepackaged makes Netbeans 6.1 a really cool IDE. When I tried to get JSF plugin installed for Eclipse 3.3 I really have to spend lot of time figuring out the right plugin and right version. I really got tired to doing it, so I tried Netbeans 6.1. To my suprise its really easy to do it in NB.

Also the new javascript support for netbeans is awesome. Take a look @ Netbeans TV

But still there are certain features that are missing in Netbeans which makes me stick to eclipse. But surely I will use Netbeans more in the future!

Tuesday, February 19, 2008

Windows Embedded. Can it stand against Unix based RTOS?

I thought Unix is something that is being used in Embedded system and windows have no part in it, though I know that there is something called Windows CE (Consumer Electronics) which typically used in PDAs and smart phones. Now next version of windows CE has been released and it is called Windows Embedded. There are 3 different editions of windows Embedded.






Guess in the future Networking devices may use Windows as their RTOS. But I'm sure that Microsoft will do great job is easing the development using Windows Embedded which is some what complicated, but performance-wise time only will answer!! If you have worked in Networking domain, you might be aware that IXIA traffic generator uses Windows as it's operating system.

With these releases it is very clear that Microsoft is more interested towards mobile computing and consumer electronics and recent acquistion of Danger Inc., mobile company confirms that!!

Don't wonder if something like M-Phone is being released by Microsoft.

Sunday, January 27, 2008

Windows Work Environment Tip

If you are using windows as your working environment, it is obvious that you want to open some files in Notepad, though you don't want to open it in Notepad by default. Adding context senstive menu when you right click on a file or folder is pretty simple.

Follow these eight simple instructions to learn about how to do it. Yes, this requires editing Registry, so be becareful.

http://everything2.com/index.pl?node_id=996222

Java 2007 a look !!!

Read through some blog and came to know that Function types and closure are being added to Java standard api and syntax. It never came to my suprise.. that's because I didn't know what function types and closures are? But after reading it, I came to know that I have used function closures without knowing what they are.. It is very common in ActionScripts and Javascript.

Function type are similar to Pointer functions in C/C++. They are special data types for holding reference to functions. So know you can even have local functions. We can use other variables visible in the scope inside the function.

Monday, January 21, 2008

How many to learn?!?!

As a famous saying says "Too much of anything is not good!!", this truly applies to Java Web development frameworks. There are very many frameworks and following are some of the terms you will always find in Java Resumes:

"Java, Struts, Sprint MVC, Ant, Hibernate"

I am not expert at even any one of these. Not even struts!! So if I want to learn something it is spending my worthful time and I should get enough returns on my time! So just made a research online to see how the trends of Java Web development framework varies.

The following are some of the frameworks compared:

I cannot put most of the details/statistics here as information provided is copy righted. So you can read them here.

Certainly JSF seems to be in leading position in terms of Job creation and demand. So guess it's worth learning!!!

Happy learning!!

Looking at C# wearing Java Glass?

I always loved Microsoft products whether it is there operating system or any software development tool. The computer that I first used had windows 95 and from that Windows has always been my favorite operating system. So I have spent lot of time developing small projects only on windows (and till now!). By the time we studied Visual Basic and Java in our high school, I always loved VB, cursing Java for not having any IDE (atleast my teacher didn't introduce any Java IDE to us. But it is there at that time!). Most of the time we have to memorize the syntax of Java, where we do VB just like that. Java lab is always a big problem!! I hated Java to the core!!

But my career made me work on Java and I came to know lot of professional IDEs (eclipse) available for Java which are far better than Visual Basic IDEs. I still love Eclipse IDE more than Microsoft Visual C# express edition 2008 (never had a look at professional version though). As a fan of Microsoft, I thought to take a look at C# from the perspective of Java.

Sure C# had lots and lot of language structs and keyword to code on. But how frequently are they used? I really don't understand the reason for having a struct as well as class. But C# have the concept of Managed Pointers and also allows free pointer manipulating is allowed which is something cool! But I really don't want or expect Java to have those features. I am fine with what Java already has. But still I am learning C# is going to be fun!!!!

Happy coding!

Wednesday, January 16, 2008

finding a good programmer !!!

Please follow this link.

The author explains how to find and recruit a good programmer. I am sure this will be important to us as well when we prepare our resume..!!! After reading that I definitely seem to be a good programmer not considering the fact that the author wrote a raycast engine at 14 (I started programming at 18!)

Good bye!

Monday, January 14, 2008

Flat Button using swing

I always wonder about how people creating such a nice button and swing controls in swing. Swing provides the most customizable user interface. Though I am not expert in it, just tried myself to do something that will give me a better understanding of how all these things fit together.

All the components in swings are rendered by ComponentUI, so a component delegates the painting job to ComponentUI. For example, a JButton will be a rendered by BasicButtonUI (not exactly!). So ComponentUI which renders a component is decided based on the LAF (look & feel) selected. So to create a new look, you just create ComponentUI for all the swing components.

windows look and feel for JButton is provided by WindowsButtonUI.

When I first read, this I thought it's bit difficult to understand, actually it's pretty easy to understand. So I tried to create a Flat Button (you can think of them as buttons that appear on toolbar in standard Microsoft Office App.).

To create your own UI for Button, we start by extending MetalButtonUI, by just overriding some painting function, we can create customized LAF for the Button.

The picture below shows the button that I tried to implement.

Java code below shows how it is done:

public class JFlatButton extends JButton
{

protected PaintProperties paintProp;

public JFlatButton(String text)
{
super(text);
}

public JFlatButton(Action action) {
super(action);
}

public JFlatButton(Icon icon) {
super(icon);
}

public JFlatButton(String text,Icon icon) {
super(text,icon);
}

public void setUI(ButtonUI ui) {
// defaults
if(paintProp==null) {
paintProp = new PaintProperties();
paintProp.borderColor = Color.BLACK;
paintProp.rollOver1 = Color.WHITE;
paintProp.rollOver2 = Color.LIGHT_GRAY;

paintProp.pressed1 = paintProp.rollOver2;
paintProp.pressed2 = paintProp.rollOver1;
}
// override the UI
// always set our UI instead of platform based LAF!
super.setUI(new MetalButtonUI() {
protected void paintButtonPressed(Graphics g, AbstractButton b) {
// if back group paint required
if ( b.isContentAreaFilled() ) {
Dimension size = b.getSize();
Graphics2D g2d = (Graphics2D) g;

Paint paint = g2d.getPaint(); // save to restore

GradientPaint pt = new GradientPaint(new Point2D.Float(0,0),paintProp.pressed1,new Point2D.Float(0,b.getHeight()),paintProp.pressed2);
g2d.setPaint(pt);
g.fillRect(0, 0, size.width, size.height);

g.setColor(paintProp.borderColor);
g.drawRect(0,0,size.width-1,size.height-1);

g2d.setPaint(paint);
}
}

public void update(Graphics g, JComponent c) {
// under normal condition, don't render the background
// on roll over render my custom color
if(model.isRollover()) {
drawBG(g,c);
}
paint(g, c);
}

protected void drawBG(Graphics g,JComponent b) {
Graphics2D g2d = (Graphics2D) g;
Paint paint = g2d.getPaint(); // save to restore
GradientPaint pt = new GradientPaint(new Point2D.Float(0,0),paintProp.rollOver1,new Point2D.Float(0,b.getHeight()),paintProp.rollOver2);
g2d.setPaint(pt);
// fill button
g.fillRect(0,0,b.getWidth()-1,b.getHeight()-1);

// draw border line
g.setColor(paintProp.borderColor);
g.drawRect(0,0,b.getWidth()-1,b.getHeight()-1);

g2d.setPaint(paint); // restore
}

protected void paintFocus(Graphics g, AbstractButton b,
Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
// nothing, focus not rendered!
}
});
// override some properties
this.setBorderPainted(false);
this.setOpaque(false);
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
}

public PaintProperties getPaintProp() {
return paintProp;
}

public void setPaintProp(PaintProperties paintProp) {
this.paintProp = paintProp;
}
}

Code is self explanatory and sufficiently commented. (I don't understand some code, I will always sun's similar implementation. They are commented well! really well!!!)

After reading about this and implementing something with what I learned, really helped me to understand it clearly.

Here you can find something similar to this but with JTabbedPane .. Really good resource..

Happy swinging!!

Saturday, January 12, 2008

Permutation generator !!!!

Unintentionally I visited this site and I felt cool, so thought of sharing (or keeping it for me to use later)!! Never thought generating permutation is so easy and they say this is the fastest permutation generating algorithm.. when algorithms get efficient, always coding gets tougher.. but not this time.. Though I didn't try to write it in any programming language, but the algorithms itself looks pretty simple(especially if i do it JAVA)

Let try to find the complexity of it..

To find the permutation of 'n', it needs to know the permutation of 'n-1', which in turn needs 'n-2'
Once we have n-1 permutation for 'n', we need to duplicate each entry 'n' times and then weave 'n'.
so totally it takes 2n assuming we already know 'n-1'

for n-1 it will take 2(n-1)...

so for n : 2n + 2(n-1) + 2(n-2) + ... 2 = 2(n+n-1+...1) = 2n(n+1)/2 = n(n+1) = O(n^2).. is it right? I think so!!!

Happy analyzing !!!

Monday, January 07, 2008

Turning back @ C++ after very very long time...

After very long time, recently I tried to refresh my C++ skills. Though I never mastered C++ I have done some considerable amount of work. This includes 3D snake game using Direct X (Those good old days in college when I had lot of spare time to do these stuffs even wasting considerable amount of time !!!). I am a visual C++ beginner at that time. (no I am not a expert now.. now I don't know Visual C++ at all!) I downloaded Visual C++ express edition 2008, download was pretty fast despite downloaded file is some couple of 100 MB. Installed it and just opened it. Look and feel is really good, but started little slow (could be because of reading the feeds from Microsoft site to show on the start up page).

I created a new windows form application. I was expecting some huge code generation like MFC, but not. I tried to open the source code and found a following piece of code.

// Test.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace Test;

[STAThreadAttribute] // <-- What is this? - 1
int main(array ^args) // <--- looks like a smiley - 2
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1()); // gcnew ! gcnew - garbage Collector ! - 3
return 0;
}

I couldn't even understand syntactically some 3 lines.

1. Guess it could be annotation (I was working in Java for sometime)
2. Template based collection classes (Java generics equivalent)
3. gcnew - garbage collector - wow! garbage collector in Visual C++, cool!!!

These are my assumption, I will try to explore it a little more after sometime.. I felt definitely I need some exploration to understand these things. Let us see what I am upto!!!

Happy coding!

Thursday, January 03, 2008

Strange Connection - Java with Assembly language

It might be surprising to know that it is possible to call assembly code directly from Java, even though Java doesn't even give you the freedom (rather problem) of handling pointers. (Don't say all native are assembly code after all!). It was reading this blog. I never done any JNI as such and but have some understanding of how it works. After reading this I felt like I never understood JNI completely. To understand this article to some extends you need good understanding of Java, JNI, Assembly language programming. Though I am unable to completely the follow the Assembly code, it gave me a fairly good idea about how it works. Really great article. In a similar article the author also explains about calling Java program from Assembly.. Sick !!!

Happy Coding!

Wednesday, January 02, 2008

Feel free write a buggy code...

Reading through this blog and I was amazed to see how even the most experienced programmer makes simple mistake. This blog shows that Sun's implementation of Binary search which had a bug and it was undiscovered for some 9 years..! Though this is a extreme case (binary search fails if the array contains some billion elements.. :) ), it is still a bug..!

So don't feel bad if your code has some bugs..! Just chill out!!!!

Do you love your code?

Every programmer feels happy and satisfied once he completes his project and same with me as well. I was reading through this blog and I learned we should not love our code. If you love your code, you have the following problem:

1. When you find some bug later in your code, you might hesitate to tell this to people. (appraisal at stake!)

2. You will not be open to comments or enhancements

3. You will never think about enhancing your code. We should always look for enhancement.

So I should start hating my code...!