Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Last active October 11, 2022 18:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/fa9ced143af84a9ae3dd to your computer and use it in GitHub Desktop.
Save thomasdarimont/fa9ced143af84a9ae3dd to your computer and use it in GitHub Desktop.
HelloWorld in Java without using a "." character

Compile

C:\tom\dev\projects\de.tutorials.training.java8\src\main\java>
javac HelloWorld.java

Run

C:\tom\dev\projects\de.tutorials.training.java8\src\main\java>
java -XX:-StackTraceInThrowable -cp . HelloWorld

Output

Hello World!
import static java.lang.String.valueOf;
import static java.util.Arrays.fill;
/**
* Author: Thomas Darimont
*/
public interface HelloWorld {
static void main(String[] args) {
char[] backspaces = new char[64];
fill(backspaces, '\b');
char[] spaces = new char[64];
fill(spaces, ' ');
throw new RuntimeException(valueOf(backspaces) + "Hello World!" + valueOf(spaces));
}
}
import static java.lang.String.join;
import static java.util.Collections.nCopies;
/**
* Author: Thomas Darimont
*/
public interface HelloWorld {
static void main(String[] args) {
throw new RuntimeException(join("", nCopies(64, "\b")) + "Hello World!" + join("", nCopies(64, " ")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment