Have you considered the possibility that you might have a coding error that your friend did not?
Or even that you both have the same coding error, for example, accessing an array with an invalid index, but that C++'s lax approach to array bound checking allowed it to pass, whilst Java’s more strict approach did not?