Saturday, June 13, 2015

How to execute Java code Inside Comments?

Hi folks,

An interesting observation. It's possible to execute Java code from inside what looks like comment line. You may call it  a Java design flaw or a trick, below is the code piece 

So what's going on there? The trick is the unicode character in front of the comment line. It is parsed by Java compiler as a newline and hence the above code is read a below by the Compiler. 

In Java Unicode decoding occurs earlier than any lexical translation. So the whole code gets converted into a unicode (not exactly, but it's easier to understand this way). This was done for Java code to be encoding free and truly platform independent.

Hence it's possible to write an entire code of Java in unicodes only. Still compiler will understand and run the program.

No comments:

Post a Comment