IT Community - Software Programming, Web Development and Technical Support

How to write a Java Application without a main method?

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 06:31 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Question How to write a Java Application without a main method?

How to write a Java Application without a main method?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 06:49 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to write a Java Application without a main method?

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);

}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 11:13 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0