Q:

In Java, why does System.out.println("\" \\"); gives " \ as output

In Java when i run System.out.println("\" \\");
I get output as :
" \
Can you please explain in detail, why this is happening?

A:

Because you escape double quotes ("") with a backslash (\) and also a backslash with a backslash.

A:

System.out.println("\" \");  
System.out.println("   --> String Open
                   \"  --> Double Quote character escaped using backslash
                   \\  --> Backslash itself as a character escaped using backslash
                   "); --> String Close

will give you output as "\
For the list of escaped characters, You can find that here.

\t    Insert a tab in the text at this point.
\b    Insert a backspace in the text at this point.
\n    Insert a newline in the text at this point.
\r    Insert a carriage return in the text at this point.
\f    Insert a formfeed in the text at this point.
\'    Insert a single quote character in the text at this point.
\"    Insert a double quote character in the text at this point.
\\    Insert a backslash character in the text at this point.

A:

backslash is a special character in JAVA and many other programming languages, one of its use is to escape characters in certain situation. 
For example:
If you want to print a string containing double quotes like: How are you "Bob" ?
Printing this using System.out.println("How are you "Bob" ?"); will not work because you are closing the quotes just before the word Bob. Therefore, a character was used to deal with such situation so one can print double quotes inside a string:
System.out.println("How are you \"Bob\" ?");

Moreover, since we've agreed above that \ escapes the double quotes, if you want to print a single backslash inside a string, doing this System.out.println("\"); will open the string but will escape the second double quotes which will result in an error because the string was not closed. To fix this, you need to escape the backslash like this: System.out.println("\");
Other interesting uses of \:
\n character to return to a new line
\t character to insert a tab
More about escape character can be found on Wikipedia

