This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is a simple code to read input from the console. Now If I type this input "I am\Pawan" which is actually illegal String in Java because of single "\". This gets sanitized and the value of str that we see while debugging is "I am\\Pawan". I want to see where this correction is happening. Can any one guide me to some tutorials on validating string values and making correction where ever required and also how and where java is doing this?
Strings are strings -- just a sequence of characters. And there are no rules as to what they can contain.
A "string literal" is a way of expressing the value of a string in code. The escaping mechanism is necessary so that characters that could not otherwise be expressed in the value can be expressed. For example \n to represent new-line. This escaping has nothing to do with strings in memory, it's just a short-hand for expressing a string value in the code.
So to say that a string cannot contain the value "\P" is wrong. Of course it can. However, in order to express this in a literal, you must type "\\P". But the in-memory value of the string is still "\P".