 <p>After looking at the answers above, I realized that I forgot that I could call the main method to create a bit of a workaround. So while I will need to create a variable string at some point, here is the code along with its input and Output.</p> <p><strong>Class JTest</strong></p> <pre><code>/** *Functions printLines, Run, and parts of main came from stacks overflow *originaly but modifications have been made *http://stackoverflow.com/questions/4842684/how-to-compile-run-java-program-in-another-java-program */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; public class JTest { private static void printLines(String name, InputStream ins) throws Exception { String line = null; BufferedReader in = new BufferedReader(new InputStreamReader(ins)); while ((line = in.readLine()) != null) { System.out.println(line); } } private static int run(String command) throws Exception { Process pro = Runtime.getRuntime().exec(command); printLines(command, pro.getInputStream()); printLines(command + " stderr:", pro.getErrorStream()); pro.waitFor(); return pro.exitValue(); } public static void main(String args[]) { System.out.println("Enter the name of the file you want to run: "); Scanner cin = new Scanner(System.in); String jFileName = cin.nextLine(); try { String arg[] = { "" } ; int binary = cin.nextInt(); int k = run("javac " + jFileName + ".java"); if (k == 0) if (binary == 1) JTest.main(arg); else Foo.main(arg); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p><strong>Class Foo</strong></p> <pre><code>import java.util.Scanner; public class Foo { public static void main(String args []) { Scanner cin = new Scanner(System.in); int bar = cin.nextInt(); System.out.println("Your number times 2 is: " + (bar * 2)); } } </code></pre> <p><strong>Input Output Dialogue</strong></p> <p>Output:</p> <pre><code>Enter the name of the file you want to run: </code></pre> <p>Input:</p> <pre><code>JTest 1 </code></pre> <p>Output:</p> <pre><code>Enter the name of the file you want to run: </code></pre> <p>Input:</p> <pre><code>JTest 1 </code></pre> <p>Output:</p> <pre><code>Enter the name of the file you want to run: </code></pre> <p>Input</p> <pre><code>Foo 0 4 </code></pre> <p>Output:</p> <pre><code>Your number times 2 is: 4 </code></pre> <p>As the program demonstrates, both input and output work fine.</p>