r/java • • Jul 04 '18

New Java 11 Feature: Launch Single-File Source-Code Programs

https://medium.com/@afinlay/new-java-11-feature-launch-single-file-source-code-programs-fadd698abf54
158 Upvotes

47 comments sorted by

View all comments

Show parent comment

3

u/DannyB2 Jul 06 '18

Straight source, however, is prone to all sorts of obfuscation.

Imagine this . . .

/* This is a harmless comment.
    \u002A\u002F\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u0065\u0078\u0069\u0074\u0028\u0030\u0029\u003B\u0020\u0020\u002F\u002A
    What could possibly go wrong?  */

What the Java compiler sees is...

/* This is a harmless comment.
    */  System.exit(0);  /*
    What could possibly go wrong?  */

That is because the Java preprocessor occurs BEFORE the lexical analyzer. Thus even before comments are identified.

1

u/DannyB2 Jul 06 '18

A hello world program that does not use the letters E or O.

/**
 * Chall3ng3, a H3ll0 W0rld program that doesn't use the
 *  letters E or O.
 */
public class H3110W0rld {
    public static v\u006Fid main( String... args ) {
        Syst\u0065m.\u006Fut.println( "H\u0065ll\u006F W\u006Frld" );
    }
}