Guru –

The disciple must worship the Guru as God Himself – Swami Vivekananda                    


Today you are YOU because you met a Guru, He taught you what are ethics, he taught you what are values, he taught you what is justice, science and everything. A Value based education is a gift by a guru, Acquisition of knowledge and skills without acceptable moral values and discipline is meaningless. You know how to lead your life , you know how to face problems in your life, you know what is within you, you are made by your Guru, without a guru you are not you, you are just a body with no moral values. 

Respect your guru, a devine power acting upon you by your guru which will put a light on your life. 

Our Ancient Indian education system was a meaningful education system, Guru-Shishya were having strong bounding, but when English education system introduced by british our education system lost its originality. Today we never see that wonderful relationship between Guru and Shishya. Think for a while what you are today and why you reached this state of your life. 

Guru will show you the right path, according to Swami Vivekananda , The first lamp is the Guru, and the lamp that is lighted from it is the disciple. The Guru must teach me and lead me into light, make me a link in that chain of which he himself is a link. The man in the street cannot claim to be a Guru. The Guru must be a man who has known, has actually realised the Divine truth, has perceived himself as the spirit. A mere talker cannot be the Guru. A talkative fool like me can talk much, but cannot be the Guru. A true Guru will tell the disciple, “Go and sin no more”; and no more can he sin, no more has the person the power to sin.

Swami Vivekananda is the man who realised what a guru is for a disciple, we learn the true meaning of guru if we go by his life , only a guru can transform your life. 

Happy Teachers Day –

 

Hibernate QueryException : could not resolve property:

Hibernate QueryException :  could not resolve property:

org.hibernate.QueryException: could not resolve property: DP of: com.cess.pojo.Customer
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:61)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1402)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1377)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:457)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:417)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:68)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:357)
at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:113)
at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.(CriteriaLoader.java:91)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1577)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at com.cess.dao.impl.CusomerDaoImpl$1.execute(CustomerDaoImpl.java:77)
at com.cess.framework.TransactionWrapper.run(TransactionWrapper.java:41)
at com.cess.dao.impl.CustomerDaoImpl.getCustomers(CustomerDaoImpl.java:43)
at com.cess.service.impl.CustomerServiceImpl.getCustomers(customerServiceImpl.java:39)
at com.cess.controller.CustomerController.Customers(CustomerController.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

			




Solution –
Instead of using nested paths directly in Criteria API (unlike HQL), create nested criteria instances and use aliases on each “entity.property”
Example –






Criteria criteria = sessionObject
.createCriteria(Customer.class, "C")
.createAlias("C.department", "D")
.createAlias("D.Section", "S")
.createAlias("S.SubSection", "SB")

SEVERE: Exception sending context initialized event to listener instance of class

SEVERE: Exception sending context initialized event to listener instance of class

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map '/project' bean method
public java.util.ArrayList com.cess.controller.UserProjectController.UserProject(com.cess.pojo.Class)
to {[/get],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already '/userinfo' bean method
public java.lang.String com.cess.controller.UserController.userInfo(com.cess.pojo.User) mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map '/project' bean method
public java.util.ArrayList com.cess.controller.UserProjectController.UserProject(com.cess.pojo.Class)
to {[/get],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already '/userinfo' bean method
public java.lang.String com.cess.controller.UserController.userInfo(com.cess.pojo.User) mapped.
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:179)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:145)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:107)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:87)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:150)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 22 more

Solution
If your controller class are as follows







			




@Controller("/userinfo")
public class UserController {
@RequestMapping(method=RequestMethod.POST)
 public String userInfo(@RequestBody User user){
 }
}

@Controller("/userproject") 
public class UserProjectController {

@RequestMapping(method=RequestMethod.POST)
  public String userProject(@RequestBody UserProject userProject){
  }
}

//Then Use value Element of @RequestMapping as follows
@Controller
public class UserController {
 
 @RequestMapping(value = "/getuserinfo", method=RequestMethod.POST)
 
  public String userInfo(@RequestBody User user){

  }
}


@Controller
public class UserProjectController {
 //Note value in both controller requestMapping should be different
 
 @RequestMapping(value = "/getuserproject",method=RequestMethod.POST)
  public String userProject(@RequestBody UserProject userProject){

  }
}

Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @OneToOne property:

Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @OneToOne property: 

Solution :

