  Josephson effect in short ballistic SINIS and SIFIS double-tunnel junctions,
consisting of clean superconductors (S), a normal metal (N) or metallic
ferromagnet (F), and insulating interfaces (I) is studied. For SINIS
double-tunnel junctions, sharp peaks in the critical Josephson current as a
function of the junction width result from the resonant amplification of the
Andreev process when the quasi-bound states enter the superconducting gap. For
SIFIS double-tunnel junctions spin split quasi-bound states partially amplify
the supercurrent and trigger the transitions between 0 and $\pi$ states of the
junction. Instead of the critical current reaching a peak value (which happens
when the Andreev states cross the Fermi surface in SINIS junctions), a narrow
dip opens up exactly at the peak due to the compensation of partial currents
flowing in opposite directions. This is related to the spin polarization of
Andreev states and explains the coexistence of stable and metastable 0 and
$\pi$ states in the vicinity of the transition. With increased barrier
transparency, the described mechanism of $0-\pi$ transitions is modified by the
broadening and overlapping of quasi-bound states (transmission resonances).
Temperature-induced transitions both from 0 to $\pi$ and from $\pi$ to 0 states
are studied by computing the phase diagram (temperature vs. junction width) for
different interfacial transparencies varying from metallic (transparent) to the
tunnel limit.
