In this paper, we prove that for any Kahler metrics $\omega_0$ and $\chi$ on $M$, there exists $\omega_\varphi=\omega_0+\sqrt{-1}\partial\bar\partial\varphi>0$ satisfying the J-equation $\mathrm{tr}_{\omega_\varphi}\chi=c$ if and only if $(M,[\omega_0],[\chi])$ is uniformly J-stable. As a corollary, we can find many constant scalar curvature Kahler metrics with $c_1<0$. Using the same method, we also prove a similar result for the deformed Hermitian-Yang-Mills equation when the angle is in $(\frac{n\pi}{2}-\frac{\pi}{4},\frac{n\pi}{2})$.