Magnetization and pinning effect of a Josephson junction