Instead of using

@Column(name="columnName")
Use 
@JoinColumn(name="columnName")

Journey towards Space – ISRO

                    

The most wonderful and most mysterious thing in the Universe is the Universe itself. No one can say exactly how it started its journey, when it came into existence. Thousands of people from several thousands years trying to understand what exactly it is, though it is mysterious the god has given an incredible gift to human, yeah that is mind. Human mind is next mysterious thing in this Universe, Human mind is capable to reveal the secret behind the Universe and its existence. Every nation is in a race to do something for the first time when it comes to revealing something about Universe, but human first look towards the moon and in late 50’s and 60’s humans started exploring the Universe and ofcourse the Moon first.

America and Soviet Russia were in competition to reach the Moon first. It was Americans who landed first on the Moon, ofcourse they are proud to say about it, but being an Indian I am proud to say that all the knowledge of Universe, planets is given by Indians several thousands of years ago. Sadly from past few centuries Bharat was unable to do great inventions, innovations due to many reasons, but no doubt those glorious ancient days will come soon.

Inspite of many hurdles Bharat struggled and succeeded to come out from all the difficulties and started its space programme in 60’s. It was successful because we had dedicated scientists who worked very hard to achieve the planned missions.

 Prof Vikram Sarabhai who lead the team of ISRO in 60’s , a very energetic leader and under his able leadership Bharat started its journey towards reaching the space. Then dedicated, enthusiastic scientists like A P J Kalam joined the group of pioneers.

 I wanted tell how our scientists worked dedicatedly to achieve the best thing in space programme even after facing hardest hurdles. A picture is worth a thousands words. So I just wanted to post images here which will tell the story of our journey towards space.

A P J Kalam working on Rocket payload at Thumba in 1964

A P J Kalam working on rocket payload
A P J Kalam working on rocket payload

Rocket parts carried by Bullock carts 

 

Rocket parts carried by Bullock carts
Rocket parts carried by Bullock carts

Scientists transporting rocket parts on a bicycle 

Scientists transporting rocket parts on a bicycle
Scientists transporting rocket parts on a bicycle

Our scientists using muscle power to lift a rocket

Our scientists using muscle power to lift a rocket
Our scientists using muscle power to lift a rocket

These images tell the story and shows how our scientists enthusiastically worked even though there were no facilities, but they were determined to achieve the mission.

 Look where we are today? We reached Moon; We are about to reach Mars in a unique way. Our Mars mission is very unique, we used a best technique called “frugal engineering” to cut the cost. I will explain it in simple way, NASA will prepare atleast 4-5 test samples and then will launch the final satellite, which cost more for all test launches, but ISRO tries all possible way by simulating it and then analyzing every possibilities then trying with a final launch. It is possible only because we have best minds, who can analyse, who can calculate everything without even doing a prototyping and without even real testing.

 I call every young Indian, get inspired by people like A P J Kalama, Vikram Sarabhai and look towards core sciences, Do something for the nation; we are born to serve the nation.

 I am happy that we are reaching Mars in couple of days, Let us wait and say proudly that we are one among those who reached Red Planet.

It is not so easy to cross the orbit of earth and put our satellite outside earth orbit. Every minute calculation matters a lot, every small part will be very sensitive.

How important to consider every minute thing in such a mission ? Let us consider few facts from the history which shows the sensitivity of such missions.

Why some missions failed:

Bad timing: Though the Russian Kosmos 419 (1971) reached Earth’s orbit, it never reached Mars’ orbit because of a wrong ignition time setting. Instead of being set for 1.5 hours after launch, it was accidentally set for 1.5 years after launch. The spacecraft soon re-entered Earth’s orbit and disintegrated.

Faulty software: Bad mathematics may not kill you, but they can kill spacecraft! NASA’s Mars Climate Orbiter (1998) disintegrated because at one instance, its software used the wrong units (pounds, instead of Newtons). This caused the spacecraft to be placed too close to Mars where atmospheric stresses destroyed it.

Mars orbiter failure : Microsoft’s Research

