Saturday, July 4, 2009

String puzzle

A short, but interesting puzzle.

Question
What does the following program print:



Answer
When you run the code, you get the answer: 2.

Why?
The compiler translates Unicode escapes into the characters they represent before it parses the program into tokens, such as strings literals. As you see, NetBeans IDE doesn't know it, it present the code like a string with a length() method.