'\n' and "\n" ?

Can any one explain what is the difference between using code like '\n' and "\n" ? For escape sequences should I use single or double quotes ?
[158 byte] By [Shebua] at [2007-11-27 9:10:19]
# 1
The first is a char.The second is a String.What do you mean about "escape sequences"? If you want a single char, use single quotes. If you want a String, use double quotes.Do you mean unicode escapes?
jverda at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...
# 2

yes Unicode escapes...

Actually, for outputting things like... carriage return, line-feed, tab, white space etc... I know we can use unicode escapes like '\n', '\r', '\t'.. etc.. but that all are used insde single quote. Now whats confusing me is at some places I see double quotes for the same purpose... ?

SO what I want to know does for those purposes (like .. tab or line feed) either can be used or they have diffferent meaning and behaviou ?

Shebua at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...
# 3
For portability reasons I always use System.getProperty("line.separator");
Nick_B100a at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...
# 4
but we cann't use this idiom at every places and also what about other whitespace characters ?
Shebua at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...
# 5
This this the tab character:'\t'there are some strings that contain tab(s):"\t""hello\tworld""\t3\ttabs\t"Problem solved?
BigDaddyLoveHandlesa at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...
# 6

> but that all are used insde single quote. Now whats

> confusing me is at some places I see double quotes

> for the same purpose... ?

> SO what I want to know does for those purposes (like

> .. tab or line feed) either can be used or they have

> diffferent meaning and behaviou ?

The single quote marks are used to input a character literal.

The double quote marks are used to input a String literal.

Both can have escaped metacharacters like \n, \t, etc.

But since the single quote marks are used for character literals, you can only have one.

So for example:

'\n'// legal

'\n\n'// not legal

"\n"// legal; it's a one-character-long String

"\n\n"// also legal, it's a two-character-long String

Double and single quotes are not used for different kinds of escape characters. It's not like Perl, where single quotes hold uninterpolated strings, for example.

paulcwa at 2007-7-12 21:51:32 > top of Java-index,Java Essentials,Java Programming...