title: How to tell if a string contains valid code in Java?
body: <p>Is there a function to test if a string contains valid code in Java?  I have a bunch of strings (e.g. <code>2.0+0.0+pow(2.0),2.0</code>, obviously this one doesn't work) that I need to verify this for.  I can add things to the beginning and end, so it doesn't much matter what language I'm testing:</p>
  <p>python:</p>
  <pre class="lang-python prettyprint-override"><code>x = 2.0+0.0+pow(2.0),2.0
  </code></pre>
  <p>Java:</p>
  <pre class="lang-java prettyprint-override"><code>float x = 2.0+0.0+pow(2.0),2.0;
  </code></pre>
  <p>JavaScript:</p>
  <pre class="lang-javascript prettyprint-override"><code>var x = 2.0+0.0+pow(2.0),2.0;
  </code></pre>
  <p>as long as I can test it in Java.</p>
  <p>I found this: <a href="https://stackoverflow.com/questions/11854745/how-to-tell-if-a-string-contains-valid-python-code">How to tell if a string contains valid Python code</a>, but that's for testing in python, not Java.</p>
  <p>Thanks in advance!</p>