Sunday 13 November 2011

see , how short / int / double can create difference in execution of for loop .

I got a beautiful response from people in previous week so i can not say good bye to my blogging ... here a simple but interesting topic , see how can values like short / int / double can create difference in execution of for loop . 

now its time to come in my topic . look when our for loop walks inside machine , for execution , at the rum time if you are using int in your for loop than its ok , because java is there for programmers who love int in their programming . i am just making a simple program of for loop where i have just use int values . 



now look what will happen when this program will reach into machine for execution . at machine level too many instructions are used there . 
                                                     
some instructions are used here . look some which i want to explain . see here why i am saying that java is built for int lovers , if you want to use increment statement in your programming than you can only use increment word in your programming with integer no other data type is in java to support "inc" instruction . and for int lovers look at comparision statement here we use if_icmpge statement , only one statement . and the best thing is that for int lovers . if you see this code this is too small than all the codes relatives to for loop . 
means i will show you some images , by seeing them you can say that run time code for for loop for int is too small than all the other data types in java . 

now i want to explain a example where i have used short . and see the difference between int and short and here you can see the compactness followed by int values which is provided by java .

               
now see the difference between int for loop and short for loop . comparsion statement is same because implicitly in java every thing is performed with the help of  "int" . so every thing is same but a statement is changed that is iadd and i2s . i have  already said that increment word or instruction is only used with integer so this is short but before this we all know that short is also used as int , so why we are using i2s instruction , we are using this instruction because when one process of for loop ends after it the value is stored into memory in the form of short so we have to store it as short . 

now look i have to explain the double for loop . so i am using double value . for explaining the for loop . 
now look at the double for loop . here things are different than int for loop but some things like increment is same as short for loop . now look at differentness from int for loop , differentness is a compare statement , at int for loop we are using statement like ig_cmpge but here different statement is used which is dmpg + ifge so .. thats the difference , and thats what i want to explain ... to all of you .. so ba-bye and take care 

                                                                                                                                  thanks tushar 

No comments: