Projects‎ > ‎Cmd && Bash Scripts‎ > ‎

BASH::New Java class creation

posted Apr 23, 2011, 8:33 PM by Chairman Steve   [ updated Apr 23, 2011, 8:42 PM ]
While only particularly useful when coding using VI on the terminal, this is super convenient when you make a bunch of little java programs like I do. This is meant to be added to your .bashrc file.

#create a new java template
#usage: new desiredFilename [0]
#0 signifies that this java file will not have a main method or imports
new() {
        imports="import*;\nimport java.util.*;\n\n"
        classdef="public class $filename {\n\t"
        main="public static void main(String[] args)throws Exception{\n"
        constructor="public $filename (){\n\n\t}//end of constructor"
        inout="\t\tScanner in = new Scanner(new File(\"$\"));\n\t\tPrintStream out = new PrintStream(new File(\"$filename.out\"));\n\n\t}//end of main"
        footers="\n}//end of class $filename"
        if [ "$kind" = "0" ]; then
                echo -e "$classdef $constructor $footers" > $
                echo -e "$imports $classdef $main $inout $footers" > $