Tuesday, 27 November 2012

We've seen the World Change!!

I always feel happy about myself that I was born in the early 90's. That was the best time to be in this world. It was that time when we say, that the world was changing. We were getting modern!! We were slowly getting into the sci-fi world!!!

If you are someone born in the 80's or 90's, you will definitely be the witness of two totally different worlds. Not only because we have already seen a lot of change, but, we will be lucky enough to be alive for more 50 years at least to see something that we never dreamed of. And that's what I'm very enthusiastic about!!


The two worlds I’m talking about is the one in which the technology has just begun to evolve. We were witness to some of those. And the other which we are yet to experience. The FUTURE!! Where there will be things that we never imagined. To write this blog, I have referred to some of the articles I found out on the internet.


So my first example for how the technology around us changed would be the Internet or the 'World Wide Web'. WWW was invented in 1990 and we know how it has changed in the past few years. The WWW brought a revolution and has proved as an important knowledge and communication resource since its invention.


We have seen the Video Games evolved. Remember the Brick Game?? When we were young, that brick game was the most awesome gadget we had. Not when we take a look at the Video games, we have just crossed the limits of our imagination. With X-BOX and Sony Play Station offering Motion control and Gesture Control. A totally different experience!!!!!! Over the last ten years we’ve seen games focus on technology: increasing graphical fidelity, delivering more natural animation and improving AI and physics. 


Experts say that the future of gaming lies in Biometrics.  Biometrics will not only be able to detect players’ emotions, but also that within 10 years, games will be able to offer unprecedented levels of interactivity. The key to this is building up an understanding of the player, a biometric profile, which may not only know what you enjoy, but possibly also how you might behave in a given situation.

We will be lucky enough to play these games. Soon!! ;)

There was a time when the Mobile phones were just available to a few fortunate. But with the evolution of technology, mobile phones have become a crucial part of our daily life nowadays. Everyone – from teenagers to old men – has a personal cell phone of their own. Improved technology has made a great change in the history of mobile phones, transforming the huge brick-like mobile phones of 1995 to sleek and stylish smartphones we carry with us now.

Mobiles will continue to get steadily better, with higher resolution touch-screens, speech recognition that really works and much greater memory and storage capabilities. And we will see many more smart applications coming with these changes that will make us wonder!!

There are many such examples which will make us think how great our future is going to be like!! We are lucky enough to be born in the era which we can call as ‘semi-modern’. This made us have a look at what the technology in the past used to be like. We are definitely advancing in all terms. We are going to experience the change! From the ‘semi-modern’ world to the ‘modern’ world, where there will be things or technologies which we never believed would be.


When we talk about the future, one thing that can come across is the ‘Sixth Sense technology’, which is a tool that connects the physical world with the world of data. 'SixthSense' is a wearable gestural interface that augments the physical world around us with digital information and lets us use natural hand gestures to interact with that information. You can find an amazing video about the Sixth Sense Technology on TED.


The Future certainly looks good!! 


~SunMit

Tuesday, 30 October 2012

Squeezing More Out of Google

Google has always been the most preferred search engine for most of us. There are some jokes which say that we use "www.google.com" just to check whether our internet is working fine.
From the very beginning, Google always targeted fast search. That is why Google always displays the time taken to search on the very first line after the search text box. This was what distinguished Google from the search engines those days. Google was the one which came up with the approach called Page Rank. Google has evolved a lot with time.
Searching things on Google is very easy. But if you want to search something precise, Google has some cool features that allow you to do so.
Some of the features were known to me. Later, I came across a post in my company portal which had it all!! :)
Do try to use them to optimize your search.

Using Keyword 'Site'

The first big thing that helps is the site: keyword. This helps you to limit your searches to a particular site. For example:
This searches only the edu sites. Whereas this one
searches only the IBM site. 

Using the Keyword 'Doc'

Similarly the next one that helps me is the doc: keyword. So
gives me only presentations while
gives me only pdf files. This keyword supports most of the popular document formats (it has helped me whenever I needed it, but I cannot vouch for all the formats).

Using Phrases for Searching

The next one is very useful when searching for a phrase. for example
allows me to search for the two words (use and case) together and in that order.

Using Hyphen to Negate

Using negation is possible by using a hyphen before a word as in
This means I am looking for a document which contains all the keywords but does not have realtime mentioned in it. By convention Google uses the AND operation for all the keywords you give. So in the above examples Google searches for documents that contain ALL the words I have mentioned ie. it applies the AND operator between keywords. The hyphen operator applies the NOT on the keyword realtime. And here is another example that is useful to exclude sites as needed.

Order of Search Keywords

