0

I'm working on the exercises in "Think Java" Chapter 15 "Conway's Game of Life". I'm a little confused by the way the provided code is set up. The program runs by typing "java Conway.java" in the console and does everything I want including the modifications from the exercises. But, as I'm using replit, I'd rather just hit the big green "Run" button. This button automatically runs "java Main.java" as far as I can tell. Looking for a fast way to point the main() method in Main.java to "java Conway.java" has lead me to suggestions that seem far too involved for what I want to do, from introducing and additional library to run console commands, to basically re-writing most of the program so "Conway.java" is replaced with Main.java in every possible location.

At last I got it to work by just calling:

class Main {
    public static void main(String[] args) {
        Conway.main(args); }
    }

But, also read that this is "bad practice" -- I guess I'm wondering why make a program that dodges the fun green "run" button? Why is it "bad practice" to do the above?

I also wanted to automate javac in the main file, but I've given up on this. It would be nice to specify what I needed to compile, but I'm concerned that I don't have enough time to fully understand the libraries suggested for running such commands.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
futurebird
  • 73
  • 7
  • 2
    Normal Java IDEs allow you to run **any** class, irrespective of their class name as long as they have a main method (in fact, using a specific name instead of calling the class "Main" is pretty common). So this is not a question of _"why make a program that dodges the fun green "run" button?"_, this is either a limitation of the tool you're using (I've never heard of replit), or you simply haven't found its option to run a different file. – Mark Rotteveel Feb 23 '23 at 14:20

0 Answers0