title: C# Check If Java Is Installed && version(int)
body: <p>I'm making launcher for my java game and I want to check if java 8 is installed, because you can't run java application if java is not installed. I looked the answer on the internet and can't find answer to my question.</p>
  
  <p><strong>My Current Code:</strong></p>
  
  <pre><code>string temp = GetJavaVersion();
  string temp2 = temp.Substring(13, temp.Length - 13);
  //string temp3 = temp2.Substring(10, temp2.Length - 1);
  string installPath = temp2;
  ShowMessageBox(installPath, "Debug", MessageBoxButtons.OK, 
  MessageBoxIcon.Information);
  </code></pre>
  
  <p><strong>GetJavaVersion() Method Code:</strong></p>
  
  <pre><code>        try
          {
              ProcessStartInfo procStartInfo =
                  new ProcessStartInfo("java", "-version ");
  
              procStartInfo.RedirectStandardOutput = true;
              procStartInfo.RedirectStandardError = true;
              procStartInfo.UseShellExecute = false;
              procStartInfo.CreateNoWindow = true;
              Process proc = new Process();
              proc.StartInfo = procStartInfo;
              proc.Start();
              return proc.StandardError.ReadLine();
  
          }
          catch (Exception objException)
          {
              return null;
          }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>"1.8.0_144"
  </code></pre>
  
  <p>Problem is that i get quotes and unnecessary numbers.(i just need number 8 to indicate that java version 8 is installed), if java isn't installed then just output 0.</p>
  
  <p>Can Any One Help?</p>
  
  <p><strong>Edit</strong>
  If i use <code>Regex</code> then how do i get number to int variable?
  Code: </p>
  
  <pre><code>   string temp = GetJavaVersion();
     string temp2 = temp.Substring(13, temp.Length - 13);
     requiredJavaVersion = 8;
     //string temp3 = temp2.Substring(10, temp2.Length - 1);
     string regexPattern = @"([0-9]+)";
     Regex regex = new Regex(regexPattern);
     //Error comes here
     int currentVersion = Convert.ToInt32(regex.Matches("1.8.0_144")[1]); 
  
     if (currentVersion == requiredJavaVersion)
     {
         hasRequiredVersion = true;
     }
  </code></pre>