In the present paper, resonant frequencies and modes of a three-atom photonic molecule and a photonic crystal placed within a cavity are numerically calculated. First, governing formulation in transverse electric field mode (TE) is obtained using Maxwell equations. Then, an algorithm based on a finite difference scheme and matrix algebra is presented. The algorithm is then implemented in a computer code developed by the authors. In the first run, resonant modes and frequencies of a linear three-atom molecule in the cavity are calculated. Calculations show that by increasing molecule length,the frequencies first come closer to each other but further increase reverses the process.Such a behavior is related to external cavity walls. In the case of photonic crystal in cavity, calculations show that the field distributions in the ground and first excited states are similar to the case where the cavity is homogeneously filled. On the other hand, calculations show that increasing the optical constant of the crystal decreases the frequencies. Such phenomenon is justified by the fact that light speed is slow in medium of high optical constants.