  We discuss the relation of the specific heat, the energy density and the
thermodynamic Casimir effect in the case of thin films in the three dimensional
XY universality class. The finite size scaling function $\theta(x)$ of the
thermodynamic Casimir force can be expressed in terms of the scaling functions
h'(x) and h(x) of the excess energy density and the excess free energy density.
A priori these quantities depend on the reduced temperature t and the thickness
L_0 of the film. However finite size scaling theory predicts that the scaling
functions depend only on the combination x=t [L_0/\xi_0]^{1/\nu}, where \nu is
the critical exponent and $\xi_0$ the amplitude of the correlation length. We
exploit this fact to compute \theta from Monte Carlo data for the excess energy
density of the improved two-component \phi^4 model on the simple cubic lattice
with free boundary conditions in the short direction. We repeat this exercise
using experimental data for the excess specific heat of 4He films. The finite
size scaling behaviour of the excess specific heat is governed by h''(x), which
is proportional to the scaling function $f_2$ discussed in the literature. We
compare our results with previous work, where the Casimir force has been
computed by taking the derivative of the excess free energy with respect to the
thickness of the film. As a preparative study we have also computed the scaling
functions h'(x) and h(x) for finite L^3 systems with periodic boundary
conditions in all directions, where L is the linear extension of the system.
