This is a discussion on How to write a Java Application without a main method? within the Java Programming forums, part of the Software Development category; How to write a Java Application without a main method?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| This can be done using the static block of the class. The static initialization blocks get executed as soon as the class is loaded, even before the main method is called. During run time JVM will search for the main method after exiting from this block. If it does not find the main method, it throws an exception. To avoid the exception system.exit (0); statement is used which terminates the program at the end of the static block itself. class Example { static { System.out.println("hi"); System.exit(0); } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| integerate Java Beans in java application | saravanan | Java Programming | 1 | 03-26-2008 02:22 AM |
| How to Refere a loaded SWF from the Main Application | seesamjagan | Adobe Flex Programming | 0 | 12-24-2007 04:28 AM |
| Can main method be declared final? | leoraja8 | Java Programming | 1 | 08-28-2007 01:24 AM |
| Main method | vigneshgets | C# Programming | 2 | 08-16-2007 11:06 PM |
| How Can I have multiple main methods in the same class in Java? | mobilegeek | Java Programming | 1 | 07-23-2007 10:45 PM |