title: Compile .java file without knowing public class name
body: <p>I'd like to know how to compile .java files without knowing the public class name.</p>
  
  <p>To provide an example use case: I am operating a sandbox, and users are allowed to send me a string. I write that string to a .java file, which I compile, evaluate the resulting class and reply the output.</p>
  
  <p><strong>?????.java</strong></p>
  
  <pre><code>public class HelloWorld {
      public static void main(String[] args) {
          System.out.println("Hello, World");
      }
  }
  </code></pre>
  
  <p>If I were to randomly assign <code>?????.java</code> a name such as <strong>test.java</strong> and ran the command <code>javac test.java</code> then it would fail </p>
  
  <p><em>error: class HelloWorld is public, should be declared in a file named HelloWorld.java</em> like so:</p>
  
  <p><strong>HelloWorld.java</strong></p>
  
  <pre><code>public class HelloWorld {
      public static void main(String[] args) {
          System.out.println("Hello, World");
      }
  }
  </code></pre>
  
  <p>Is this possible? Should I forego the ability to compile Java, or is there an alternative solution?</p>