Skip to content

Instantly share code, notes, and snippets.

@SubOptimal
Created September 12, 2014 10:18
Show Gist options
  • Save SubOptimal/add86cc4b1f4a141c382 to your computer and use it in GitHub Desktop.
Save SubOptimal/add86cc4b1f4a141c382 to your computer and use it in GitHub Desktop.
Java "Hello World" without keyword "class"
# Linux / Mac
echo 'java.lang.System.out.println("Hello World")' | java -cp ${JAVA_HOME}/lib/tools.jar com.sun.tools.script.shell.Main
# Windows
echo java.lang.System.out.println("Hello World") | java -cp %JAVA_HOME%/lib/tools.jar com.sun.tools.script.shell.Main
@yfain
Copy link

yfain commented Sep 12, 2014

Nice solution!

This one is more readable though:

public interface HelloWorldInterface {
public static void main(String[] args) {
System.out.println("HelloWorldInterface World");
}
}

@thomasdarimont
Copy link

Btw. you don't need the "public" modifiert in interfaces so you can make it even shorter ;-)

@SubOptimal
Copy link
Author

@yfain Sure your interface solution is more readable. Mine was more to show a "more different" solution. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment