Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run Java .class file from another .class file? (java newb)
    primarykey
    data
    text
    <p>I've been running different individual Java .java files in the Netbeans IDE by right-clicking the .java files themselves in the Project Explorer of Netbeans (the portion normally at the upper left part of Netbeans).</p> <p>However, i've been googling on how to make a class file run another class file using code, but to no avail.</p> <p>I have a project named "loadanotherfile" with 2 files, namely: Loadanotherfile.java and otherfile.java</p> <p>I'm trying to make Loadanotherfile.java run otherfile.java, but I'm not exactly sure how. I read about Classloaders and URLClassloaders however these methods don't seem suitable for my purpose of running another .java file. </p> <p>Below is the code of the 2 files i mentioned.</p> <p><strong>Loadanotherfile.java</strong></p> <pre><code>package loadanotherfile; public class Loadanotherfile { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Hello World!"); // TODO code application logic here } } </code></pre> <p><strong>otherfile.java</strong></p> <pre><code>package loadanotherfile; public class otherfile { public static void main(String args[]) { System.out.println("This is the other file."); } } </code></pre> <p>I have a feeling that the task has something to do with using the "import" syntax (namely something like <strong>import loadanotherfile.*</strong> but even if my guess is correct, I'm still not sure on how to make my Loadanotherfile.java run otherfile.java using code.</p> <p>How can I load otherfile.java using Loadanothefile.java?</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload