Skip to content

Instantly share code, notes, and snippets.

@destan
Last active December 8, 2020 08:02
Show Gist options
  • Save destan/c0db5a237e9875a56141403aaa6cb9c7 to your computer and use it in GitHub Desktop.
Save destan/c0db5a237e9875a56141403aaa6cb9c7 to your computer and use it in GitHub Desktop.
Simple Java quine, self replicating (self copying) Java code, with text blocks. This code can be run with Java 15+ or Java 13+ with special flags. License is public domain, no rights reserved.
public class Quine {
public static void main(String[] args) {
String textBlockQuotes = new String(new char[]{'"', '"', '"'});
char newLine = 10;
String source = """
public class Quine {
public static void main(String[] args) {
String textBlockQuotes = new String(new char[]{'"', '"', '"'});
char newLine = 10;
String source = %s;
System.out.println(source.formatted(textBlockQuotes + newLine + source + textBlockQuotes));
}
}
""";
System.out.println(source.formatted(textBlockQuotes + newLine + source + textBlockQuotes));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment