From :help J
(scroll down a bit, or scroll up a bit from :help replacing
):
These commands, except "gJ", insert one space in place of the <EOL> unless
there is trailing white space or the next line starts with a ')'. These
commands, except "gJ", delete any leading white space on the next line.
I am not sure why it works that way--maybe it is convenient for C editing--but it is well documented.