All Calories Are Not Created Equal
What is a calorie, or a kilojoule for that matter? They are both simply a measure of energy. The body needs energy to perform all of it's basic functions as well as for doing work or walking the dog or washing the car or whatever physical activity you are engaged in.
But just counting calories, without taking into account the way that these different calories affect the body is an absolutely useless exercise.
Let's compare eating 1,000 calories worth of ice cream to eating the same calories in salad.
The ice cream is high in sugar and therefore creates an insulin response in the body. Some of the calories may get burned up by the body but some are definitely getting stored as fat.
The salad, on the other hand, contains little sugar or carbohydrate content. It is also high in fibre and better in nutrient content than the ice cream. Therefore, it is unlikely any of that "energy" will be stored.
Our body gains or loses fat according to detailed hormonal instructions from our brain. The rise and fall of insulin is the main stimulus to weight gain. So, food that stimulate insulin are typically more fattening (cookies). Those that do not (kale) are typically not fattening at all. If the body cares about insulin (and other hormones too, but mostly insulin), then we need to use the common currency, speak the common language of the body. Insulin.
The amount of insulin generated by the food you eat is a much better measure of the effects of food that you eat than it caloric content, because that is what determines whether the energy in your food will be used or "stored".
The measure of how any particular type of food affects your insulin production is the Glycemic Index (GI). GI is a useful index to use when measuring the fat-storing potential of food, calories is not.