Posted on December 19, 2009 by Veerabahu
Last week, I was reading through an article written by Bill Venners (don’t read this now). Though the purpose of the article is to highlight some of the key interviewing techniques, I was excited by Josh Bloch question, “Finding is a number power of 2”.
After finding few answers other than the one mentioned in the above article, I put the same question to some of my colleagues/friends. Most of them (99% of people, including me) immediately came up with the following answer “recursive (Number/2)==0, then power of 2” or continuous multiplication with 2 gives that number, as shown below
int number = 8;
int tempNumber = 1;
while(tempNumber<number){
tempNumber*=2;
}
if(tempNumber==number){
System.out.println("Power of");
else{
System.out.println("Not a power of");
}
Yes, the above solve the problem in hand, but is this an efficient one? Will this work for large numbers or gives overflow issues? For sure I can’t see this solution as an efficient one. So I contacted my genius friend Sree. Not to the surprise, he came up with a more efficient solution. I and 99% of my friends have seen the problem in decimal but Sree has seen it in bits. Without further ado let us see the (one line) code
System.out.println(((number&(number-1))==0)?"Power of":"Not a power of");
Hope you too accept it to be more efficient than mine One other solution proposed by Josh Bloch in the article http://www.artima.com/wbc/interprog.html (now read it) is
System.out.println(((number&(-number))==number)?"Power of":"Not a power of");
Which answer you came up with? Hey did you come up with some new one? Let us know the same.










Filed under: techinal | Tagged: java | Leave a Comment »
Posted on November 11, 2009 by Veerabahu
Today (10-Nov-2009) I have experienced many new things in my life. First to mention, being an inhabitant of Chennai only after five years of industry experience, today is my first day to visit Tidel Park, Chennai. Also today I have my first time exposure to Amazon Web Services (AWS). It is a good workshop that opened my eyes towards many new technical jargons. In this blog, I am trying to capture most of the items that are discussed today. Most of the things captured here are from my notes (or from top of my head), so they are going to be keywords rather than detailed explanations. Read more »
Filed under: techinal | Tagged: aws awschennai | 5 Comments »
Posted on November 9, 2009 by Veerabahu
In the last article in addition to setting up our IDE for writing REST services we have also got friendly with four basic annotations. In this article we will look in to some of the other commonly used annotations in REST. Read more »
Filed under: techinal | Tagged: java, rest jersey | 1 Comment »
Posted on October 29, 2009 by Veerabahu
Introduction
REST, acronym for Representational State Transfer is coined by Roy Fielding to represent architectural style of networked systems. This is not a standard but an architectural style for an application that is based on different standards like HTTP, XML, URL, MIME types. JAX-RS specification, JSR 311 defines a set of java APIs for development of RESTful web services and RESTful java application. Sun Jersey, JBoss RESTEasy, Apache CXF provides implementation for JSR 311. In this article we will look at the steps needed to setup Eclipse IDE for developing REST application using Jersey. We will also write our first HelloWorld service. Read more »
Filed under: techinal | Tagged: rest jersey | 1 Comment »
Posted on September 16, 2009 by Veerabahu
Currently I am reading Struts 2 in Action. This is my second book from Manning publication. My first book was JQuery in Action which is awesome. As I completed the second chapter in Struts 2 I like to try out the sample HelloWorld program. So I downloaded the source code from manning website. I am able to play with HelloWorld in few minutes by deploying (copying) the downloaded war inside Tomcat 5.5. However I also want to make a development setup in my eclipse so that I could try out certain things after changing the downloaded source. Unfortunately I am not able to make this easily. Read more »
Filed under: techinal | 1 Comment »
Posted on August 22, 2009 by Veerabahu
Simple Network Management Protocol (SNMP) is one of the widely used management protocol. SNMP has gained a huge advantage due to its ease of data retrieval and efficient use of network bandwidth. This blog aims to cover certain key points in SNMP (version 1 & 2c). Some of these points are not explicitly said in the SNMP RFC. Hope the concepts discussed will be a good learning experience to you Read more »
Filed under: techinal | Tagged: snmp | 1 Comment »
Posted on July 17, 2009 by Veerabahu
Posted on July 14, 2009 by Veerabahu
As I have wrote in my previous article, JQGrid is one of the most powerful JQuery plug-ins used in creation of grids. Though JQGrid provides most of the functionality out of box, there are certain things for which we might need to extend. I came across one such requirement a week before.
Read more »
Filed under: techinal | Tagged: jqgrid, jquery, js | 12 Comments »
Posted on July 13, 2009 by Veerabahu
For the past few days I have been working with JQGrid, one of the most powerful JQuery plug-in. To give an outline, JQGrid helps us to create a grid with ease. The power of JQGrid comes from the fact that almost all the needs for a grid are addressed using simple tunable options. JQGrid can be downloaded from http://www.trirand.com/blog/?page_id=6. JQGrid has a good documentation available at http://www.secondpersonplural.ca/jqgriddocs/index.htm. Also most of the JQGrid options are demonstrated well in http://www.trirand.com/jqgrid35/jqgrid.html. In spite of these well written documents, there are times I spent digging JQGrid source code for some customization needs. I also strongly feel that most of my co-workers might need the same at some point of time, so thought of blogging (documenting) for further reference.
Read more »
Filed under: techinal | Tagged: jqgrid, jquery, js | 33 Comments »
Posted on May 25, 2009 by Veerabahu
Though JQuery comes with a bunch of selectors, there are situation where we need to have additional functionality. JQuery has provided the interface using which we could harness our selector with the already available selectors. In this blog we are going to see 4 easy steps to do the same. Read more »
Filed under: techinal | Tagged: jquery, js | 1 Comment »