Source: OUKC (Oracle University Knowledge Center) mock exam question
Hi guys I have serious doubts about the escape options.
What is the result?
A. total: 3
B. total: 4
C. total: 7
D. total: 8
E. Compilation fails.
F. An exception is thrown at runtime.
The answer is D.
I chose compilation fails because I thought the legal escape was "\\d" and NOT "\d"
Which is valid for the real exam?? Can someone explain??
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:I tried running compiling this code- It does give a compilation error. Not always that the mock exam questions are perfectly correct. It might be a printing mistake in the question otherwise or might be the answer is wrong.
Thanks Mohammed, I have just found out from a reliable source that option D is correct.
"\d" is a valid regex metacharacter AND the real exam questions will treat it as "\d", NEITHER "\\d" NOR "\\\d" because the number of back or forward slashes depends ONLY on the underlying operating system.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
because the number of back or forward slashes depends ONLY on the underlying operating system.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:
because the number of back or forward slashes depends ONLY on the underlying operating system.
Can you explain about this?
And also let us know the reliable sources.
Looking at the fact that they have given a complete working code in the question one has to think in the compilation direction as well. Moreover I dont think the escape character depends on the underlying operating system.
Mohammed thank you for raising up the debate.
The reliable source is the book:
Sun Certified Programmer for Java 6 Study Guide. By: Kathy Sierra AND Bert Bates.
Page 503 Chapter 6: (Strings, I/O, Formatting and Parsing) it says quote:
"Note: Remember that to represent "\" in a string you may need to use the escape sequence "\\". Because of this, AND DEPENDING ON YOUR OS, your second argument might have to be ("\\d" or even "\\\\d".)"
As a computer programmer you need to understand that there are certain features that depends on the UNDERLYING OS(operating system).
That will make life(as A programmer) easier for you.
I know that there are some "jokers" in this forum, please "burn it in" that I am NOT one of them. Thank you.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:
The reliable source is the book:
Sun Certified Programmer for Java 6 Study Guide. By: Kathy Sierra AND Bert Bates.
Page 503 Chapter 6: (Strings, I/O, Formatting and Parsing) it says quote:
"Note: Remember that to represent "\" in a string you may need to use the escape sequence "\\". Because of this, AND DEPENDING ON YOUR OS, your second argument might have to be ("\\d" or even "\\\\d".)"
Ikpefua Jacob-Obinyan wrote:
As a computer programmer you need to understand that there are certain features that depends on the UNDERLYING OS(operating system).
That will make life(as A programmer) easier for you.
Ikpefua Jacob-Obinyan wrote:
I know that there are some "jokers" in this forum, please "burn it in" that I am NOT one of them. Thank you.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
gaurav gupta sitm wrote:
why output is 11 insteadof 10.........???
OCMJD 6, OCPJP8, CISSP Baroque Potion, G+
Don't get me started about those stupid light bulbs. |