title: Why does Java permit escaped unicode characters in the source code?
body: <p>I <a href="http://en.wikibooks.org/wiki/Java_Programming/Syntax/Unicode_Source" rel="noreferrer">recently learned</a> that Unicode is permitted within Java source code not only as Unicode characters (eg. <code>double π = Math.PI;</code> ) but also as escaped sequences (eg. <code>double \u03C0 = Math.PI;</code> ).</p>
  
  <p>The first variant makes sense to me - it allows programmers to name variables and methods in an international language of their choice. However, I don't see any practical application of the second approach.</p>
  
  <p>Here are a few pieces of code to illustrate usage, tested with Java SE 6 and NetBeans 6.9.1:</p>
  
  <p>This code will print out 3.141592653589793</p>
  
  <pre><code>public static void main(String[] args) {
      double π = Math.PI;
      System.out.println(\u03C0);
  }
  </code></pre>
  
  <p>Explanation: π and \u03C0 are the same Unicode character</p>
  
  <p>This code will not print out anything</p>
  
  <pre><code>public static void main(String[] args) {
      double π = Math.PI; /\u002A
      System.out.println(π);
  
      /* a comment */
  }
  </code></pre>
  
  <p>Explanation: The code above actually encodes:</p>
  
  <pre><code>public static void main(String[] args) {
      double π = Math.PI; /*
      System.out.println(π);
  
      /* a comment */
  }
  </code></pre>
  
  <p>Which comments out the print satement.</p>
  
  <p>Just from my examples, I notice a number of potential problems with this language feature.</p>
  
  <p>First, a bad programmer could use it to secretly comment out bits of code, or create multiple ways of identifying the same variable. Perhaps there are other horrible things that can be done that I haven't thought of.</p>
  
  <p>Second, there seems to be a lack of support among IDEs. Neither NetBeans nor Eclipse provided the correct code highlighting for the examples. In fact, NetBeans even marked a syntax error (though compilation was not a problem).</p>
  
  <p>Finally, this feature is poorly documented and not commonly accepted. Why would a programmer use something in his code that other programmers will not be able to recognize and understand? In fact, I couldn't even find something about this on the <a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden Java Features question</a>.</p>
  
  <p>My question is this:</p>
  
  <p>Why does Java allow escaped Unicode sequences to be used within syntax?
  What are some "pros" of this feature that have allowed it to stay a part Java, despite its many "cons"?</p>