

Though you can run a Java program with an empty Main method, in which case only code executed will be from the static initializer block. This contains several free courses to learn key topics like core Java, Multithreading, collections, socket programming, and more. The answer is NO, Why? I will explain that in the next paragraph.īy the way, if you are new to the Java world and want to learn Java in-depth, I suggest you check out these free Java courses for beginners and experienced. Now, if the Interviewer persists with something like this, Can you run a Java program without the main method in Core Java, not on the managed environment like the case of Applet, Servlet, and MIDlet. Since MIDlets are also Java programs, you can say they run without the main method.
#How to run a bluej program in cmd android
Ironically J2ME has an app in its core method, but it was made popular by Android and iPhone. MIDlet has life-cycle methods like startApp(), pauseApp() and destroyApp(), to start, pause and shut-down mobile applications. The third one in this category is MIDlet, which runs on mobile devices like Nokia, Samsung, and others. Since Servlet is also a Java program, we can say that it runs without the main method. Container calls init() if Servlet is a first-time loaded into memory, calls service() if there is a request to process, and calls destroy() before removing it from memory. The Servlet also works on callback mechanism, it has methods like init(), service(), and destroy(). Similarly, we have Servlet, which runs in a Servlet container, comes as bundled in a web server like Tomcat, or Jetty. Since Applet is a Java program, you can answer this question is Yes.

Instead, they have life-cycle methods like init(), start() and stop(), which controls their execution. Well, there are actually different types of execution models available in Java for example, Applets, which run on the browser don't have the main method. Hello guys, the first thing Java programmers learn is that they need a main method to run, but when they go to any Interview or college viva and ask can run a Java program without a main method, they are surprised like hell.