Another little known aspect is the algorithms Google run give importance to the order in which we mention the keywords. It seems that the keywords at the start (left side of the search bar) are given more importance than the ones mentioned later. So sometimes changing the order of your keywords bubbles up the results you are looking for.

By far these few methods above are the best tools Google has provided me in making my searches more effective. However there are more methods that Google provides (but I use them only once in a while).

Other Logical Operators

You can use other operators as well. Google supports OR, parenthesizing, wildcard and ranges. So you can build some really complex expressions. For example:
Note how wild cards and number ranges are used in these searches.

Other Interesting Stuff

There are a host other interesting keywords one can use: intitle, inurl, intext, inanchor, link, cache, related, info, define, and so on. Some of these useful whereas others I find the others of only pedantic value. Here are some interesting examples that I have found useful in the past.
inurl:/web/guest - this search finds all websites which have the structure '/web/guest'! 
link:persistentsys.com - this lists all sites that link to persistentsys.com. Find who is linking to our website, its a good research tool.
related:persistentsys.com or related:liferay.com - these queries give you competitors (according to Google) of Persistent and Liferay! This is very useful information for research
And then there are special syntax queries that Google supports to do the following
1 gbp in inr - this converts a pound (Great Britain) to Indian Rupees as the first line of the search results.
time in paris - gives the current local time in Paris.
sfo jfk - Check flight details, airfares, etc. Just enter the Airport codes of the cities you are interested in.
43323 * 32322 - 324 - Just enter Numeric expressions into the search bar and Google turns into a calculator.
define:central processing unit - Find Definitions by entering the keyword define followed by the term you are looking for and watch the first line of the results.
and many more. Overall Google is trying hard to be your everyday desktop tool beyond a search engine. I might have missed many others, please add any other interesting things that you have found.
Okay we dont need to restrict to Google - if you have tips like these with other search engines we can discuss those too! By the way you can get a list of other search engines by using related:google.com !!
Now, thats cool!! :)
Enjoy Googling..... ;)
~SunMit

Tuesday, 25 September 2012

Find sum of two numbers without using any arithmetic operators in C

Finding sum of two numbers in C is simple.
You simply add the two numbers using an ADDITION operator:

sum = num1 + num2;

Simple!

I had never come across something which said "how to find sum of two numbers in C, without using arithmetic operators".
Yes, this is possible. You can do this using the 'printf()' function in C.
Basically, a printf() returns the number of characters that the function prints, i.e. an int.

For example,

printf("%d",printf("Hello"));

will print 5, because the inner printf() prints 5 characters of the word 'Hello'(5 characters).

Also, you can specify how many times do you want to print a particular character by using a *, which represents the width field of printf():

For example,

printf("%*c",5,'A');

will print AAAAA, as we specified width=5.

Now, to find the sum of two numbers, all we need to do is to print a particular string whose length is equal to the sum of the two numbers.
Following is the way it can be done:

int a=3,b=4;
printf("%d",printf("%*c%*c",a,'A',b,'B'));

will print 7, which is the sum of a and b. This is because the inner printf returns a character string AAABBBB.

I hope this helps you.
So, next time you go in an interview and you are asked if its possible to find the sum of two numbers in C without using any arithmetic operators, you have your answer! :)

~SunMit

Saturday, 25 August 2012

HOW TO Insert a code snippets in Blogger

Hello Readers,
Just while writing my first blog, I came across the problem that how can I insert a code snippet into my Blog. I then came across something called Syntax Highlighter. SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript. 

In this post, I have tried to provide a simple way to insert a simple code snippet into your Blog.

Firstly, all you have to do is to create a simple blog containing all the text part without the code in it and save it as draft.

Then edit the blog in HTML mode an insert the following code just above the <HEAD> tab:

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script> 
<script language='javascript'> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
Now, there are two methods to insert your actual code into your blog:

1) Using a script Tag:
Just insert your code within the following into your HTML.
Using a script Tag can display an error.
This error does not allow you to draft your blog. You can fix this by simply inserting a 'space' before the <![CDATA[ like this < ![CDATA[ (dont forget to add a space at end and change ]]> to ]] >) then it wont count it as a broken tag and you can save it as draft. Just don't forget to revert it before you publish the blog.

2) Using the pre Tag:
Using a PRE Tag is simple and it does not involve any issue as in the script tag.
 
 // HTML Encoded code

I have always used the term 'HTML Encoded code' in the above examples to denote your code, wherein we must insert a HTML encoded form of the code when our code consists of tags which are similar to HTML tags.
For example, when using the following code snippet into your blog, you need to first encode the code into HTML to keep it from breaking:
Set<Object> set = new HashSet<Object>();

The syntax highlighting wont be proper if you don't encode the code containing the tags similar to HTML tags.
You can encode your code online using a simple HTML Encoder.

