Sponsored By
MindStick Cleaner
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
   

Home >> Java Programming >> Java >> How can I execute any program in java without main method?
Author Post

Awadhendra Tiwari


Total Post: 126
Member Since: 1/19/2011
Points: 893
How can I execute any program in java without main method?
Posted On: 7/23/2011 5:55:28 AM

Hi,

I have a  small problem while creating program. This might be a silly question as I am fresher in JAVA. I want to ask that
is it possible to run any program in java which have not main method. Like we can run some program in c and c++ which
doesent have main method. Is it possible in java.

Thanks.

Author Post

James Smith


Total Post: 48
Member Since: 3/16/2011
Points: 270
Re: How can I execute any program in java without main method?
Posted On: 7/23/2011 6:23:22 AM

Hi awadhendra,

You can use static block to perform this task and at the end of statements called System.exit(0) to avoid to generate an exception.

class MainMethodNot
{
    static
    {
        System.out.println("This java program have run without the run method");
        System.exit(0);
       
    }
}

Thanks.

Report Abuse Form
Reason:    
 
Total Online Users: 2643
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.