Can you run the java program without main method? - Java

Can you run the java program without main method?

A java applet application, a web application can run without main method. A Java program can run without using ‘ public static void main(String args[]) ‘ method by using a static block.

The static block gets executed soon after the class is loaded, even prior to the ‘public static void main(String args[]) ‘. JVM searches for main method only after exiting from the static block. JVM throws an exception if main method is not found. To avoid throwing this exception we can use System.exit(0);

The following example depicts a class without main method; with only static block and System.exit(0).
class WithoutMainMethod
{
   static
   {
       System.out.println(“This class has no public static void main(String args[]) “);
       System.out.exit(0);
   }
}
Can you explain why servlets extend HttpServlet?
Most of the web applications uses HTTProtocol. The user requests need to be received and processed through the HTTProtocol...
What is Servlet Filter and how does it work?
Filters are powerful tools in servlet environment. Filters add certain functionality to the servlets apart from processing request and response paradigm of servlet processing...
Explain the use of logic:iterate tag in struts application
The tag is utilized for repeating the nested body content over a collection. Every element / object in a specified collection...
Post your comment