Also, there is a very easy way if you dont want to play around with the HTML code of your blog. You can use http://hilite.me/ to format source code. It supports lots of formats and outputs rather clean html. But if you have lots of code snippets then you have to do a lot of copy paste.

Please let me know if this post helped you in any way or if there are any other simple ways to achieve the same.
I'd love learning new things.

Please leave a comment if this post helped you or if there are any suggestions.

~SunMit.


Iterating over Collections in JAVA


The Collections API's  in JAVA were introduced to provide a simple way to handle the collection of objects.
Collections works a bit like arrays where unlike arrays, collections prove very important when you expect their size to change dynamically.
The Iterable interface (java.lang.Iterable) is one of the root interfaces of the Java collection classes.
The Collection interface extends Iterable, so all subtypes of Collection also implement the Iterable interface.

Considering the three most frequently used Collection types ie. Array List, Hash Set and Hash Map, this post will help you iterate over these collections.

Iterating using iterators :

1) Iterate over Array List:
List<Object> list = new ArrayList<Object>();
while(listIterator.hasNext()){
 Object object = listIterator.next();
 // do something with object
}

2) Iterate over Hash Set:

HashSet is backed by a HashMap. It makes no guarantees about the sequence of the elements when you iterate them.

LinkedHashSet differs from HashSet by guaranteeing that the order of the elements during iteration is the same as the order they were inserted into the LinkedHashSet.
Reinserting an element that is already in the LinkedHashSet does not change this order.
Set<Object> set = new HashSet<Object>();
Iterator setIterator = set.iterator();
while(setIterator.hasNext()){
 Object object = setIterator.next();
 // Do something with object
}

3) Iterate over Hash Map:

HashMap maps a key and a value. It does not guarantee any order of the elements stored internally in the map.
TreeMap also maps a key and a value and it guarantees the order in which keys or values are iterated - which is the sort order of the keys or values.

Iterating over a Hash Map is tricky as Hash map contains a key-value pair.
A map entry (key-value pair). The Map.entrySet method returns a collection-view of the map, whose elements are of this class.

Map<Object> map = new HashMap<Object>();
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
 Entry thisEntry = (Entry) entries.next();
 Object key = thisEntry.getKey();
 Object value = thisEntry.getValue();
 // do something with key and value
}

Iterating using for-each loop and its advantages :

JAVA later introduced 'Enhanced for each loop iteration control', which extends the JAVA5 for-each loop to allow access to the loop index,  whether this is the first or last iteration, and to remove the current item.

MAJOR ADVANTAGE :

The for-each loop is almost certainly the most new popular feature from Java 5. It works because it increases the abstraction level - instead of having to express the low-level details of how to loop around a list or array (with an index or iterator), the developer simply states that they want to loop and the language takes care of the rest.
However, all the benefit is lost as soon as the developer needs to access the index or to remove an item. The original Java 5 for each work took a relatively conservative stance on a number of issues aiming to tackle the 80% case.
However, loops are such a common form in coding that the remaining 20% that was not tackled represents a significant body of code.

The process of converting the loop back from the for each to be index or iterator based is painful. This is because the old loop style if significantly lower-level, is more verbose and less clear. It is also painful as most IDEs don't support this kind of 'de-refactoring'.

MAJOR BENEFIT :

A common coding idiom is expressed at a higher abstraction than at present. This aids readability and clarity.


# Iterating over Array list and Hash Set using for-each loop is similar and simple.
for(Object object: list){
 // Do something with object
}
for(Object object: set){
 // Do something with object
}

# Iterating over Hash Map:
The simplest method to iterate over a Hash Map is by using a for-each loop.
for (Map.Entry<Object> entry : map.entrySet()){
 Object key = thisEntry.getKey();
 Object value = thisEntry.getValue();
 // do something with key and value
}

I have used stuff from JAVA Tutorials provided by Oracle and some answers I got from
Stack Overflow. You can find these things online out there, but I have tried using those 
things in a simple way and that you can find at one place.
Please let me know if I am wrong or if there are any other easy and efficient methods that can be used to iterate over these collections.
I would love learning something more.


Please leave a comment if this post helped you or if there are any suggestions.


~SunMit

Friday, 24 August 2012

My First Blog

Hello Readers,
I had wished to write my own blog for a long time. Always wondered what the content of my blog would be. Whether it should be technical or just some random stuff that I would like sharing.
So here I am, trying to put everything that I have learned and will be learning throughout my journey.

Being a Software Engineer, I believe most of the things I post will be technical, the new things that I will be learning. The tricks that might be useful to all the new professionals who get into this industry.

That's all for now. Will update my first blog later when I myself get a clear idea about my strengths and key areas so that I can help the readers in developing themselves too.

Always keen to learn new things.

~SunMit