Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active February 7, 2025 21:18
Show Gist options
  • Save bzdgn/78b6f92b391650a48c50 to your computer and use it in GitHub Desktop.
Save bzdgn/78b6f92b391650a48c50 to your computer and use it in GitHub Desktop.
Dummy Code Generator : 10000 Lines of Useless Code
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class GenerateDummyCode {
public static void main(String[] args) {
String className = "Eben";
String newLine = "\n";
String tab = "\t";
String classStart = "public class " + className + " {";
String closeBracket = "}";
String mainStart = "public static void main(String[] args) {";
String dummyContent = "";
String temp = null;
int size = 10000;
for (int i = 1; i <= size; i++) {
temp = String.format("System.out.println(\" %6d .ci satir\");", i);
dummyContent += tab + tab + temp + newLine;
}
String outputCode =
classStart + newLine + newLine +
tab + mainStart + newLine + newLine +
dummyContent + newLine +
tab + closeBracket + newLine +
closeBracket + newLine;
// System.out.println(result); // To print the output to the console
PrintWriter out = null;
try {
out = new PrintWriter(className + ".java");
} catch (FileNotFoundException e) {
System.out.println("File not found!");
}
out.println(outputCode);
out.close();
}
}
@bzdgn
Copy link
Author

bzdgn commented Dec 1, 2015

@emrekekec
Copy link

Dear bzgdn,

If Eben.java file is not found, you will receive a NullPointerException inside stream writer since you are swallowing the Exception and trying to access an unitialized object on the heap.

Keep up the good work, you are almost there

Best Regards

@vghfr
Copy link

vghfr commented Nov 23, 2021

yoink! that's mine now, need filler code

@c-dawkins
Copy link

u

@ulose1234
Copy link

import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class GenerateDummyCode {
public static void main(String[] args) {
String className = "Eben";
int size = 10000;

    // Use StringBuilder to build the class content
    StringBuilder contentBuilder = new StringBuilder();

    // Generate the dummy content
    for (int i = 1; i <= size; i++) {
        contentBuilder.append("\t\tSystem.out.println(\" " + String.format("%6d", i) + " .ci satir\");\n");
    }

    // Construct the entire Java class code
    String outputCode = String.format(
            "public class %s {\n\n\tpublic static void main(String[] args) {\n\n%s\n\t}\n}",
            className, contentBuilder.toString()
    );

    // Write to the file
    try (PrintWriter out = new PrintWriter(className + ".java")) {
        out.println(outputCode);
    } catch (FileNotFoundException e) {
        System.out.println("File not found!");
    }
}

}

@Isimplifycode
Copy link

here is a simplified version

import java.io.PrintWriter;

public class GenerateDummyCode {
public static void main(String[] args) {
try (PrintWriter out = new PrintWriter("Eben.java")) {
out.println("public class Eben {");
out.println("\tpublic static void main(String[] args) {");
for (int i = 1; i <= 10000; i++) out.printf("\t\tSystem.out.println("%6d .ci satir");\n", i);
out.println("\t}");
out.println("}");
} catch (Exception e) {
System.out.println("Error!");
}
}
}

@ulose1234
Copy link

here is a simplified version

import java.io.PrintWriter;

public class GenerateDummyCode { public static void main(String[] args) { try (PrintWriter out = new PrintWriter("Eben.java")) { out.println("public class Eben {"); out.println("\tpublic static void main(String[] args) {"); for (int i = 1; i <= 10000; i++) out.printf("\t\tSystem.out.println("%6d .ci satir");\n", i); out.println("\t}"); out.println("}"); } catch (Exception e) { System.out.println("Error!"); } } }

wrong

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