Quick-Fix
You can call a main-method like every other regular method as well:
public static void main(String[] args) { imFirst.main(null); imSecond.main(null); }
Better approach
But you should first think of why you even need two main methods at all. A main method is the first thing in the whole Java chain and usually you only use one for every complete program. The purpose is to simply start the program, most times its just a call to a dedicated class like:
public static void main(String[] args) { ProgramXY programXY = new ProgramXY(); programXY.init(); programXY.start(); }
So I recommend you to simply move both print statements into own classes and methods and then simply call them from one main method:
The utility class:
public class ConsolePrinter { public static void println(String line) { System.out.println(line); } }
The only main-method:
public static void main(String[] args) { ConsolePrinter.println("I want to be the first one executed!"); ConsolePrinter.println("I want to be the second one executed!"); }
More general
Or for a more general purpose:
First class:
public class FirstClass { public void firstMethod() { // ... } }
Second class:
public class SecondClass { public void secondMethod() { // ... } }
The only main method:
public static void main(String[] args) { FirstClass first = new FirstClass(); SecondClass second = new SecondClass(); first.firstMethod(); second.secondMethod(); }
main-method is the first part in the whole Java chain. You should think of moving both your prints into regular methods and then call them from a dedicatedmain-method.mainafter the first has finished. However you could create a simplebatch/script-file for such a purpose.