Sometimes I found that writing just "J. Doe" may lead, in a justified line with few words, to a big space between the initial and the surname. Using
J.\,Doe looks ok but I would like to know if there is a general rule for spacing between initials and surnames.
As often in typography, this depends a lot on your own taste. When you write, "sometimes I found that [...] a big space", you already got your answer. You should reduce the space with kerning, horizontal correction or, easiest way, a smaller space like
The reason for the "too big space" is the dot after your abbreviation. The big white space above this symbol is sometimes distracting. That's why many abbreviations which have to be separated are typeset with a half space. In German e.g. we have
u.\,a.. In English, those abbreviations are often set together (e.g.
The space after "J." is mandatory in my eyes, as you would set a space after "John" too. However, there is no international standard for this and for example in Switzerland, they often leave it off. E.g. "St.Gallen" on traffic signs. In Germany, the standard DIN 5008:2011-04 (chapter 5 page 10) requires a protected space
~ after each abbreviation with use of a dot. As this standard is about writing rules but not about typography, they don't mention the possible use of half spaces anywhere.
For a reference: F. Fossmann and R. de Jong write their initials with a half space in their book "Detailtypografie" and also recommend that on page 126. They are using round about 25 % of the DTP-em-dash or 20 % of the standard em-dash.
The last point would be the question if a line break would be acceptable.
John\\Doe is quite easy to read but
J.\\Doe may mislead the quick reader to believe that the sentence is ending at the line end.
In conclusion: I think
J.\,Doe will be fine for most cases. But the problem expands when you want to write titles as well. E.g.
Dr. rer. nat. Dr. phil. J. Doe. I think a nice grouping which depends on every case will help the reader. But there are no standards for this. I believe that I would write:
Dr.\,rer.\,nat.~Dr.\,phil.~J.\,Doe. As mentioned in the comments, a line break may occur in long titles and names. As the period after a small letter is interpreted as the end of a sentence (which is indicated by a bigger space), you should at least prevent the stretching by use of
\. This could look like
I usually use
to create an "unbreakable space", keeping the space fixed even in justified paragraphs and preventing line breaks.
This is also useful after abbreviations like e.g., i.e. and so on, where Latex thinks of the dot as the end of a sentence and adds too much space after the dot.