Engineering Full Stack Apps with Java and JavaScript
The line separator is the name given to the character or characters used to separate lines of text, and vary from platform to platform. On Windows, it is the CR character (carriage return) followed by the LF character (linefeed), which is \r\n. On UNIX, it is the LF character alone, often referred to as the newline character.
Although the output may look the same to the naked eye through command prompt or eclipse, it could easily cause problems if it were saved in a file or piped to another program for subsequent processing.
You can use printf with the format string "%n". Each occurrence of the characters %n will cause printf to print the appropriate platform-specific line separator.
System.out.printf("%n");
The "%n" specifier doesn't correspond to an argument, unlike most specifiers in printf.
Similarly you can use String.format() instead of printf() to get the platform specific line separator.
You can also use System.getProperty() to get the line separator.
System.getProperty("line.separator");
Java 7 now has a method specific for this purpose:
System.lineSeparator()
If you're trying to write a newline to a file, you could simply even use BufferedWriter's newLine() method.