title: How to call a Java class from Java code using Runtime exec
body: <p>I would like to know if there is a way to call a Java class from another. I implemented a testing code as follows using Runtime exec, calling "test.java" from "exec.java", but the exec calling won't execute. What is the problem in the code? Thanks.</p>
  
  <p>test.java:</p>
  
  <pre><code>package com.example.exec;
  
  public class test{
  
      public static void main(String args[]) {
          System.out.println("Hello World!");
      }
  }
  </code></pre>
  
  <p>exec.java:</p>
  
  <pre><code>package com.example.exec;
  
  public class exec {
  
      public static void main(String args[]) {
          try {
              Process pro = Runtime.getRuntime().exec("java test");
          } catch (Exception err) {
              System.out.println("Error!");
          }
      }
  }
  </code></pre>