Thanks for your explanation. That makes it much clearer and I am glad to give you a helpful answer now. What you need is the knowledge about threads. You can read about it in detail for example if you google for "java simple thread example".
In your case, you should rename the methods "main" in both your files Test.java and Test2.java to "run()" and add "extends Thread" to both classes.
Now you will write a new file, let us call it "ThreadStarter", which you will run from the command line (shell) with "java ThreadStarter".
- class ThreadStarter {
-
public static void main (String[] args) {
-
new Test().start();
-
new Test1().start();
-
}
-
}
By the way, if you want to keep the threads running after ThreadStarter and the shell finishes, read about "Demon" threads.