Just to be clear, I am trained as a physicist and I am not criticizing the thermodynamics as
incorrect but rather
insufficient.
It is also incorrect, which is to say that there is only a vague relationship between the kilocalories reported on the side of the box and the actual marginal energy absorbed into your body. This is due to multiple factors. The most basic is measurement methodology: “count up the carbs in grams and multiply by 4 because this one ancient paper claimed that was the right fudge factor to average all carbohydrates with”; then there is the reality that the carbs described as “dietary fiber” on the label should never have been counted in the first place; add to this that the fudge factor for protein is also 4 kcal/gr even though it is known that proteins require twice the energy input from your body to be metabolized. If you're a physicist you're hoping for very clean simple measurements, “we put this into a calorimeter and burned it, or maybe we let some bacteria rot the thing in a sealed jar and monitored the oxygen in there” or something. The nutrition facts are nothing of the sort! (Related: the scale llliiieeesss, it lies, liar liar pants on fire how it lies.)
However the bigger problem is that it is insufficient. For instance if you are worried about health outcomes, like diabetes risks, it turns out that calories in minus calories out doesn't predict those well. Both Omega-3 fats and trans fats are given the same fudge factor of 9 kcal/gr, but one is significantly less healthy than the other.
It's not even terribly helpful to understand the full context of weight gain. Did you know that before our species grew up in Africa, our ape ancestors actually grew up in Europe? During this process they lost the ability to make an enzyme called uricase, which helps most other mammals eliminate a waste product called uric acid from the body. The loss of this enzyme is usually chalked up to, “those apes needed to put on a lot of weight really fast at harvest time before the winter came up”—google «uricase evolution» to learn more. So we actually have a hardwired tendency which most mammals do not have, to consume fructose and not consciously register those kilocalories as satiety signal, and instead we pack on those kilocalories as fat because of our artificially high uric acid levels. Wild stuff.
The physics curriculum does touch on this but in a strange place: it's the courses where we teach kids to analyze circuits made with nonlinear components like op-amps and transistors. So there's the thermodynamic fact of calories in, calories out... but it also comes with a sales pitch which is trying to provide a simple answer that would work for a linear system, “just perturb this input a little bit and you will get the corresponding output.” But nonlinear systems don't work that way!