2
public class trial { 
    static {
        System.out.println("Main not required to print this");
        System.exit(0);
    }
}

This code still throws an error as

Error: Main method not found in class trial, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application**

There were posts saying that it will work in java 1.9 but it doesn't.

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • https://stackoverflow.com/questions/11421542/how-can-you-run-a-java-program-without-main-method – Mohammed Ismail A Mar 14 '18 at 16:01
  • 1
    Welcome to Stack Overflow! Please take the [tour], have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) 1. Show how you were trying to run the class. 2. Link to and quote (in the *question*) the post that you think says something changed in JDK 9. – T.J. Crowder Mar 14 '18 at 16:02
  • 2
    Can you give us a link to the page that said so? – Alexander Kaschta Mar 14 '18 at 16:02
  • Who told you that **Main method is not required to print this**...? Main method is mandatory to start the application. Once it's been started, all your static blocks will be executed when the Class Loader loads the relevant class. – Roshana Pitigala Mar 14 '18 at 16:03

0 Answers0