Sun appears to be white and sky appears to be black in space because
There is no atmosphere to scatter the sun's light in space
On Earth, the sun appears yellow. If you were out in space, or on the moon, the sun would look white. In space, there is no atmosphere to scatter the sun's light. On Earth, some of the shorter wavelength light (the blues and violets) are removed from the direct rays of the sun by scattering. The remaining colors together appear yellow. Also, out in space, the sky looks dark and black, instead of blue. This is because there is no atmosphere. There is no scattered light to reach your eyes.