What’s the Java Shebang for OS X?
Here is a simple wrapper script that effectively can work as a Java shebang on OS X and Linux:

# /* ------- build and run wrapper script for Java -----------------------------
TMP=$(mktemp -d)
tail -c +3 ${0} &gt; ${TMP}/$(basename ${0})
cd ${TMP} &amp;&amp; javac $(basename ${0}) &amp;&amp; java $(basename ${0%.*}) ${@:1}
RV=${?} ; cd - &gt; /dev/null ; rm -rf ${TMP}
exit ${RV}
----------------------------------------------------------------------------- */

public class example {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}


However, as pointed out in the comments this is technically not a "shebang", but it comes pretty close in terms of functionality.