FWIW - this is a part of carriage control - from mainframe control words to Windows/UNIX/FORTRAN carriage control. Carriage control can be implemented at a language level like FORTRAN does, or system-wide like UNIX and Windows do.
\n
arose from limitations of early PDP user "interfaces" - the tty terminal. Go to a museum if you want see one.
A very simple point: The difference between \n \r is explained above. But all of these explanations are really saying that carriage control is implementation dependent.
The [J
is part of ANSI escape sequences and what they do on a "standards conforming tty terminal".
DOS used to have ANSI.SYS to provide: colors, underline, bold using those sequences.
http://ascii-table.com/ansi-escape-sequences.php
Is a good reference for the question: what does some odd looking string in the output do?