title: Dynamic Compiling Without Create Physical File
body: <p>I follow the tutorial from <a href="http://www.accordess.com/wpblog/an-overview-of-java-compilation-api-jsr-199/" rel="nofollow">Generating Java classes dynamically through Java compiler API</a>, the code is work but what I see is the program will create a class file after compiling it.</p>
  
  <pre><code>import java.io.IOException;
  import java.net.URI;
  import java.util.Arrays;
  import java.util.Locale;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.tools.JavaCompiler.CompilationTask;
  import javax.tools.*;
  
  public class Compiler {
  
      static final Logger logger = Logger.getLogger(Compiler.class.getName());
      static String sourceCode = "class HelloWorld{"
          + "public static void main (String args[]){"
          + "System.out.println (\"Hello, dynamic compilation world!\");"
          + "}"
          + "}";
  
      public void doCompilation() {
  
          SimpleJavaFileObject fileObject = new DynamicJavaSourceCodeObject("HelloWorld", sourceCode);
          JavaFileObject javaFileObjects[] = new JavaFileObject[]{fileObject};
  
          JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  
          StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, Locale.getDefault(), null);
  
          Iterable&lt;? extends JavaFileObject&gt; compilationUnits = Arrays.asList(javaFileObjects);
  
          DiagnosticCollector&lt;JavaFileObject&gt; diagnostics = new DiagnosticCollector&lt;&gt;();
  
          CompilationTask compilerTask = compiler.getTask(null, stdFileManager, diagnostics, null, null, compilationUnits);
  
          boolean status = compilerTask.call();
  
          if (!status) {
              for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
                  System.out.format("Error on line %d in %s\n", diagnostic.getLineNumber(), diagnostic);
              }
          }
          try {
              stdFileManager.close();
          } catch (IOException ex) {
              Logger.getLogger(Compiler.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
      public static void main(String args[]) {
          new Compiler().doCompilation();
      }
  }
  
  class DynamicJavaSourceCodeObject extends SimpleJavaFileObject {
  
      private String qualifiedName;
      private String sourceCode;
  
      protected DynamicJavaSourceCodeObject(String name, String code) {
          super(URI.create("string:///" + name.replaceAll("\\.", "/") + JavaFileObject.Kind.SOURCE.extension), JavaFileObject.Kind.SOURCE);
          this.qualifiedName = name;
          this.sourceCode = code;
      }
  
      @Override
      public CharSequence getCharContent(boolean ignoreEncodingErrors)
          throws IOException {
          return sourceCode;
      }
  
      public String getQualifiedName() {
          return qualifiedName;
      }
  
      public void setQualifiedName(String qualifiedName) {
          this.qualifiedName = qualifiedName;
      }
  
      public String getSourceCode() {
          return sourceCode;
      }
  
      public void setSourceCode(String sourceCode) {
          this.sourceCode = sourceCode;
      }
  }
  </code></pre>
  
  <p>Is it possible that after call <code>compilerTask.call();</code> to not create a class file? If yes how to do that?</p>