Software Stability – How The Mars Path finder mission failed just because of improper setting of thread priority. ( http://research.microsoft.com/en-us/um/people/mbj/Mars_Pathfinder/Mars_Pathfinder.html )

Solar flares and fuel shortage: The communication systems of Japan’s Nozomi orbiter (1998) were disrupted by powerful solar flares. It also damaged the heat control system causing the fuel to freeze. It was unable to attain Mars orbit and operation was terminated.

Nobody really knows: Just three days away from Mars, all communication was suddenly lost with NASA’s Mars Observer (1992). For months, scientists could not explain what became of the spacecraft, but investigations finally concluded that a fuel and gas leak had probably sent the spacecraft into an uncontrollable spin damaging critical electrical circuits.

A journey To Mars –

This small video clip will give clear picture on how a satellite will reach Mars

http://www.jpl.nasa.gov/video/index.php?id=1038

Update – http://knowledge-cess.com/reaching-the-red-planet-mom-isros-successful-mission/

Dr K Radhakrishnan Chairman of ISRO  Interviewed – http://www.youtube.com/watch?v=ALPKTEitvrg&list=PLVOgwA_DiGzqMeD9X9LnC9SINtosOgE5W

Independence Day – Bharat

~~~~~~~~~~~~~                   Happy Independence Day             ~~~~~~~~~~~~~  

I remember my childhood days , I use to ask my dad to help me to prepare a speech for independence day, I use to prepare myself to give a nice speech on Aug 15th

Those moments are memorable , the interest within us to prepare for speech, the enthusiasm within us to keep everything ready for the day, our white colour uniform, a small flag on our chest , getting up early and going to school and helping workers to keep everything ready for the flag hosting.

I still remember how our teachers use to tell stories of our struggle to get independence, stories of Bhagat Singh, Mahatma Gandhi, Subhashchandra Bose and many more. I might have missed those days , but I never missed flag hosting ceremony , even while working I always tried to visit my native and celebrate our independence day as a school boy 🙂

Today I wanted to give my message to every one and hence posting this article here. 

We are celebrating 68th independence day , its been 67 years that british left our country and we became independent. If we look back to history and think about freedom struggle and sacrifices of our freedom fighters we feel heaviness in our heart, we will feel resentful (angry), we can’t express our emotions, some of you may cry, some of you may become speechless. We lost our wealth , we lost our culture , we lost our unity, we lost our values. Bharat is a land of inventions, Bharat is origin of civilization , Bharat is the land where a language and a script is invented first time ever on the planet, but later things got changed just within few hundred years because of british rule.

That was about the past , but the present of Bharat is showing a rays of hope , future is getting clear to every one . The journey of post independence was very challenging , we have faced every challenge, we have overcome from most of the problems. Inspite of all the challenges our country has achieved great, we have shown the world what is the capability of our nation. We reached Moon, Mars in a unique way, We have shown the strength of military to the world, we have 4th largest and strongest military power in the world, We have shown our capability in technology and science. We are unique in science and technology, today most of the Indians are leading most of the big MNC companies in the world. Sundar Pichai in Google, Satya Nadella in Microsoft, Indira Nooyi in Pepsico,Shantanu Narayen in Adobe, Sanjay Kumar Jha in Motorola now in Global Foundries and many more.  

The word’s most powerful countries are looking towards Bharat, we are strong enough to beat every one in many aspects. Everything is great and I am proud to say about the glorious vision of our nation, but My concern is our culture, my concern is about values , my concern is about education system of our country, my concern is about our language, my concern is about our patriotism, my concern is about unity within us. Even if we don’t reach moon that is perfectly OK, but unity within us, a value based education are primary focus.

I feel somewhere we are loosing the track in that manner, Education system in our nation became a business rather than becoming a value based education as said by Swami Vivekananda. According to me we are complete if we are able to get back to our glorious ancient Bharat. We should reconstruct our education system first, We should bring back our solid gurukula system back , our ancient Bharatiya education system was awesome, it was a meaningful education. Today our kids love to talk in english than our own language, today our kids talk more about hollywood movies and other fascinating stuff rather than talking about our freedom fighters, somewhere we are losing values and losing our track in this materialistic life. 

Lal Bahadur Shastri ji said “ The preservation of freedom, is not the task of soldiers alone… The whole nation has to be strong.” Being a software engineer , I use to ask myself always, what I am giving back to my nation? Am I developing something great for my nation ? 8 hours in a day we use to work for foreign clients, weekends most of you spend time in shopping malls, in theaters to watch Hollywood movies. I really respect government workers, some of them might be corrupt but at least they are working for our own people. 

I read somewhere that in ancient Indian education system Gurukula, the Guru and Students together use to do innovative activities, a bridge somewhere near Vishakapatnam was constructed by Guru and students thousands of years ago and still it is in great conditions. That was the bounding between Guru and Shishya but today we hardly see respect towards a guru . According to me a perfect education system is the one which we teach humanity first rather than science and technology, a perfect education system is the one which teach ethics of every profession. 

A Civil engineer must consider an environmental consideration first before constructing a building, he should not construct if its harmful to the Eco system. An electrical engineer must consider what he can do best to the nation, constructing a huge dam to generate power may not be a good idea than establishing a huge solar power station. a computer science engineer must think first about the nation and make things better by giving something great to our nation. In every profession one must be ethical , one must think about our planet first, our nation first, our system first. Earning money should not be a primary concern, but that is not happening in today’s world. For everything money is the biggest factor which change the human mind, which spoil everything.

Swami Vivekananda had said, “The education which does not help the common mass of people to equip themselves for the struggle for life, which does not bring out strength of character, a spirit of philanthropy, and the courage of a lion – Is it worth the name ? ”.  We should work to achieve this and get back our glorious ancient Bharat. You might earn hell lot of money, you might have your own big house, car everything which gives you a luxurious life , but nothing you will take with you at the end, we should first think about giving something back to our nation, that is responsibility of every countrymen .

Let us think for a while and bring change within us on this wonderful day, let us start thinking about every problem what our nation is facing today and try to find a best possible solution and implement it to solve it. Let us think about the future of our nation and work together to achieve it. You make a group within your friends, discuss about our country, take necessary steps to correct the system, bring awareness within people, within your family members, within your friends. Read about Ancient India and spread the facts and story of our nation.

Country has given everything to us, Ask yourself What you have given back to country ? 

“ The preservation of freedom, is not the task of soldiers alone… The whole nation has to be strong.”
- Lal Bahadur Shastri                         

Graph Theory, Matrices – A Realtime example

Observe the matrix given below 

Adjacent Matrix
Adjacent Matrix

 

The above Matrix shows all zero at diagonal. 

Let me draw a graph for this ,

Directed Graph
Directed Graph

 

Assume that A, B and C are entities in database , Say Person entity.

A – Ram , B – Suma, C – Prema

Ram – Posted 
 Hello ….
Suma – Commented
  Idiot 🙂 …
Ram – Replied
  You Idiot …
Prema – commented
  See every one call you as idiot 🙂
 
Directed Graph
Directed Graph
 
Hold a moment … Does the above graph is correct ?
Observe what is changed in below graph
Un-Directed Graph
Un-Directed Graph

 

It is not mandatory that only A has to comment B ! , Even B can comment A .

So the first graph shown  is a directed graph and it is wrong , It should be undirected graph.

Now assume that how a facebook keeps track of connected friends ? Mutual Friends ? how big is the graph of facebook ?

The intention of this article is , to teach you guys how a Matrix concept is used to represent a graph, and how a graph theory is used in realtime to represent a social networking site like facebook.

Now understand why one should learn Graph Theory and Matrices

Let us have a look into facebook DB and Big data
Total Monthly Active users – 1,310,000,000
Total Mobile users  – 680,000,000
Every 20 minutes on Facebook
Links shared –  1 million
Friend Requests – 2 million
Messages sent – 3 million
http://www.statisticbrain.com/facebook-statistics/

For loop VS While Loop – which is faster ?

Many times I have come across a very basic question Whether For loop is faster ? or While loop is faster in C and other languages. Most of the times an unexperienced developers use to ask this question to me. So I thought to write an article on this .

The answer to this question is – there are no difference in performance , both For and While loop perform same , but this may differ a little for different compilers. It may slightly differ for different compilers because it depends on how a compiler compiles and generates machine code for the same. Even thought those factors are negligible .

I managed to figure it out by looking into the intermediate assembly code generated for both For loop and while loop. Looking at the assembly instructions generated for both , it shows that both have similarly equal number of instructions and similar instructions.

Instead of explaining it in text, I am posting screenshot of assembly code generated with marking of details. The assembly code is generated in Mac OS X , XCode by using Assemble option.

For Loop Assembly Code
For Loop Assembly Code

 

While Loop assembly code
While Loop assembly code