If you're interested, you can calculate the recoil energy of a given load using the following formula:
WG = Weight of gun in pounds
WB = Weight of bullet in grains
WP = Weight of powder charge in grains
VB = Muzzle velocity of bullet in f/s
I = Interim number (Recoil Impulse in lb/sec)
VG = Recoil velocity of gun (f/s)
EG = Recoil energy of gun (ft lb)
I = [(WB * VB) + (WP * 4000)] / 225218
VG = 32.2 * (I / WG)
EG = (WG * VG * VG) / 64.4
The formula I've reproduced above, is from the Q&As at http://www.frfrogspad.com/miscella.htm (specifically the question about why some guns of the same caliber kick harder than others). John Schaefer (FrFrog) notes that, "..."4000" is the nominal velocity of the powder gases at the muzzle for commercial smokeless powder and the observed range is between 3700 and 4300 f/s. It is sometimes stated as 4700 in some sources but this is based on observations of artillery, not small arms...."
Let's assume that the two guns, one in .40 S&W and one in 9mm Luger weigh approximately the same. So --
A typical 9mm cartridge, say Federal American Eagle, fires a 124 grain bullet with a muzzle velocity of 1120 fps (Federal's published specs).
A typical .40 S&W cartridge, say Federal American Eagle, fires a 165 grain bullet with a muzzle velocity of 1130 fps (Federal's published specs).
Based on the above formula, recoil energy is directly proportional to bullet weight and muzzle velocity, i. e., the heavier the bullet (at a given velocity) will produce more recoil energy than a lighter one, with the same weight gun; and the greater muzzle velocity (for a given bullet weight) will produce more recoil energy with the same weight gun.
Looking at the 9mm Luger and the .40 S&W, the .40 fires a heavier bullet at a higher muzzle velocity. Therefore the .40 will produce more recoil energy, assuming guns of about the same weight.
Of course, recoil energy and felt recoil are two different things.
Recoil energy is a precise, physical quantity that is a function of the weight (mass) of the bullet, the weight (mass) of the powder charge, the muzzle velocity of the bullet, the muzzle velocity of the powder gases, and the weight (mass) of the gun. If you have those quantities for a given load in a given gun, you can calculate the amount of recoil energy produced when that load is fired in that gun.
Felt recoil is a subjective matter. It's how you experience the recoil, and it's really something that only you can decide for yourself.