title: How to run Java source code within a Java program
body: <p>I have wrote some code to compile a Java source code. It then produces the .class file. The problem is how do I run it?</p>
  
  <p>For example, I am ok with the name of the program and class being set, I've used prog p = new prog(), in this case, however, the class file does not yet exist until I compile it. Not really sure what to do. Can someone give me an advice?</p>
  
  <p>btw, the class looks like this:</p>
  
  <pre><code>public void compile{
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();  
    int compilationResult = compiler.run(null, null, null, fileToCompile);  
  }
  
  public void run(){
    Prog prog = new Prog();
    prog.run();
  }
  </code></pre>